├── library ├── .vs │ ├── PSFramework │ │ └── v15 │ │ │ └── .gitignore │ └── PSFrameworkTemp │ │ └── v15 │ │ └── .suo ├── PSFramework │ ├── Parameter │ │ ├── ParameterClassAttribute.cs │ │ ├── ParameterContractType.cs │ │ ├── ParameterClasses.cs │ │ ├── ComputerParameterInputType.cs │ │ └── ParameterContractAttribute.cs │ ├── PSFCore │ │ ├── NoJeaCommandAttribute.cs │ │ ├── NoJeaParameterAttribute.cs │ │ ├── PsfInternalAttribute.cs │ │ └── DebugData.cs │ ├── Serialization │ │ └── ClixmlDataStyle.cs │ ├── Filter │ │ ├── ConditionType.cs │ │ ├── ConditionWrapper.cs │ │ └── ConditionSetWrapper.cs │ ├── Meta │ │ └── PSTraceSource.cs │ ├── FlowControl │ │ ├── PSEdition.cs │ │ ├── OperatingSystem.cs │ │ └── CallbackException.cs │ ├── Validation │ │ └── NoResultsAction.cs │ ├── Configuration │ │ └── PersistedConfig.cs │ ├── Logging │ │ ├── ProviderVersion.cs │ │ ├── LogFileFileType.cs │ │ ├── LoggingState.cs │ │ └── Error.cs │ ├── Runspace │ │ ├── RSPowerShellWrapper.cs │ │ ├── RunspaceState.cs │ │ ├── RSState.cs │ │ └── RSWorkflowRunespaceReport.cs │ ├── Temp │ │ └── TempItemType.cs │ ├── TaskEngine │ │ ├── TaskState.cs │ │ └── Priority.cs │ ├── Utility │ │ ├── DynamicContentObjectType.cs │ │ ├── ThrottleBase.cs │ │ └── TypeTransformationAttribute.cs │ ├── TabExpansion │ │ ├── CompletionResultComparer.cs │ │ └── TeppScriptMode.cs │ ├── Message │ │ ├── TransformType.cs │ │ └── LogEntryType.cs │ ├── ComputerManagement │ │ ├── ComputerManagementHost.cs │ │ └── PSSessionContainer.cs │ ├── License │ │ ├── ProductType.cs │ │ └── LicenseType.cs │ ├── Data │ │ ├── Converters │ │ │ ├── BoolConverter.cs │ │ │ ├── DBNullConverter.cs │ │ │ ├── IntConverter.cs │ │ │ ├── DoubleConverter.cs │ │ │ ├── VersionConverter.cs │ │ │ ├── GuidConverter.cs │ │ │ ├── TimeSpanConverter.cs │ │ │ ├── PSDriveInfoConverter.cs │ │ │ ├── SwitchConverter.cs │ │ │ ├── PSProviderInfoConverter.cs │ │ │ ├── DateTimeConverter.cs │ │ │ ├── AssemblyConverter.cs │ │ │ ├── TypeInfoConverter.cs │ │ │ ├── TextConverter.cs │ │ │ ├── ScriptblockConverter.cs │ │ │ └── ArrayConverter.cs │ │ └── IPsd1Converter.cs │ ├── ResultCache │ │ └── ResultCache.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ └── Feature │ │ └── FeatureItem.cs └── PSFramework.sln ├── .gitattributes ├── PSFramework ├── internal │ ├── readme.md │ ├── tepp │ │ └── scripts │ │ │ ├── features.ps1 │ │ │ ├── temp.ps1 │ │ │ ├── license-name.ps1 │ │ │ ├── psprovider.ps1 │ │ │ ├── callback-name.ps1 │ │ │ ├── config-schema.ps1 │ │ │ ├── config-validation.ps1 │ │ │ ├── pathName.ps1 │ │ │ ├── dynamiccontentobject-name.ps1 │ │ │ ├── config-module.ps1 │ │ │ ├── runspace.ps1 │ │ │ ├── scriptblocks.ps1 │ │ │ ├── config-fullname.ps1 │ │ │ ├── encoding.ps1 │ │ │ ├── parametersetNames.ps1 │ │ │ ├── config-name.ps1 │ │ │ ├── localization.ps1 │ │ │ ├── tepp.ps1 │ │ │ ├── message.ps1 │ │ │ ├── filter.ps1 │ │ │ ├── logging-provider.ps1 │ │ │ └── Unregister-PSFConfig.ps1 │ ├── scriptblocks │ │ ├── strings.validate.ps1 │ │ ├── filters.validate.ps1 │ │ └── timespan.validate.ps1 │ ├── scripts │ │ ├── strings.ps1 │ │ ├── sessionRegistration.ps1 │ │ ├── preimport.ps1 │ │ ├── loadConfigurationPersisted.ps1 │ │ ├── removalEvent.ps1 │ │ ├── cmdlets.ps1 │ │ └── taskEngine.ps1 │ ├── configurations │ │ ├── serialization.ps1 │ │ ├── computermanagement.ps1 │ │ ├── path.ps1 │ │ ├── runspace.ps1 │ │ ├── utility.ps1 │ │ └── tabexpansion.ps1 │ ├── parameters │ │ ├── readme.md │ │ └── ComputerParameter.ps1 │ ├── configurationvalidation │ │ ├── integerarray.ps1 │ │ ├── guid.ps1 │ │ ├── long.ps1 │ │ ├── integer.ps1 │ │ ├── double.ps1 │ │ ├── datetime.ps1 │ │ ├── consolecolor.ps1 │ │ ├── timespan.ps1 │ │ ├── uriabsolute.ps1 │ │ ├── guidarray.ps1 │ │ ├── sizestyle.ps1 │ │ ├── integerpositive.ps1 │ │ ├── logfilefiletype.ps1 │ │ ├── stringarray.ps1 │ │ ├── credential.ps1 │ │ ├── integer0to9.ps1 │ │ ├── integer1to9.ps1 │ │ ├── bool.ps1 │ │ ├── languagecode.ps1 │ │ ├── string.ps1 │ │ └── secret.ps1 │ ├── loggingProviders │ │ └── console.provider.ps1 │ └── functions │ │ └── flowcontrol │ │ └── Invoke-PsfTerminatingException.ps1 ├── bin │ ├── readme.md │ ├── PSFramework.dll │ ├── PSFramework.pdb │ ├── PS4 │ │ └── PSFramework.dll │ ├── type-extensions.ps1 │ └── assembly.ps1 ├── en-us │ ├── stringsResultCache.psd1 │ ├── stringsTabExpansion.psd1 │ ├── stringsFilter.psd1 │ ├── stringsComputerManagement.psd1 │ ├── stringsTaskEngine.psd1 │ ├── stringsImport.psd1 │ ├── about_psf_license.help.txt │ ├── about_psf_flowcontrol.help.txt │ ├── about_psf_resultcache.help.txt │ ├── about_psf_runspace.help.txt │ ├── stringsSerialization.psd1 │ ├── stringsFlowControl.psd1 │ ├── stringsScriptblock.psd1 │ └── stringsLogging.psd1 ├── tests │ ├── testdata │ │ ├── configdata.json │ │ └── utility │ │ │ ├── ImportPsd1.psd1 │ │ │ └── ImportJson.json │ ├── functions │ │ ├── readme.md │ │ ├── runspace │ │ │ ├── Read-PSFRunspaceQueue.Tests.ps1 │ │ │ ├── Start-PSFRunspaceWorker.Tests.ps1 │ │ │ ├── Stop-PSFRunspaceDispatcher.Tests.ps1 │ │ │ ├── Stop-PSFRunspaceWorker.Tests.ps1 │ │ │ ├── Write-PSFRunspaceQueue.Tests.ps1 │ │ │ ├── Remove-PSFRunspaceDispatcher.Tests.ps1 │ │ │ ├── Start-PSFRunspaceDispatcher.Tests.ps1 │ │ │ ├── Get-PSFRunspaceDispatcher.Tests.ps1 │ │ │ ├── end-to-end.Tests.ps1 │ │ │ ├── New-PSFRunspaceDispatcher.Tests.ps1 │ │ │ └── Get-PSFRunspaceWorker.Tests.ps1 │ │ ├── configuration │ │ │ └── Get-PSFConfig.Tests.ps1 │ │ ├── message │ │ │ └── New-PSFMessageLevelModifier.Tests.ps1 │ │ └── pipeline │ │ │ └── Remove-PSFNull.Tests.ps1 │ ├── general │ │ ├── Help.Exceptions.ps1 │ │ ├── FileIntegrity.Exceptions.ps1 │ │ ├── strings.Tests.ps1 │ │ └── PSScriptAnalyzer.Tests.ps1 │ ├── readme.md │ └── extensions │ │ ├── BeTrueFOrAll.ps1 │ │ └── BeTrueForAny.ps1 ├── functions │ ├── readme.md │ ├── utility │ │ ├── Enable-PSFConsoleInterrupt.ps1 │ │ ├── Disable-PSFConsoleInterrupt.ps1 │ │ ├── Get-PSFPath.ps1 │ │ ├── Register-PSFSupportDataProvider.ps1 │ │ ├── Remove-PSFAlias.ps1 │ │ └── Register-PSFArgumentTransformationScriptblock.ps1 │ ├── message │ │ ├── Clear-PSFMessage.ps1 │ │ ├── Get-PSFMessageColorTransform.ps1 │ │ ├── Unregister-PSFMessageColorTransform.ps1 │ │ └── Get-PSFMessageLevelModifier.ps1 │ ├── feature │ │ ├── Get-PSFFeature.ps1 │ │ └── Test-PSFFeature.ps1 │ ├── temp │ │ └── Get-PSFTempItem.ps1 │ ├── runspace │ │ ├── Get-PSFRunspaceWorkflow.ps1 │ │ ├── Get-PSFRunspace.ps1 │ │ ├── Stop-PSFRunspaceWorker.ps1 │ │ ├── Start-PSFRunspaceWorker.ps1 │ │ ├── Get-PSFDynamicContentObject.ps1 │ │ ├── Remove-PSFRunspaceWorkflow.ps1 │ │ ├── Stop-PSFRunspaceWorkflow.ps1 │ │ ├── Get-PSFRunspaceWorker.ps1 │ │ └── Start-PSFRunspaceWorkflow.ps1 │ ├── configuration │ │ ├── Register-PSFConfigSchema.ps1 │ │ └── Register-PSFConfigValidation.ps1 │ ├── logging │ │ ├── Get-PSFLoggingError.ps1 │ │ ├── Get-PSFLoggingProvider.ps1 │ │ └── Remove-PSFLoggingProviderRunspace.ps1 │ ├── taskengine │ │ ├── Get-PSFTaskEngineTask.ps1 │ │ ├── Test-PSFTaskEngineTask.ps1 │ │ ├── Test-PSFTaskEngineCache.ps1 │ │ ├── Disable-PSFTaskEngineTask.ps1 │ │ └── Get-PSFTaskEngineCache.ps1 │ ├── resultcache │ │ └── Clear-PSFresultCache.ps1 │ ├── ComputerManagement │ │ └── Register-PSFSessionObjectType.ps1 │ ├── flowcontrol │ │ ├── Get-PSFCallback.ps1 │ │ ├── Test-PSFFunctionInterrupt.ps1 │ │ ├── Test-PSFLanguageMode.ps1 │ │ └── Unregister-PSFCallback.ps1 │ ├── import │ │ └── Export-PSFModuleClass.ps1 │ ├── filter │ │ └── Get-PSFFilterConditionSet.ps1 │ ├── data │ │ └── ConvertTo-PSFPsd1.ps1 │ ├── localization │ │ └── Get-PSFLocalizedString.ps1 │ └── license │ │ └── Remove-PSFLicense.ps1 ├── snippets │ └── help_par_EnableException.snippet └── xml │ └── readme.md ├── .github ├── workflows │ ├── validate.yml │ └── build.yml └── FUNDING.yml ├── .vscode └── settings.json ├── .gitignore └── LICENSE /library/.vs/PSFramework/v15/.gitignore: -------------------------------------------------------------------------------- 1 | .suo -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto -------------------------------------------------------------------------------- /PSFramework/internal/readme.md: -------------------------------------------------------------------------------- 1 | # Description 2 | This is where all the internal stuff goes. -------------------------------------------------------------------------------- /PSFramework/bin/readme.md: -------------------------------------------------------------------------------- 1 | # Placeholder 2 | One day there shall be binaries and the likes found here -------------------------------------------------------------------------------- /PSFramework/en-us/stringsResultCache.psd1: -------------------------------------------------------------------------------- 1 | @{ 2 | 'Clear-PSFResultCache.Clear' = 'Clearing the result cache' 3 | } -------------------------------------------------------------------------------- /PSFramework/en-us/stringsTabExpansion.psd1: -------------------------------------------------------------------------------- 1 | @{ 2 | 'Set-PSFTeppResult.UpdateValue' = 'Setting the cache' 3 | } -------------------------------------------------------------------------------- /PSFramework/en-us/stringsFilter.psd1: -------------------------------------------------------------------------------- 1 | @{ 2 | 'Test-PSFFilter.Condition.NotInSet' = 'Condition not included: {0}' # $condition 3 | } -------------------------------------------------------------------------------- /PSFramework/bin/PSFramework.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PowershellFrameworkCollective/psframework/HEAD/PSFramework/bin/PSFramework.dll -------------------------------------------------------------------------------- /PSFramework/bin/PSFramework.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PowershellFrameworkCollective/psframework/HEAD/PSFramework/bin/PSFramework.pdb -------------------------------------------------------------------------------- /PSFramework/bin/PS4/PSFramework.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PowershellFrameworkCollective/psframework/HEAD/PSFramework/bin/PS4/PSFramework.dll -------------------------------------------------------------------------------- /library/.vs/PSFrameworkTemp/v15/.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PowershellFrameworkCollective/psframework/HEAD/library/.vs/PSFrameworkTemp/v15/.suo -------------------------------------------------------------------------------- /PSFramework/internal/tepp/scripts/features.ps1: -------------------------------------------------------------------------------- 1 | Register-PSFTeppScriptblock -Name "PSFramework.Feature.Name" -ScriptBlock { 2 | (Get-PSFFeature).Name 3 | } -Global -------------------------------------------------------------------------------- /PSFramework/internal/tepp/scripts/temp.ps1: -------------------------------------------------------------------------------- 1 | Register-PSFTeppScriptblock -Name 'PSFramework.Temp.ProviderName' -ScriptBlock { 2 | $script:tempItems.Providers.Keys 3 | } -------------------------------------------------------------------------------- /PSFramework/internal/scriptblocks/strings.validate.ps1: -------------------------------------------------------------------------------- 1 | Set-PSFScriptblock -Name 'PSFramework.Validate.SafeName' -Scriptblock { 2 | $_ -match '^[\d\w_\-\.]+$' 3 | } -Global -------------------------------------------------------------------------------- /PSFramework/internal/tepp/scripts/license-name.ps1: -------------------------------------------------------------------------------- 1 | Register-PSFTeppScriptblock -Name 'PSFramework-license-name' -ScriptBlock { 2 | (Get-PSFLicense).Product 3 | } -Global -------------------------------------------------------------------------------- /PSFramework/internal/tepp/scripts/psprovider.ps1: -------------------------------------------------------------------------------- 1 | Register-PSFTeppScriptblock -Name 'PSFramework-utility-psprovider' -ScriptBlock { 2 | (Get-PSProvider).Name 3 | } -Global -------------------------------------------------------------------------------- /PSFramework/en-us/stringsComputerManagement.psd1: -------------------------------------------------------------------------------- 1 | @{ 2 | # New-PSFSessionContainer 3 | 'New-PSFSessionContainer.UnknownSessionType' = 'Unknown type of session: {0} | From {1}' 4 | } -------------------------------------------------------------------------------- /PSFramework/internal/tepp/scripts/callback-name.ps1: -------------------------------------------------------------------------------- 1 | Register-PSFTeppScriptblock -Name 'PSFramework.Callback.Name' -ScriptBlock { 2 | (Get-PSFCallback).Name | Select-Object -Unique 3 | } -Global -------------------------------------------------------------------------------- /PSFramework/tests/testdata/configdata.json: -------------------------------------------------------------------------------- 1 | { 2 | "FullName": "config.import.test", 3 | "Type": 3, 4 | "Version": 1, 5 | "Value": "42", 6 | "Style": "Default" 7 | } 8 | -------------------------------------------------------------------------------- /PSFramework/internal/scriptblocks/filters.validate.ps1: -------------------------------------------------------------------------------- 1 | Set-PSFScriptblock -Name 'PSFramework.Validate.Filter.ConditionName' -Scriptblock { 2 | $_ -match '^[\d\w_]+$' -and $_ -notin 0,1 3 | } -Global -------------------------------------------------------------------------------- /PSFramework/internal/tepp/scripts/config-schema.ps1: -------------------------------------------------------------------------------- 1 | Register-PSFTeppScriptblock -Name 'PSFramework-Config-Schema' -ScriptBlock { 2 | [PSFramework.Configuration.ConfigurationHost]::Schemata.Keys 3 | } -Global -------------------------------------------------------------------------------- /PSFramework/internal/scripts/strings.ps1: -------------------------------------------------------------------------------- 1 | Import-PSFLocalizedString -Path "$script:ModuleRoot\en-us\*.psd1" -Module PSFramework -Language 'en-US' 2 | 3 | $script:strings = Get-PSFLocalizedString -Module PSFramework -------------------------------------------------------------------------------- /PSFramework/internal/tepp/scripts/config-validation.ps1: -------------------------------------------------------------------------------- 1 | Register-PSFTeppScriptblock -Name 'PSFramework-config-validation' -ScriptBlock { 2 | [PSFramework.Configuration.ConfigurationHost]::Validation.Keys 3 | } -Global -------------------------------------------------------------------------------- /PSFramework/internal/tepp/scripts/pathName.ps1: -------------------------------------------------------------------------------- 1 | Register-PSFTeppScriptblock -Name 'PSFramework.Utility.PathName' -ScriptBlock { 2 | (Get-PSFConfig "PSFramework.Path.*").Name -replace '^.+\.([^\.]+)$', '$1' 3 | } -Global -------------------------------------------------------------------------------- /PSFramework/internal/tepp/scripts/dynamiccontentobject-name.ps1: -------------------------------------------------------------------------------- 1 | Register-PSFTeppScriptblock -Name 'PSFramework-dynamiccontentobject-name' -ScriptBlock { 2 | [PSFramework.Utility.DynamicContentObject]::List 3 | } -Global -------------------------------------------------------------------------------- /PSFramework/en-us/stringsTaskEngine.psd1: -------------------------------------------------------------------------------- 1 | @{ 2 | 'Disable-PSFTaskEngineTask.Disabling' = "Disabling task engine task: {0}" # $item.Name 3 | 4 | 'Enable-PSFTaskEngineTask.Enable' = "Enabling task engine task: {0}" # $item.Name 5 | } -------------------------------------------------------------------------------- /PSFramework/internal/scriptblocks/timespan.validate.ps1: -------------------------------------------------------------------------------- 1 | Set-PSFScriptblock -Name 'PSFramework.Validate.TimeSpan.Positive' -Scriptblock { 2 | if ($_ -is [PSFTimeSpan]) { $_.Value.Ticks -gt 0 } 3 | else { $_.Ticks -gt 0 } 4 | } -Global -------------------------------------------------------------------------------- /PSFramework/internal/tepp/scripts/config-module.ps1: -------------------------------------------------------------------------------- 1 | Register-PSFTeppScriptblock -Name "PSFramework-config-module" -ScriptBlock { 2 | [PSFramework.Configuration.ConfigurationHost]::Configurations.Values.Module | Select-Object -Unique 3 | } -Global -------------------------------------------------------------------------------- /PSFramework/tests/functions/readme.md: -------------------------------------------------------------------------------- 1 | # Description 2 | This is where the function tests go. 3 | Make sure to put them in folders reflecting the actual module structure. 4 | It is not necessary to differentiate between internal and public functions here. -------------------------------------------------------------------------------- /PSFramework/functions/readme.md: -------------------------------------------------------------------------------- 1 | # Functions 2 | 3 | This is the folder where the functions go. 4 | 5 | Depending on the complexity of the module, it is recommended to subdivide them into subfolders. 6 | 7 | The module will pick up all .ps1 files recursively -------------------------------------------------------------------------------- /PSFramework/internal/tepp/scripts/runspace.ps1: -------------------------------------------------------------------------------- 1 | Register-PSFTeppScriptblock -Name 'PSFramework-runspace-name' -ScriptBlock { 2 | (Get-PSFRunspace).Name 3 | } -Global 4 | 5 | Register-PSFTeppScriptblock -Name 'PSFramework-runspace-workflow-name' -ScriptBlock { 6 | (Get-PSFRunspaceWorkflow).Name 7 | } -Global -------------------------------------------------------------------------------- /PSFramework/tests/functions/runspace/Read-PSFRunspaceQueue.Tests.ps1: -------------------------------------------------------------------------------- 1 | Describe "Testing the command XXX" -Tag "CI", "Pipeline", "Unit" { 2 | BeforeEach { 3 | & (Get-Module PSFramework) { $script:runspaceWorkflows = @{ } } 4 | } 5 | AfterAll { 6 | & (Get-Module PSFramework) { $script:runspaceWorkflows = @{ } } 7 | } 8 | } -------------------------------------------------------------------------------- /PSFramework/tests/functions/runspace/Start-PSFRunspaceWorker.Tests.ps1: -------------------------------------------------------------------------------- 1 | Describe "Testing the command XXX" -Tag "CI", "Pipeline", "Unit" { 2 | BeforeEach { 3 | & (Get-Module PSFramework) { $script:runspaceWorkflows = @{ } } 4 | } 5 | AfterAll { 6 | & (Get-Module PSFramework) { $script:runspaceWorkflows = @{ } } 7 | } 8 | } -------------------------------------------------------------------------------- /PSFramework/tests/functions/runspace/Stop-PSFRunspaceDispatcher.Tests.ps1: -------------------------------------------------------------------------------- 1 | Describe "Testing the command XXX" -Tag "CI", "Pipeline", "Unit" { 2 | BeforeEach { 3 | & (Get-Module PSFramework) { $script:runspaceWorkflows = @{ } } 4 | } 5 | AfterAll { 6 | & (Get-Module PSFramework) { $script:runspaceWorkflows = @{ } } 7 | } 8 | } -------------------------------------------------------------------------------- /PSFramework/tests/functions/runspace/Stop-PSFRunspaceWorker.Tests.ps1: -------------------------------------------------------------------------------- 1 | Describe "Testing the command XXX" -Tag "CI", "Pipeline", "Unit" { 2 | BeforeEach { 3 | & (Get-Module PSFramework) { $script:runspaceWorkflows = @{ } } 4 | } 5 | AfterAll { 6 | & (Get-Module PSFramework) { $script:runspaceWorkflows = @{ } } 7 | } 8 | } -------------------------------------------------------------------------------- /PSFramework/tests/functions/runspace/Write-PSFRunspaceQueue.Tests.ps1: -------------------------------------------------------------------------------- 1 | Describe "Testing the command XXX" -Tag "CI", "Pipeline", "Unit" { 2 | BeforeEach { 3 | & (Get-Module PSFramework) { $script:runspaceWorkflows = @{ } } 4 | } 5 | AfterAll { 6 | & (Get-Module PSFramework) { $script:runspaceWorkflows = @{ } } 7 | } 8 | } -------------------------------------------------------------------------------- /PSFramework/tests/functions/runspace/Remove-PSFRunspaceDispatcher.Tests.ps1: -------------------------------------------------------------------------------- 1 | Describe "Testing the command XXX" -Tag "CI", "Pipeline", "Unit" { 2 | BeforeEach { 3 | & (Get-Module PSFramework) { $script:runspaceWorkflows = @{ } } 4 | } 5 | AfterAll { 6 | & (Get-Module PSFramework) { $script:runspaceWorkflows = @{ } } 7 | } 8 | } -------------------------------------------------------------------------------- /PSFramework/tests/functions/runspace/Start-PSFRunspaceDispatcher.Tests.ps1: -------------------------------------------------------------------------------- 1 | Describe "Testing the command XXX" -Tag "CI", "Pipeline", "Unit" { 2 | BeforeEach { 3 | & (Get-Module PSFramework) { $script:runspaceWorkflows = @{ } } 4 | } 5 | AfterAll { 6 | & (Get-Module PSFramework) { $script:runspaceWorkflows = @{ } } 7 | } 8 | } -------------------------------------------------------------------------------- /PSFramework/tests/testdata/utility/ImportPsd1.psd1: -------------------------------------------------------------------------------- 1 | @{ 2 | Name = "Fred" 3 | Age = 66 4 | Soul = @{ 5 | Color = "Black" 6 | Size = 0.002 7 | Exists = $false 8 | States = @( 9 | "Rotten" 10 | "Corrupted" 11 | ) 12 | Owner = $null 13 | } 14 | } 15 | @{ 16 | Name = "Max" 17 | Nachname = "Mustermann" 18 | } -------------------------------------------------------------------------------- /library/PSFramework/Parameter/ParameterClassAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace PSFramework.Parameter 4 | { 5 | /// 6 | /// Attribute marking a class 7 | /// 8 | [AttributeUsage(AttributeTargets.Class)] 9 | public class ParameterClassAttribute : Attribute 10 | { 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /PSFramework/internal/tepp/scripts/scriptblocks.ps1: -------------------------------------------------------------------------------- 1 | Register-PSFTeppScriptblock -Name 'PSFramework.Utility.Scriptblock.Name' -ScriptBlock { 2 | (Get-PSFScriptblock -List).Name 3 | } -Global 4 | 5 | Register-PSFTeppScriptblock -Name 'PSFramework.Utility.Scriptblock.Tag' -ScriptBlock { 6 | (Get-PSFScriptblock -List).Tag | Sort-Object -Unique 7 | } -Global -------------------------------------------------------------------------------- /PSFramework/tests/testdata/utility/ImportJson.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "Name": "Fred", 4 | "Age": 66, 5 | "Soul": { 6 | "Color": "Black", 7 | "Size": 0.002, 8 | "Exists": false, 9 | "States": [ 10 | "Rotten", 11 | "Corrupted" 12 | ], 13 | "Owner": null 14 | } 15 | }, 16 | { 17 | "Name": "Max", 18 | "Nachname": "Mustermann" 19 | } 20 | ] -------------------------------------------------------------------------------- /PSFramework/internal/configurations/serialization.ps1: -------------------------------------------------------------------------------- 1 | # The path where type-files are stored when registered 2 | Set-PSFConfig -Module PSFramework -Name 'Serialization.WorkingDirectory' -Value $script:path_typedata -Initialize -Validation "string" -Description "The folder in which registered type extension files are placed before import. Relevant for Register-PSFTypeSerializationData." -------------------------------------------------------------------------------- /PSFramework/internal/tepp/scripts/config-fullname.ps1: -------------------------------------------------------------------------------- 1 | Register-PSFTeppScriptblock -Name "PSFramework-config-fullname" -ScriptBlock { 2 | [PSFramework.Configuration.ConfigurationHost]::Configurations.Values | Where-Object { 3 | -not $_.Hidden 4 | } | ForEach-Object { 5 | [PSCustomObject]@{ 6 | Text = $_.FullName 7 | ToolTip = $_.Description 8 | } 9 | } 10 | } -Global -------------------------------------------------------------------------------- /PSFramework/internal/parameters/readme.md: -------------------------------------------------------------------------------- 1 | # Parameters 2 | 3 | The PSFramework delivers dedicated, extensible parameter classes, that act as input converters. 4 | It is possible to add support for additional input types by mapping the properties of the respective type. 5 | 6 | All such additional mappings that ship within the PSFramework itself are stored here and can be used for reference. -------------------------------------------------------------------------------- /library/PSFramework/PSFCore/NoJeaCommandAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace PSFramework.PSFCore 4 | { 5 | /// 6 | /// Decorator attribute declaring a command in its entirety unsafe for making publicly available in JEA 7 | /// 8 | [AttributeUsage(AttributeTargets.All)] 9 | public class NoJeaCommandAttribute : Attribute 10 | { 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /PSFramework/internal/configurationvalidation/integerarray.ps1: -------------------------------------------------------------------------------- 1 | Register-PSFConfigValidation -Name "integerarray" -ScriptBlock { 2 | param ( 3 | $var 4 | ) 5 | 6 | $test = $true 7 | try { [int[]]$res = $var } 8 | catch { $test = $false } 9 | 10 | [pscustomobject]@{ 11 | Success = $test 12 | Value = $res 13 | Message = "Casting $var as [int[]] failure. Input is being identified as $($var.GetType())" 14 | } 15 | } -------------------------------------------------------------------------------- /PSFramework/en-us/stringsImport.psd1: -------------------------------------------------------------------------------- 1 | @{ 2 | 'Register-PSFParameterClassMapping.NotImplemented' = "Support for the {0} parameter class has not yet been added!" # $ParameterClass 3 | 'Register-PSFParameterClassMapping.Registration.Error' = "Failed to update property mapping for {0} : {1}. This is likely happening on some Linux distributions due to an underlying .NET issue and means the parameter class cannot be used." # $ParameterClass, $Typename 4 | } -------------------------------------------------------------------------------- /PSFramework/internal/tepp/scripts/encoding.ps1: -------------------------------------------------------------------------------- 1 | Register-PSFTeppScriptblock -Name "PSFramework-Encoding" -ScriptBlock { 2 | 'Unicode' 3 | 'BigEndianUnicode' 4 | 'UTF8' 5 | 'UTF8Bom' 6 | 'UTF8NoBom' 7 | 'UTF7' 8 | 'UTF32' 9 | 'Ascii' 10 | 'Default' 11 | 'BigEndianUTF32' 12 | if (Get-PSFConfigValue -FullName 'PSFramework.Text.Encoding.FullTabCompletion') 13 | { 14 | [System.Text.Encoding]::GetEncodings().BodyName 15 | } 16 | } -Global -------------------------------------------------------------------------------- /PSFramework/internal/configurations/computermanagement.ps1: -------------------------------------------------------------------------------- 1 | Set-PSFConfig -Module 'PSFramework' -Name 'ComputerManagement.PSSession.IdleTimeout' -Value (New-TimeSpan -Minutes 15) -Initialize -Validation 'timespan' -Handler { [PSFramework.ComputerManagement.ComputerManagementHost]::PSSessionIdleTimeout = $args[0] } -Description "The idle timeout for cached pssessions. When using Invoke-PSFCommand, it will remember sessions for up to this time after last using them, before cleaning them up." -------------------------------------------------------------------------------- /PSFramework/internal/scripts/sessionRegistration.ps1: -------------------------------------------------------------------------------- 1 | # Load Session Registrations for the Session Container feature 2 | # See: New-PSSessionContainer 3 | 4 | Register-PSFSessionObjectType -DisplayName CimSession -TypeName Microsoft.Management.Infrastructure.CimSession 5 | Register-PSFSessionObjectType -DisplayName PSSession -TypeName System.Management.Automation.Runspaces.PSSession 6 | Register-PSFSessionObjectType -DisplayName SmoServer -TypeName Microsoft.SqlServer.Management.Smo.Server -------------------------------------------------------------------------------- /.github/workflows/validate.yml: -------------------------------------------------------------------------------- 1 | on: [pull_request] 2 | 3 | jobs: 4 | validate: 5 | 6 | runs-on: windows-latest 7 | 8 | steps: 9 | - uses: actions/checkout@v1 10 | - name: Install Prerequisites 11 | run: .\build\psf-prerequisites.ps1 12 | shell: powershell 13 | - name: Install Prerequisites 14 | run: .\build\vsts-help.ps1 15 | shell: powershell 16 | - name: Validate 17 | run: .\build\vsts-validate.ps1 18 | shell: powershell -------------------------------------------------------------------------------- /PSFramework/internal/tepp/scripts/parametersetNames.ps1: -------------------------------------------------------------------------------- 1 | Register-PSFTeppScriptblock -Name 'PSFramework.Utility.ParameterSetNames' -ScriptBlock { 2 | $referenceCommandName = $fakeBoundParameter.ReferenceCommand 3 | if (-not $referenceCommandName) { return } 4 | 5 | $commandInfo = Get-Command -Name $referenceCommandName -ErrorAction SilentlyContinue | Microsoft.PowerShell.Utility\Select-Object -First 1 6 | if (-not $commandInfo) { return } 7 | 8 | $commandInfo.ParameterSets.Name 9 | } -Global -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "editor.detectIndentation": false, 3 | "editor.insertSpaces": false, 4 | "powershell.codeFormatting.pipelineIndentationStyle": "IncreaseIndentationAfterEveryPipeline", 5 | "powershell.codeFormatting.trimWhitespaceAroundPipe": true, 6 | "powershell.codeFormatting.whitespaceBetweenParameters": true, 7 | "powershell.codeFormatting.autoCorrectAliases": true, 8 | "powershell.codeFormatting.useCorrectCasing": true, 9 | 10 | "files.encoding": "utf8bom", 11 | } -------------------------------------------------------------------------------- /PSFramework/internal/configurationvalidation/guid.ps1: -------------------------------------------------------------------------------- 1 | Register-PSFConfigValidation -Name "guid" -ScriptBlock { 2 | Param ( 3 | $Value 4 | ) 5 | 6 | $Result = [PSCustomObject]@{ 7 | Success = $True 8 | Value = $null 9 | Message = "" 10 | } 11 | 12 | try { [guid]$guid = $Value } 13 | catch 14 | { 15 | $Result.Message = "Not a GUID: $Value" 16 | $Result.Success = $False 17 | return $Result 18 | } 19 | 20 | $Result.Value = $guid 21 | 22 | return $Result 23 | } 24 | -------------------------------------------------------------------------------- /PSFramework/internal/configurationvalidation/long.ps1: -------------------------------------------------------------------------------- 1 | Register-PSFConfigValidation -Name "long" -ScriptBlock { 2 | Param ( 3 | $Value 4 | ) 5 | 6 | $Result = [PSCustomObject]@{ 7 | Success = $True 8 | Value = $null 9 | Message = "" 10 | } 11 | 12 | try { [long]$number = $Value } 13 | catch 14 | { 15 | $Result.Message = "Not a long: $Value" 16 | $Result.Success = $False 17 | return $Result 18 | } 19 | 20 | $Result.Value = $number 21 | 22 | return $Result 23 | } -------------------------------------------------------------------------------- /PSFramework/internal/configurationvalidation/integer.ps1: -------------------------------------------------------------------------------- 1 | Register-PSFConfigValidation -Name "integer" -ScriptBlock { 2 | Param ( 3 | $Value 4 | ) 5 | 6 | $Result = [PSCustomObject]@{ 7 | Success = $True 8 | Value = $null 9 | Message = "" 10 | } 11 | 12 | try { [int]$number = $Value } 13 | catch 14 | { 15 | $Result.Message = "Not an integer: $Value" 16 | $Result.Success = $False 17 | return $Result 18 | } 19 | 20 | $Result.Value = $number 21 | 22 | return $Result 23 | } -------------------------------------------------------------------------------- /PSFramework/internal/scripts/preimport.ps1: -------------------------------------------------------------------------------- 1 | $moduleRoot = Split-Path (Split-Path $PSScriptRoot) 2 | 3 | # Load Assembly 4 | "$($moduleRoot)\bin\assembly.ps1" 5 | 6 | # Load "Environment" variables within the module 7 | "$($moduleRoot)\internal\scripts\environment.ps1" 8 | 9 | # Load Tab Expansion Plus Plus code (PS4 or older) 10 | "$($moduleRoot)\internal\scripts\teppCoreCode.ps1" 11 | 12 | # Load resources for TEPP input completion 13 | "$($moduleRoot)\internal\scripts\teppSimpleCompleter.ps1" -------------------------------------------------------------------------------- /library/PSFramework/PSFCore/NoJeaParameterAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace PSFramework.PSFCore 8 | { 9 | /// 10 | /// The thus tagged parameter is not safe to publish with JEA 11 | /// 12 | [AttributeUsage(AttributeTargets.All)] 13 | public class NoJeaParameterAttribute : Attribute 14 | { 15 | 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /PSFramework/functions/utility/Enable-PSFConsoleInterrupt.ps1: -------------------------------------------------------------------------------- 1 | function Enable-PSFConsoleInterrupt { 2 | <# 3 | .SYNOPSIS 4 | Re-enables the use of CTRL+C to interrupt the console. 5 | 6 | .DESCRIPTION 7 | Re-enables the use of CTRL+C to interrupt the console. 8 | 9 | .EXAMPLE 10 | PS C:\> Enable-PSFConsoleInterrupt 11 | 12 | Re-enables the use of CTRL+C to interrupt the console. 13 | #> 14 | [CmdletBinding()] 15 | param () 16 | 17 | [Console]::TreatControlCAsInput = $false 18 | } -------------------------------------------------------------------------------- /PSFramework/internal/configurationvalidation/double.ps1: -------------------------------------------------------------------------------- 1 | Register-PSFConfigValidation -Name "double" -ScriptBlock { 2 | Param ( 3 | $Value 4 | ) 5 | 6 | $Result = [PSCustomObject]@{ 7 | Success = $True 8 | Value = $null 9 | Message = "" 10 | } 11 | 12 | try { [double]$number = $Value } 13 | catch 14 | { 15 | $Result.Message = "Not a double: $Value" 16 | $Result.Success = $False 17 | return $Result 18 | } 19 | 20 | $Result.Value = $number 21 | 22 | return $Result 23 | } -------------------------------------------------------------------------------- /PSFramework/internal/tepp/scripts/config-name.ps1: -------------------------------------------------------------------------------- 1 | Register-PSFTeppScriptblock -Name "PSFramework-config-name" -ScriptBlock { 2 | $moduleName = "*" 3 | if ($fakeBoundParameter.Module) { $moduleName = $fakeBoundParameter.Module } 4 | [PSFramework.Configuration.ConfigurationHost]::Configurations.Values | Where-Object { 5 | -not $_.Hidden -and ($_.Module -like $moduleName) 6 | } | ForEach-Object { 7 | [PSCustomObject]@{ 8 | Text = $_.Name 9 | ToolTip = $_.Description 10 | } 11 | } 12 | } -Global -------------------------------------------------------------------------------- /library/PSFramework/Serialization/ClixmlDataStyle.cs: -------------------------------------------------------------------------------- 1 | namespace PSFramework.Serialization 2 | { 3 | /// 4 | /// The serialization output options available 5 | /// 6 | public enum ClixmlDataStyle 7 | { 8 | /// 9 | /// Serialize to and from string 10 | /// 11 | String = 1, 12 | 13 | /// 14 | /// Serialize to and from byte 15 | /// 16 | Byte = 2 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /PSFramework/internal/configurationvalidation/datetime.ps1: -------------------------------------------------------------------------------- 1 | Register-PSFConfigValidation -Name "datetime" -ScriptBlock { 2 | Param ( 3 | $Value 4 | ) 5 | 6 | $Result = [PSCustomObject]@{ 7 | Success = $True 8 | Value = $null 9 | Message = "" 10 | } 11 | 12 | try { [DateTime]$DateTime = $Value } 13 | catch 14 | { 15 | $Result.Message = "Not a DateTime: $Value" 16 | $Result.Success = $False 17 | return $Result 18 | } 19 | 20 | $Result.Value = $DateTime 21 | 22 | return $Result 23 | } -------------------------------------------------------------------------------- /PSFramework/internal/configurationvalidation/consolecolor.ps1: -------------------------------------------------------------------------------- 1 | Register-PSFConfigValidation -Name "consolecolor" -ScriptBlock { 2 | Param ( 3 | $Value 4 | ) 5 | 6 | $Result = [PSCustomObject]@{ 7 | Success = $True 8 | Value = $null 9 | Message = "" 10 | } 11 | 12 | try { [System.ConsoleColor]$color = $Value } 13 | catch 14 | { 15 | $Result.Message = "Not a console color: $Value" 16 | $Result.Success = $False 17 | return $Result 18 | } 19 | 20 | $Result.Value = $color 21 | 22 | return $Result 23 | } -------------------------------------------------------------------------------- /PSFramework/bin/type-extensions.ps1: -------------------------------------------------------------------------------- 1 | #region Configuration Static Remove() Compatibility 2 | Update-TypeData -TypeName "System.Collections.Concurrent.ConcurrentDictionary``2[[$([System.String].AssemblyQualifiedName)],[$([PSFramework.Configuration.Config].AssemblyQualifiedName)]]" -MemberType ScriptMethod -MemberName Remove -Value ([scriptblock]::Create(@' 3 | param ( 4 | $Item 5 | ) 6 | 7 | $dummyItem = $null 8 | $null = $this.TryRemove($Item, [ref] $dummyItem) 9 | '@)) -Force 10 | #endregion Configuration Static Remove() Compatibility -------------------------------------------------------------------------------- /PSFramework/internal/configurationvalidation/timespan.ps1: -------------------------------------------------------------------------------- 1 | Register-PSFConfigValidation -Name "timespan" -ScriptBlock { 2 | Param ( 3 | $Value 4 | ) 5 | 6 | $Result = [PSCustomObject]@{ 7 | Success = $True 8 | Value = $null 9 | Message = "" 10 | } 11 | 12 | try { [timespan]$timespan = [PSFramework.Parameter.TimeSpanParameter]$Value } 13 | catch 14 | { 15 | $Result.Message = "Not a Timespan: $Value" 16 | $Result.Success = $False 17 | return $Result 18 | } 19 | 20 | $Result.Value = $timespan 21 | 22 | return $Result 23 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # ignore the settings folder and files for VSCode and PSS 3 | *.psproj 4 | *TempPoint* 5 | 6 | # Ignore staging info from Visual Studio 7 | library/.vs/* 8 | library/PSFramework/bin/* 9 | library/PSFramework/obj/* 10 | library/PSFramework/.vs/* 11 | 12 | # ignore PowerShell Studio MetaData 13 | PSFramework/PSFramework.psproj 14 | PSFramework/PSFramework.psproj.bak 15 | PSFramework/PSFramework.psprojs 16 | PSFramework/PSFramework.psproj 17 | 18 | # ignore the TestResults 19 | TestResults/* 20 | 21 | # ignore the publishing Directory 22 | publish/* -------------------------------------------------------------------------------- /PSFramework/functions/message/Clear-PSFMessage.ps1: -------------------------------------------------------------------------------- 1 | function Clear-PSFMessage { 2 | <# 3 | .SYNOPSIS 4 | Clears the in-memory log of the message system. 5 | 6 | .DESCRIPTION 7 | Clears the in-memory log of the message system. 8 | Has no effect on written logfiles, table entries, eventlog logs or wherever else you may be logging. 9 | 10 | .EXAMPLE 11 | PS C:\> Clear-PSFMessage 12 | 13 | Clears the in-memory log of the message system. 14 | #> 15 | [CmdletBinding()] 16 | param () 17 | 18 | process { 19 | [PSFramework.Message.LogHost]::ClearLog() 20 | } 21 | } -------------------------------------------------------------------------------- /PSFramework/en-us/about_psf_license.help.txt: -------------------------------------------------------------------------------- 1 | TOPIC 2 | about_psf_license 3 | 4 | SHORT DESCRIPTION 5 | Explains the PSFrameworks license component 6 | 7 | LONG DESCRIPTION 8 | #-------------------------------------------------------------------------# 9 | # Component Commands # 10 | #-------------------------------------------------------------------------# 11 | 12 | - Get-PSFLicense 13 | - New-PSFLicense 14 | - Remove-PSFLicense 15 | 16 | 17 | 18 | KEYWORDS 19 | psframework license -------------------------------------------------------------------------------- /PSFramework/internal/configurationvalidation/uriabsolute.ps1: -------------------------------------------------------------------------------- 1 | Register-PSFConfigValidation -Name "uriabsolute" -ScriptBlock { 2 | param ( 3 | $Value 4 | ) 5 | 6 | $Result = [PSCustomObject]@{ 7 | Success = $True 8 | Value = $null 9 | Message = "" 10 | } 11 | 12 | $stringValue = $Value -as [string] 13 | [uri]$uri = $stringValue 14 | 15 | if (-not $uri.IsAbsoluteUri) 16 | { 17 | $Result.Message = "Not an absolute Uri: $Value" 18 | $Result.Success = $False 19 | return $Result 20 | } 21 | 22 | $Result.Value = $stringValue 23 | 24 | return $Result 25 | } -------------------------------------------------------------------------------- /PSFramework/en-us/about_psf_flowcontrol.help.txt: -------------------------------------------------------------------------------- 1 | TOPIC 2 | about_psf_flowcontrol 3 | 4 | SHORT DESCRIPTION 5 | Explains the PSFrameworks flow control component 6 | 7 | LONG DESCRIPTION 8 | #-------------------------------------------------------------------------# 9 | # Component Commands # 10 | #-------------------------------------------------------------------------# 11 | 12 | - Stop-PSFFunction 13 | - Test-PSFFunctionInterrupt 14 | 15 | 16 | 17 | KEYWORDS 18 | psframework flowcontrol -------------------------------------------------------------------------------- /PSFramework/internal/configurationvalidation/guidarray.ps1: -------------------------------------------------------------------------------- 1 | Register-PSFConfigValidation -Name "guidarray" -ScriptBlock { 2 | param ( 3 | $Value 4 | ) 5 | 6 | $Result = [PSCustomObject]@{ 7 | Success = $True 8 | Value = $null 9 | Message = "" 10 | } 11 | 12 | try 13 | { 14 | $data = @() 15 | foreach ($item in $Value) 16 | { 17 | $data += [guid]$item 18 | } 19 | } 20 | catch 21 | { 22 | $Result.Message = "Not a guid array: $Value" 23 | $Result.Success = $False 24 | return $Result 25 | } 26 | 27 | $Result.Value = $data 28 | 29 | return $Result 30 | } -------------------------------------------------------------------------------- /PSFramework/internal/configurationvalidation/sizestyle.ps1: -------------------------------------------------------------------------------- 1 | Register-PSFConfigValidation -Name "sizestyle" -ScriptBlock { 2 | param ( 3 | $Value 4 | ) 5 | 6 | $Result = [PSCustomObject]@{ 7 | Success = $True 8 | Value = $null 9 | Message = "" 10 | } 11 | 12 | try { [PSFramework.Utility.SizeStyle]$style = $Value } 13 | catch { 14 | $Result.Message = "Not a size style: $Value" 15 | $Result.Success = $False 16 | return $Result 17 | } 18 | 19 | $Result.Value = $style 20 | 21 | return $Result 22 | } -------------------------------------------------------------------------------- /PSFramework/functions/feature/Get-PSFFeature.ps1: -------------------------------------------------------------------------------- 1 | function Get-PSFFeature 2 | { 3 | <# 4 | .SYNOPSIS 5 | Returns a list of all registered features. 6 | 7 | .DESCRIPTION 8 | Returns a list of all registered features. 9 | 10 | .PARAMETER Name 11 | The name to filter by. 12 | 13 | .EXAMPLE 14 | PS C:\> Get-PSFFeature 15 | 16 | Returns all features registered. 17 | #> 18 | [CmdletBinding()] 19 | param ( 20 | [string] 21 | $Name = "*" 22 | ) 23 | 24 | process 25 | { 26 | [PSFramework.Feature.FeatureHost]::Features.Values | Where-Object Name -Like $Name 27 | } 28 | } -------------------------------------------------------------------------------- /library/PSFramework/Filter/ConditionType.cs: -------------------------------------------------------------------------------- 1 | namespace PSFramework.Filter 2 | { 3 | /// 4 | /// What kind of condition is it? 5 | /// 6 | public enum ConditionType 7 | { 8 | /// 9 | /// The condition is static - its value needs only be processed once. 10 | /// 11 | Static, 12 | 13 | /// 14 | /// The condition is dynamic - its value may change and should be evaluated each time. 15 | /// May accept arguments. 16 | /// 17 | Dynamic 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /PSFramework/en-us/about_psf_resultcache.help.txt: -------------------------------------------------------------------------------- 1 | TOPIC 2 | about_psf_resultcache 3 | 4 | SHORT DESCRIPTION 5 | Explains the PSFrameworks result cache component 6 | 7 | LONG DESCRIPTION 8 | #-------------------------------------------------------------------------# 9 | # Component Commands # 10 | #-------------------------------------------------------------------------# 11 | 12 | - Clear-PSFResultCache 13 | - Get-PSFResultCache 14 | - Set-PSFResultCache 15 | 16 | 17 | 18 | KEYWORDS 19 | psframework resultcache -------------------------------------------------------------------------------- /PSFramework/en-us/about_psf_runspace.help.txt: -------------------------------------------------------------------------------- 1 | TOPIC 2 | about_psf_runspace 3 | 4 | SHORT DESCRIPTION 5 | Explains the PSFrameworks runspace component 6 | 7 | LONG DESCRIPTION 8 | #-------------------------------------------------------------------------# 9 | # Component Commands # 10 | #-------------------------------------------------------------------------# 11 | 12 | - Get-PSFRunspace 13 | - Register-PSFRunspace 14 | - Start-PSFRunspace 15 | - Stop-PSFRunspace 16 | 17 | 18 | 19 | KEYWORDS 20 | psframework runspace -------------------------------------------------------------------------------- /library/PSFramework/PSFCore/PsfInternalAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace PSFramework.PSFCore 4 | { 5 | /// 6 | /// Attribute designating something as reserved as PSFramework-internal. 7 | /// Changes to any component marked thus is not considered a breaking change. 8 | /// 9 | [AttributeUsage(AttributeTargets.All)] 10 | internal class PsfInternalAttribute : Attribute 11 | { 12 | /// 13 | /// Allows specifying a description or comments along with the attribute. 14 | /// 15 | public string Description; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /library/PSFramework/Meta/PSTraceSource.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Management.Automation; 6 | 7 | namespace PSFramework.Meta 8 | { 9 | internal class PSTraceSource 10 | { 11 | internal static PSArgumentException NewArgumentException(string paramName) 12 | { 13 | if (string.IsNullOrEmpty(paramName)) 14 | { 15 | throw new ArgumentNullException("paramName"); 16 | } 17 | 18 | return new PSArgumentException(paramName, paramName); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /library/PSFramework/FlowControl/PSEdition.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace PSFramework.FlowControl 8 | { 9 | /// 10 | /// The powershell edition 11 | /// 12 | public enum PSEdition 13 | { 14 | /// 15 | /// The desktop edition of PowerShell - all editions 5.1 or below 16 | /// 17 | Desktop, 18 | 19 | /// 20 | /// .NET core based editions of PowerShell 21 | /// 22 | Core 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /PSFramework/functions/message/Get-PSFMessageColorTransform.ps1: -------------------------------------------------------------------------------- 1 | function Get-PSFMessageColorTransform { 2 | <# 3 | .SYNOPSIS 4 | Lists registered message color rules. 5 | 6 | .DESCRIPTION 7 | Lists registered message color rules. 8 | 9 | .PARAMETER Name 10 | Name by which to filter the rules. 11 | Defaults to: * 12 | 13 | .EXAMPLE 14 | PS C:\> Get-PSFMessageColorTransform 15 | 16 | Lists all registered message color rules. 17 | #> 18 | [CmdletBinding()] 19 | param ( 20 | [string] 21 | $Name = '*' 22 | ) 23 | process { 24 | $([PSFramework.Message.MessageHost]::ColorTransforms.Values) | Where-Object Name -Like $Name 25 | } 26 | } -------------------------------------------------------------------------------- /PSFramework/internal/configurationvalidation/integerpositive.ps1: -------------------------------------------------------------------------------- 1 | Register-PSFConfigValidation -Name "integerpositive" -ScriptBlock { 2 | Param ( 3 | $Value 4 | ) 5 | 6 | $Result = [PSCustomObject]@{ 7 | Success = $True 8 | Value = $null 9 | Message = "" 10 | } 11 | 12 | try { [int]$number = $Value } 13 | catch 14 | { 15 | $Result.Message = "Not an integer: $Value" 16 | $Result.Success = $False 17 | return $Result 18 | } 19 | 20 | if ($number -lt 0) 21 | { 22 | $Result.Message = "Negative value: $Value" 23 | $Result.Success = $False 24 | return $Result 25 | } 26 | 27 | $Result.Value = $number 28 | 29 | return $Result 30 | } -------------------------------------------------------------------------------- /PSFramework/bin/assembly.ps1: -------------------------------------------------------------------------------- 1 | try { 2 | if ($PSVersionTable.PSVersion.Major -ge 5) { 3 | Add-Type -Path "$script:ModuleRoot\bin\PSFramework.dll" -ErrorAction Stop 4 | } 5 | else { 6 | Add-Type -Path "$script:ModuleRoot\bin\PS4\PSFramework.dll" -ErrorAction Stop 7 | } 8 | } 9 | catch { 10 | Write-Warning "Failed to load PSFramework Assembly! Unable to import module." 11 | throw 12 | } 13 | try { 14 | Update-TypeData -AppendPath "$script:ModuleRoot\xml\PSFramework.Types.ps1xml" -ErrorAction Stop 15 | } 16 | catch { 17 | Write-Warning "Failed to load PSFramework type extensions! Unable to import module." 18 | throw 19 | } -------------------------------------------------------------------------------- /PSFramework/internal/configurationvalidation/logfilefiletype.ps1: -------------------------------------------------------------------------------- 1 | Register-PSFConfigValidation -Name "psframework.logfilefiletype" -ScriptBlock { 2 | Param ( 3 | $Value 4 | ) 5 | 6 | $Result = [PSCustomObject]@{ 7 | Success = $True 8 | Value = $null 9 | Message = "" 10 | } 11 | 12 | try { [PSFramework.Logging.LogFileFileType]$type = $Value } 13 | catch 14 | { 15 | $Result.Message = "Not a logfile file type: $Value . Specify one of these values: $(([enum]::GetNames([PSFramework.Logging.LogFileFileType])) -join ", ")" 16 | $Result.Success = $False 17 | return $Result 18 | } 19 | 20 | $Result.Value = $type 21 | 22 | return $Result 23 | } -------------------------------------------------------------------------------- /PSFramework/internal/configurationvalidation/stringarray.ps1: -------------------------------------------------------------------------------- 1 | Register-PSFConfigValidation -Name "stringarray" -ScriptBlock { 2 | Param ( 3 | $Value 4 | ) 5 | 6 | $Result = [PSCustomObject]@{ 7 | Success = $True 8 | Value = $null 9 | Message = "" 10 | } 11 | 12 | try 13 | { 14 | $data = @() 15 | # Seriously, this should work for almost anybody and anything 16 | foreach ($item in $Value) 17 | { 18 | $data += [string]$item 19 | } 20 | } 21 | catch 22 | { 23 | $Result.Message = "Not a string array: $Value" 24 | $Result.Success = $False 25 | return $Result 26 | } 27 | 28 | $Result.Value = $data 29 | 30 | return $Result 31 | } -------------------------------------------------------------------------------- /library/PSFramework/Validation/NoResultsAction.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace PSFramework.Validation 8 | { 9 | /// 10 | /// The preference on how to deal with no legal values being returned. Used by PsfValidateSet 11 | /// 12 | public enum NoResultsActionPreference 13 | { 14 | /// 15 | /// Allow to continue 16 | /// 17 | Continue, 18 | 19 | /// 20 | /// Fail in fire and blood 21 | /// 22 | Error 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /library/PSFramework/Configuration/PersistedConfig.cs: -------------------------------------------------------------------------------- 1 | namespace PSFramework.Configuration 2 | { 3 | /// 4 | /// A setting that has been persisted on the computer. 5 | /// 6 | public class PersistedConfig 7 | { 8 | /// 9 | /// The full name of the setting 10 | /// 11 | public string FullName; 12 | 13 | /// 14 | /// The scope it has been persisted to 15 | /// 16 | public ConfigScope Scope; 17 | 18 | /// 19 | /// The value of the setting 20 | /// 21 | public object Value; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /library/PSFramework/Logging/ProviderVersion.cs: -------------------------------------------------------------------------------- 1 | namespace PSFramework.Logging 2 | { 3 | /// 4 | /// The generation of the Logging Provider Type 5 | /// 6 | public enum ProviderVersion 7 | { 8 | /// 9 | /// The initial, now legacy version of logging providers, where all providers share the same variable scope. 10 | /// 11 | Version_1 = 1, 12 | 13 | /// 14 | /// Generation 2 logging provider, where each provider is handled as a dynamically created module, properly isolating resource from each other. 15 | /// 16 | Version_2 = 2 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /library/PSFramework/Runspace/RSPowerShellWrapper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Management.Automation; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace PSFramework.Runspace 9 | { 10 | internal class RSPowerShellWrapper : IDisposable 11 | { 12 | internal PowerShell Pipe; 13 | internal IAsyncResult Status; 14 | 15 | internal RSPowerShellWrapper(PowerShell pipe, IAsyncResult status) 16 | { 17 | Pipe = pipe; 18 | Status = status; 19 | } 20 | 21 | public void Dispose() 22 | { 23 | Pipe.Dispose(); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /PSFramework/internal/configurationvalidation/credential.ps1: -------------------------------------------------------------------------------- 1 | Register-PSFConfigValidation -Name "credential" -ScriptBlock { 2 | param ( 3 | $Value 4 | ) 5 | 6 | $Result = [PSCustomObject]@{ 7 | Success = $True 8 | Value = $null 9 | Message = "" 10 | } 11 | try 12 | { 13 | if ($Value.GetType().FullName -ne "System.Management.Automation.PSCredential") 14 | { 15 | $Result.Message = "Not a credential: $Value" 16 | $Result.Success = $False 17 | return $Result 18 | } 19 | } 20 | catch 21 | { 22 | $Result.Message = "Not a credential: $Value" 23 | $Result.Success = $False 24 | return $Result 25 | } 26 | 27 | $Result.Value = $Value 28 | 29 | return $Result 30 | } -------------------------------------------------------------------------------- /PSFramework/internal/configurationvalidation/integer0to9.ps1: -------------------------------------------------------------------------------- 1 | Register-PSFConfigValidation -Name "integer0to9" -ScriptBlock { 2 | Param ( 3 | $Value 4 | ) 5 | 6 | $Result = [PSCustomObject]@{ 7 | Success = $True 8 | Value = $null 9 | Message = "" 10 | } 11 | 12 | try { [int]$number = $Value } 13 | catch 14 | { 15 | $Result.Message = "Not an integer: $Value" 16 | $Result.Success = $False 17 | return $Result 18 | } 19 | 20 | if (($number -lt 0) -or ($number -gt 9)) 21 | { 22 | $Result.Message = "Out of range. Specify a number ranging from 0 to 9" 23 | $Result.Success = $False 24 | return $Result 25 | } 26 | 27 | $Result.Value = $Number 28 | 29 | return $Result 30 | } -------------------------------------------------------------------------------- /PSFramework/internal/configurationvalidation/integer1to9.ps1: -------------------------------------------------------------------------------- 1 | Register-PSFConfigValidation -Name "integer1to9" -ScriptBlock { 2 | param ( 3 | $Value 4 | ) 5 | 6 | $Result = [PSCustomObject]@{ 7 | Success = $True 8 | Value = $null 9 | Message = "" 10 | } 11 | 12 | try { [int]$number = $Value } 13 | catch 14 | { 15 | $Result.Message = "Not an integer: $Value" 16 | $Result.Success = $False 17 | return $Result 18 | } 19 | 20 | if (($number -lt 1) -or ($number -gt 9)) 21 | { 22 | $Result.Message = "Out of range. Specify a number ranging from 1 to 9" 23 | $Result.Success = $False 24 | return $Result 25 | } 26 | 27 | $Result.Value = $Number 28 | 29 | return $Result 30 | } -------------------------------------------------------------------------------- /PSFramework/internal/configurationvalidation/bool.ps1: -------------------------------------------------------------------------------- 1 | Register-PSFConfigValidation -Name "bool" -ScriptBlock { 2 | Param ( 3 | $Value 4 | ) 5 | 6 | $Result = [PSCustomObject]@{ 7 | Success = $True 8 | Value = $null 9 | Message = "" 10 | } 11 | try 12 | { 13 | if ($Value.GetType().FullName -notin "System.Boolean", 'System.Management.Automation.SwitchParameter') 14 | { 15 | $Result.Message = "Not a boolean: $Value" 16 | $Result.Success = $False 17 | return $Result 18 | } 19 | } 20 | catch 21 | { 22 | $Result.Message = "Not a boolean: $Value" 23 | $Result.Success = $False 24 | return $Result 25 | } 26 | 27 | $Result.Value = $Value -as [bool] 28 | 29 | return $Result 30 | } -------------------------------------------------------------------------------- /PSFramework/internal/tepp/scripts/localization.ps1: -------------------------------------------------------------------------------- 1 | Register-PSFTeppScriptblock -Name 'PSFramework-LanguageNames' -ScriptBlock { 2 | [System.Globalization.CultureInfo]::GetCultures([System.Globalization.CultureTypes]::AllCultures).Name | Where-Object { $_ -and ($_.Trim()) } 3 | } -Global 4 | 5 | Register-PSFTeppScriptblock -Name 'PSFramework-LocalizedStrings-Names' -ScriptBlock { 6 | ([PSFRamework.Localization.LocalizationHost]::Strings.Values | Where-Object Module -EQ $fakeBoundParameter.Module).Name 7 | } -Global 8 | 9 | Register-PSFTeppScriptblock -Name 'PSFramework-LocalizedStrings-Modules' -ScriptBlock { 10 | [PSFRamework.Localization.LocalizationHost]::Strings.Values.Module | Select-Object -Unique 11 | } -Global -------------------------------------------------------------------------------- /PSFramework/internal/configurationvalidation/languagecode.ps1: -------------------------------------------------------------------------------- 1 | Register-PSFConfigValidation -Name "languagecode" -ScriptBlock { 2 | param ( 3 | $Value 4 | ) 5 | 6 | $Result = [PSCustomObject]@{ 7 | Success = $True 8 | Value = $null 9 | Message = "" 10 | } 11 | 12 | $legal = [System.Globalization.CultureInfo]::GetCultures([System.Globalization.CultureTypes]::AllCultures).Name | Where-Object { $_ -and ($_.Trim()) } 13 | 14 | if ($Value -in $legal) 15 | { 16 | $Result.Value = [string]$Value 17 | } 18 | else 19 | { 20 | $Result.Success = $false 21 | $Result.Message = [PSFramework.Localization.LocalizationHost]::Read('PSFramework.Configuration_ValidateLanguage') 22 | } 23 | 24 | return $Result 25 | } -------------------------------------------------------------------------------- /library/PSFramework/Runspace/RunspaceState.cs: -------------------------------------------------------------------------------- 1 | namespace PSFramework.Runspace 2 | { 3 | /// 4 | /// Contains the state a managed, unique runspace can be in. 5 | /// 6 | public enum PsfRunspaceState 7 | { 8 | /// 9 | /// The runspace is up and running 10 | /// 11 | Running = 1, 12 | 13 | /// 14 | /// The runspace has received the stop order, but has not yet obeyed it 15 | /// 16 | Stopping = 2, 17 | 18 | /// 19 | /// The runspace has followed its order to stop and is currently disabled 20 | /// 21 | Stopped = 3, 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /library/PSFramework/Temp/TempItemType.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace PSFramework.Temp 8 | { 9 | /// 10 | /// What kind of temp item is the object? 11 | /// 12 | public enum TempItemType 13 | { 14 | /// 15 | /// A regular file 16 | /// 17 | File = 1, 18 | 19 | /// 20 | /// A regular folder / directory 21 | /// 22 | Directory = 2, 23 | 24 | /// 25 | /// A generic item type 26 | /// 27 | Generic = 3 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /library/PSFramework/FlowControl/OperatingSystem.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace PSFramework.FlowControl 8 | { 9 | /// 10 | /// The various operating systems PowerShell can run on 11 | /// 12 | public enum OperatingSystem 13 | { 14 | /// 15 | /// Common windows OS 16 | /// 17 | Windows, 18 | 19 | /// 20 | /// Any Linux distribution 21 | /// 22 | Linux, 23 | 24 | /// 25 | /// Any Mac Operating System 26 | /// 27 | MacOS 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /PSFramework/en-us/stringsSerialization.psd1: -------------------------------------------------------------------------------- 1 | @{ 2 | 'ConvertFrom-PSFClixml.BadInput' = "Unsupported input! Provide either a string or byte-array that previously were serialized from objects in powershell" # 3 | 4 | 'ConvertTo-PSFClixml.Conversion.Error' = "Error converting input to Clixml" # 5 | 6 | 'Export-PSFClixml.Exporting' = "Writing data to '{0}'" # $resolvedPath 7 | 'Export-PSFClixml.Exporting.Failed' = "Failed to export object" # 8 | 9 | 'Import-PSFClixml.Path.Resolution' = "Failed to resolve path: {0}" # 10 | 'Import-PSFClixml.Path.NotFile' = "{0} is not a file" # $pathItem 11 | 'Import-PSFClixml.Processing' = "Processing {0}" # ($pathItem) 12 | 'Import-PSFClixml.Conversion.Failed' = "Failed to convert input object" # 13 | } -------------------------------------------------------------------------------- /PSFramework/functions/utility/Disable-PSFConsoleInterrupt.ps1: -------------------------------------------------------------------------------- 1 | function Disable-PSFConsoleInterrupt { 2 | <# 3 | .SYNOPSIS 4 | Prevents the use of CTRL+C from interrupting the console. 5 | 6 | .DESCRIPTION 7 | Prevents the use of CTRL+C from interrupting the console. 8 | 9 | Use this to prevent manual interruption of critical tasks, but do not forget to re-enable it as soon as possible. 10 | Usually, ctrl+C is a critical part of the user experience, enabling the user to interrupt the console 11 | and avoid a hang from locking the console. 12 | 13 | .EXAMPLE 14 | PS C:\> Disable-PSFConsoleInterrupt 15 | 16 | Prevents the use of CTRL+C from interrupting the console. 17 | #> 18 | [CmdletBinding()] 19 | param () 20 | 21 | [Console]::TreatControlCAsInput = $true 22 | } -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] 4 | FriedrichWeinmann 5 | patreon: # Replace with a single Patreon username 6 | open_collective: # Replace with a single Open Collective username 7 | ko_fi: # Replace with a single Ko-fi username 8 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 9 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 10 | liberapay: # Replace with a single Liberapay username 11 | issuehunt: # Replace with a single IssueHunt username 12 | otechie: # Replace with a single Otechie username 13 | custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] 14 | -------------------------------------------------------------------------------- /library/PSFramework/Parameter/ParameterContractType.cs: -------------------------------------------------------------------------------- 1 | namespace PSFramework.Parameter 2 | { 3 | /// 4 | /// Defines what kind of element is granted the contract 5 | /// 6 | public enum ParameterContractType 7 | { 8 | /// 9 | /// The contracted element is a field containing a value 10 | /// 11 | Field, 12 | 13 | /// 14 | /// The contracted element is a method, performing an action 15 | /// 16 | Method, 17 | 18 | /// 19 | /// The contracted element is an operator, facilitating type conversion. Generally into a dedicated object type this parameterclass abstracts. 20 | /// 21 | Operator 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /PSFramework/internal/configurations/path.ps1: -------------------------------------------------------------------------------- 1 | Set-PSFConfig -Module 'PSFramework' -Name 'Path.Temp' -Value $script:path_temp -Initialize -Validation 'string' -Description "Path pointing at the temp path. Used with Get-PSFPath." 2 | Set-PSFConfig -Module 'PSFramework' -Name 'Path.LocalAppData' -Value $script:path_LocalAppData -Initialize -Validation 'string' -Description "Path pointing at the LocalAppData path. Used with Get-PSFPath." 3 | Set-PSFConfig -Module 'PSFramework' -Name 'Path.AppData' -Value $script:path_AppData -Initialize -Validation 'string' -Description "Path pointing at the AppData path. Used with Get-PSFPath." 4 | Set-PSFConfig -Module 'PSFramework' -Name 'Path.ProgramData' -Value $script:path_ProgramData -Initialize -Validation 'string' -Description "Path pointing at the ProgramData path. Used with Get-PSFPath." -------------------------------------------------------------------------------- /PSFramework/tests/functions/runspace/Get-PSFRunspaceDispatcher.Tests.ps1: -------------------------------------------------------------------------------- 1 | Describe "Testing the command Get-PSFRunspaceWorkflow" -Tag "CI", "Pipeline", "Unit" { 2 | BeforeEach { 3 | & (Get-Module PSFramework) { $script:runspaceWorkflows = @{ } } 4 | $null = New-PSFRunspaceWorkflow -Name "Test1" 5 | $null = New-PSFRunspaceWorkflow -Name "Test2" 6 | $null = New-PSFRunspaceWorkflow -Name "Test3" 7 | } 8 | AfterAll { 9 | & (Get-Module PSFramework) { $script:runspaceWorkflows = @{ } } 10 | } 11 | 12 | It "Should return all registered Runspace Workflows" { 13 | Get-PSFRunspaceWorkflow | Should -HaveCount 3 14 | } 15 | It "Should return the specified Runspace Workflows" { 16 | Get-PSFRunspaceWorkflow -Name Test1 | Should -HaveCount 1 17 | (Get-PSFRunspaceWorkflow -Name Test1).Name | Should -Be 'Test1' 18 | } 19 | } -------------------------------------------------------------------------------- /PSFramework/snippets/help_par_EnableException.snippet: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | help_par_EnableException 5 | 6 | Help for the EnableException parameter 7 | Infernal Associates Ltd. 8 | 9 | Expansion 10 | 11 |
12 | 13 | 14 | 17 | 18 | 19 |
20 |
-------------------------------------------------------------------------------- /PSFramework/functions/temp/Get-PSFTempItem.ps1: -------------------------------------------------------------------------------- 1 | function Get-PSFTempItem { 2 | <# 3 | .SYNOPSIS 4 | List existing temporary items. 5 | 6 | .DESCRIPTION 7 | List existing temporary items. 8 | 9 | .PARAMETER Name 10 | Name of the item to filter by. 11 | Defaults to '*' 12 | 13 | .PARAMETER ModuleName 14 | Name of the module to filter by. 15 | Defaults to '*' 16 | 17 | .EXAMPLE 18 | PS C:\> Get-PSFTempItem 19 | 20 | List all existing temporary items. 21 | #> 22 | [CmdletBinding()] 23 | param ( 24 | [Parameter(ValueFromPipelineByPropertyName = $true, ValueFromPipeline = $true)] 25 | [string] 26 | $Name = '*', 27 | 28 | [Parameter(ValueFromPipelineByPropertyName = $true)] 29 | [string] 30 | $ModuleName = '*' 31 | ) 32 | 33 | process { 34 | ($script:tempItems.Get($ModuleName, $Name)) 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /PSFramework/internal/tepp/scripts/tepp.ps1: -------------------------------------------------------------------------------- 1 | Register-PSFTeppScriptblock -Name 'PSFramework-tepp-scriptblockname' -ScriptBlock { 2 | [PSFramework.TabExpansion.TabExpansionHost]::Scripts.Keys 3 | } -Global 4 | 5 | Register-PSFTeppScriptblock -Name 'PSFramework-tepp-parametername' -ScriptBlock { 6 | if ($fakeBoundParameter.Command) 7 | { 8 | $common = 'Verbose', 'Debug', 'ErrorAction', 'WarningAction', 'InformationAction', 'ErrorVariable', 'WarningVariable', 'InformationVariable', 'OutVariable', 'OutBuffer', 'PipelineVariable', 'WhatIf', 'Confirm' 9 | 10 | try 11 | { 12 | $command = Get-Command $fakeBoundParameter.Command 13 | if ($command -is [System.Management.Automation.AliasInfo]) { $command = $command.ResolvedCommand } 14 | $command.Parameters.Keys | Where-Object { $_ -notin $common } 15 | } 16 | catch { } 17 | } 18 | } -Global -------------------------------------------------------------------------------- /library/PSFramework/TaskEngine/TaskState.cs: -------------------------------------------------------------------------------- 1 | namespace PSFramework.TaskEngine 2 | { 3 | /// 4 | /// The state of the task or its previous execution 5 | /// 6 | public enum TaskState 7 | { 8 | /// 9 | /// Task is new, hasn't executed yet 10 | /// 11 | New, 12 | 13 | /// 14 | /// Task is currently running 15 | /// 16 | Running, 17 | 18 | /// 19 | /// Task has completed 20 | /// 21 | Completed, 22 | 23 | /// 24 | /// Task is pending another execution 25 | /// 26 | Pending, 27 | 28 | /// 29 | /// Task had an error 30 | /// 31 | Error 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /PSFramework/functions/message/Unregister-PSFMessageColorTransform.ps1: -------------------------------------------------------------------------------- 1 | function Unregister-PSFMessageColorTransform { 2 | <# 3 | .SYNOPSIS 4 | Removes a previously registered message color rule. 5 | 6 | .DESCRIPTION 7 | Removes a previously registered message color rule. 8 | 9 | .PARAMETER Name 10 | Name of the rule to remove. 11 | 12 | .EXAMPLE 13 | PS C:\> Get-PSFMessageColorTransform | Unregister-PSFMessageColorTransform 14 | 15 | Clears all message color rules.. 16 | #> 17 | [CmdletBinding()] 18 | param ( 19 | [parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] 20 | [string[]] 21 | $Name 22 | ) 23 | process { 24 | foreach ($conditionName in $Name) { 25 | $null = [PSFramework.Message.MessageHost]::ColorTransforms.TryRemove($conditionName, [ref]$null) 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /library/PSFramework/Logging/LogFileFileType.cs: -------------------------------------------------------------------------------- 1 | namespace PSFramework.Logging 2 | { 3 | /// 4 | /// The data format to log to in the logfile logging provider 5 | /// 6 | public enum LogFileFileType 7 | { 8 | /// 9 | /// Write as comma separated value 10 | /// 11 | Csv, 12 | 13 | /// 14 | /// Write as Html fragment 15 | /// 16 | Html, 17 | 18 | /// 19 | /// Write as Json fragment 20 | /// 21 | Json, 22 | 23 | /// 24 | /// Write as Xml fragment 25 | /// 26 | Xml, 27 | 28 | /// 29 | /// Write as CMTrace compatible entry 30 | /// 31 | CMTrace 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /library/PSFramework/Utility/DynamicContentObjectType.cs: -------------------------------------------------------------------------------- 1 | namespace PSFramework.Utility 2 | { 3 | /// 4 | /// The kind of dynamic content object was specified 5 | /// 6 | public enum DynamicContentObjectType 7 | { 8 | /// 9 | /// A regular object was requested 10 | /// 11 | Common, 12 | 13 | /// 14 | /// A queue was requested 15 | /// 16 | Queue, 17 | 18 | /// 19 | /// A list was requested 20 | /// 21 | List, 22 | 23 | /// 24 | /// A stack was requested 25 | /// 26 | Stack, 27 | 28 | /// 29 | /// A dictionary was requested 30 | /// 31 | Dictionary 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /PSFramework/en-us/stringsFlowControl.psd1: -------------------------------------------------------------------------------- 1 | @{ 2 | # Invoke-PSFProtectedCommand 3 | 'FlowControl.Invoke-PSFProtectedCommand.Confirmed' = 'Execution Confirmed: {0}' 4 | 'FlowControl.Invoke-PSFProtectedCommand.Denied' = 'Execution Denied: {0}' 5 | 'FlowControl.Invoke-PSFProtectedCommand.Failed' = 'Failed to: {0}' 6 | 'FlowControl.Invoke-PSFProtectedCommand.Retry' = 'Failed {0} / {1} attempts, trying again: {2}' 7 | 'FlowControl.Invoke-PSFProtectedCommand.Success' = 'Execution Successful: {0}' 8 | 'FlowControl.Invoke-PSFProtectedCommand.ErrorEvent' = 'Executing error event for "{0}" against {1}' 9 | 'FlowControl.Invoke-PSFProtectedCommand.ErrorEvent.Failed' = 'Error executing error event for "{0}" against {1}: {2}' 10 | 'FlowControl.Invoke-PSFProtectedCommand.ErrorEvent.Success' = 'Successfully executed error event for "{0}" against {1}' 11 | } -------------------------------------------------------------------------------- /PSFramework/functions/utility/Get-PSFPath.ps1: -------------------------------------------------------------------------------- 1 | function Get-PSFPath 2 | { 3 | <# 4 | .SYNOPSIS 5 | Access a configured path. 6 | 7 | .DESCRIPTION 8 | Access a configured path. 9 | Paths can be configured using Set-PSFPath or using the configuration system. 10 | To register a path using the configuration system create a setting key named like this: 11 | "PSFramework.Path." 12 | For example the following setting points at the temp path: 13 | "PSFramework.Path.Temp" 14 | 15 | .PARAMETER Name 16 | Name of the path to retrieve. 17 | 18 | .EXAMPLE 19 | PS C:\> Get-PSFPath -Name 'temp' 20 | 21 | Returns the temp path. 22 | #> 23 | [CmdletBinding()] 24 | Param ( 25 | [Parameter(Mandatory = $true, Position = 0)] 26 | [string] 27 | $Name 28 | ) 29 | 30 | process 31 | { 32 | Get-PSFConfigValue -FullName "PSFramework.Path.$Name" 33 | } 34 | } -------------------------------------------------------------------------------- /library/PSFramework/TabExpansion/CompletionResultComparer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Management.Automation; 4 | 5 | namespace PSFramework.TabExpansion 6 | { 7 | /// 8 | /// Compares two completion results 9 | /// 10 | public class CompletionResultComparer : IComparer 11 | { 12 | /// 13 | /// Compares two completion results 14 | /// 15 | /// Completer to compare 16 | /// Completer to compare 17 | /// -1, 0 or 1 18 | public int Compare(CompletionResult Completer1, CompletionResult Completer2) 19 | { 20 | return Completer1.CompletionText.CompareTo(Completer2.CompletionText); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /library/PSFramework/Message/TransformType.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace PSFramework.Message 8 | { 9 | /// 10 | /// The messaging system provides these kinds of transformations for input. 11 | /// 12 | public enum TransformType 13 | { 14 | /// 15 | /// A target transform can transform the target object specified. Used for live-state objects that should not be serialized on a second thread. 16 | /// 17 | Target = 1, 18 | 19 | /// 20 | /// An exception transform allows automatic transformation of exceptions. Primarily used to unwrap exceptions from an API that wraps all exceptions. 21 | /// 22 | Exception = 2, 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | on: 2 | push: 3 | branches: 4 | - master 5 | - main 6 | 7 | jobs: 8 | build: 9 | 10 | runs-on: windows-latest 11 | permissions: 12 | contents: write 13 | 14 | steps: 15 | - uses: actions/checkout@v1 16 | - name: Install Prerequisites 17 | run: .\build\psf-prerequisites.ps1 18 | shell: powershell 19 | - name: Compile Help 20 | run: .\build\vsts-help.ps1 21 | shell: powershell 22 | - name: Validate 23 | run: .\build\vsts-validate.ps1 24 | shell: powershell 25 | - name: Build 26 | run: .\build\vsts-build.ps1 -ApiKey $env:APIKEY 27 | shell: powershell 28 | env: 29 | APIKEY: ${{ secrets.ApiKey }} 30 | - name: Release 31 | run: .\build\vsts-release.ps1 32 | shell: powershell 33 | env: 34 | GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} -------------------------------------------------------------------------------- /PSFramework/functions/runspace/Get-PSFRunspaceWorkflow.ps1: -------------------------------------------------------------------------------- 1 | function Get-PSFRunspaceWorkflow { 2 | <# 3 | .SYNOPSIS 4 | Returns a list of registered runspace workflows. 5 | 6 | .DESCRIPTION 7 | Returns a list of registered runspace workflows. 8 | A Runspace workflow object is the main component managing a PSFramework Runspace Workflow 9 | 10 | .PARAMETER Name 11 | By which name to filter. 12 | Defaults to * 13 | 14 | .EXAMPLE 15 | PS C:\> Get-PSFRunspaceWorkflow 16 | 17 | Returns all registered runspace workflows. 18 | 19 | .LINK 20 | https://psframework.org/documentation/documents/psframework/runspace-workflows.html 21 | #> 22 | [CmdletBinding()] 23 | param ( 24 | [PsfArgumentCompleter('PSFramework-runspace-workflow-name')] 25 | [string] 26 | $Name = '*' 27 | ) 28 | process { 29 | ($script:runspaceWorkflows.Values | Where-Object Name -Like $Name) 30 | } 31 | } -------------------------------------------------------------------------------- /PSFramework/internal/configurations/runspace.ps1: -------------------------------------------------------------------------------- 1 | #region Setting the configuration 2 | Set-PSFConfig -Module PSFramework -Name 'Runspace.StopTimeoutSeconds' -Value 30 -Initialize -Validation "integerpositive" -Handler { [PSFramework.Runspace.RunspaceHost]::StopTimeoutSeconds = $args[0] } -Description "Time in seconds that Stop-PSFRunspace will wait for a scriptspace to selfterminate before killing it." 3 | Set-PSFConfig -Module PSFramework -Name 'Runspace.RunspaceBoundValue.CleanupInterval' -Value 900000 -Initialize -Validation "integerpositive" -Handler { [PSFramework.Runspace.RunspaceHost]::RbvCleanupInterval = $args[0] } -Description "Interval in milliseconds at which PSFramework will cleanup all Runspace-Bound Values, deleting values for runspaces that no longer exist. Reduce the interval to ensure lower memory peaks in situations of creating and closing runspaces frequently." 4 | #endregion Setting the configuration -------------------------------------------------------------------------------- /PSFramework/functions/runspace/Get-PSFRunspace.ps1: -------------------------------------------------------------------------------- 1 | function Get-PSFRunspace 2 | { 3 | <# 4 | .SYNOPSIS 5 | Returns registered runspaces. 6 | 7 | .DESCRIPTION 8 | Returns a list of runspaces that have been registered with the PSFramework 9 | 10 | .PARAMETER Name 11 | Default: "*" 12 | Only registered runspaces of similar names are returned. 13 | 14 | .EXAMPLE 15 | PS C:\> Get-PSFRunspace 16 | 17 | Returns all registered runspaces 18 | 19 | .EXAMPLE 20 | PS C:\> Get-PSFRunspace -Name 'mymodule.maintenance' 21 | 22 | Returns the runspace registered under the name 'mymodule.maintenance' 23 | #> 24 | [CmdletBinding(HelpUri = 'https://psframework.org/documentation/commands/PSFramework/Get-PSFRunspace')] 25 | Param ( 26 | [string] 27 | $Name = "*" 28 | ) 29 | 30 | process 31 | { 32 | [PSFramework.Runspace.RunspaceHost]::Runspaces.Values | Where-Object Name -Like $Name 33 | } 34 | } -------------------------------------------------------------------------------- /PSFramework/internal/scripts/loadConfigurationPersisted.ps1: -------------------------------------------------------------------------------- 1 | if (-not [PSFramework.Configuration.ConfigurationHost]::ImportFromRegistryDone) 2 | { 3 | # Read config from all settings 4 | $config_hash = Read-PsfConfigPersisted -Scope 511 5 | 6 | foreach ($value in $config_hash.Values) 7 | { 8 | try 9 | { 10 | if (-not $value.KeepPersisted) { Set-PSFConfig -FullName $value.FullName -Value $value.Value -EnableException } 11 | else { Set-PSFConfig -FullName $value.FullName -PersistedValue $value.Value -PersistedType $value.Type -EnableException } 12 | [PSFramework.Configuration.ConfigurationHost]::Configurations[$value.FullName].PolicySet = $value.Policy 13 | [PSFramework.Configuration.ConfigurationHost]::Configurations[$value.FullName].PolicyEnforced = $value.Enforced 14 | } 15 | catch { } 16 | } 17 | 18 | [PSFramework.Configuration.ConfigurationHost]::ImportFromRegistryDone = $true 19 | } 20 | -------------------------------------------------------------------------------- /library/PSFramework/ComputerManagement/ComputerManagementHost.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Concurrent; 3 | 4 | namespace PSFramework.ComputerManagement 5 | { 6 | /// 7 | /// Host class containing static iresources for the computer management component 8 | /// 9 | public static class ComputerManagementHost 10 | { 11 | /// 12 | /// The timespan a PSSession may be idle before it is cleared for cleanup 13 | /// 14 | public static TimeSpan PSSessionIdleTimeout = new TimeSpan(0, 15, 0); 15 | 16 | /// 17 | /// List of known session types that can be used in a SessionContainer. 18 | /// 19 | public static ConcurrentDictionary KnownSessionTypes = new ConcurrentDictionary(StringComparer.InvariantCultureIgnoreCase); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /PSFramework/functions/configuration/Register-PSFConfigSchema.ps1: -------------------------------------------------------------------------------- 1 | function Register-PSFConfigSchema 2 | { 3 | <# 4 | .SYNOPSIS 5 | Register new schemas for ingersting configuration data. 6 | 7 | .DESCRIPTION 8 | Register new schemas for ingersting configuration data. 9 | This can be used to dynamically extend the configuration system and add new file types as supported input. 10 | 11 | .PARAMETER Name 12 | The name of the Schema to register. 13 | 14 | .PARAMETER Schema 15 | The Schema Code to register. 16 | 17 | .EXAMPLE 18 | PS C:\> Register-PSFConfigSchema -Name Default -Schema $scriptblock 19 | 20 | Registers the scriptblock stored in $scriptblock under 'Default' 21 | #> 22 | [CmdletBinding()] 23 | Param ( 24 | [string] 25 | $Name, 26 | 27 | [ScriptBlock] 28 | $Schema 29 | ) 30 | 31 | process 32 | { 33 | [PSFramework.Configuration.ConfigurationHost]::Schemata[$Name] = $Schema 34 | } 35 | } -------------------------------------------------------------------------------- /PSFramework/internal/scripts/removalEvent.ps1: -------------------------------------------------------------------------------- 1 | #region Handle Module Removal 2 | $PSF_OnRemoveScript = { 3 | # Clear all temp items 4 | $script:tempItems.Clear() 5 | 6 | # Stop all managed runspaces ONLY on the main runspace's termination 7 | if ([runspace]::DefaultRunspace.Id -eq 1) 8 | { 9 | Wait-PSFMessage -Timeout 30s -Terminate 10 | Get-PSFRunspace | Stop-PSFRunspace 11 | [PSFramework.PSFCore.PSFCoreHost]::Uninitialize() 12 | } 13 | 14 | # Properly disconnect all remote sessions still held open 15 | $psframework_pssessions.Values | Remove-PSSession 16 | # Remove all Runspace-specific callbacks 17 | [PSFramework.FlowControl.CallbackHost]::RemoveRunspaceOwned() 18 | } 19 | $ExecutionContext.SessionState.Module.OnRemove += $PSF_OnRemoveScript 20 | $null = Register-EngineEvent -SourceIdentifier ([System.Management.Automation.PsEngineEvent]::Exiting) -Action $PSF_OnRemoveScript -SupportEvent 21 | #endregion Handle Module Removal -------------------------------------------------------------------------------- /PSFramework/functions/logging/Get-PSFLoggingError.ps1: -------------------------------------------------------------------------------- 1 | function Get-PSFLoggingError { 2 | <# 3 | .SYNOPSIS 4 | Retrieve errors that happened when trying to log messages. 5 | 6 | .DESCRIPTION 7 | Retrieve errors that happened when trying to log messages. 8 | This command is used to troubleshoot issues with the logging system itself. 9 | 10 | It can only return errors that happened during the current process. 11 | Only logging instances that are currently enabled are considered, does not work for Legacy Logging Providers. 12 | 13 | .EXAMPLE 14 | PS C:\> Get-PSFLoggingError 15 | 16 | Returns all errors any currently enabled logging providers had. 17 | #> 18 | [CmdletBinding()] 19 | param ( 20 | 21 | ) 22 | process { 23 | $errors = foreach ($instance in Get-PSFLoggingProviderInstance) { 24 | if (-not $instance.Enabled) { continue } 25 | $instance.GetError() 26 | } 27 | 28 | $errors | Sort-Object Timestamp 29 | } 30 | } -------------------------------------------------------------------------------- /PSFramework/internal/configurationvalidation/string.ps1: -------------------------------------------------------------------------------- 1 | Register-PSFConfigValidation -Name "string" -ScriptBlock { 2 | Param ( 3 | $Value 4 | ) 5 | 6 | $Result = [PSCustomObject]@{ 7 | Success = $True 8 | Value = $null 9 | Message = "" 10 | } 11 | 12 | try 13 | { 14 | # Seriously, this should work for almost anybody and anything 15 | [string]$data = $Value 16 | } 17 | catch 18 | { 19 | $Result.Message = "Not a string: $Value" 20 | $Result.Success = $False 21 | return $Result 22 | } 23 | 24 | if ([string]::IsNullOrEmpty($data)) 25 | { 26 | $Result.Message = "Is an empty string: $Value" 27 | $Result.Success = $False 28 | return $Result 29 | } 30 | 31 | if ($data -eq $Value.GetType().FullName) 32 | { 33 | $Result.Message = "Is an object with no proper string representation: $Value" 34 | $Result.Success = $False 35 | return $Result 36 | } 37 | 38 | $Result.Value = $data 39 | 40 | return $Result 41 | } -------------------------------------------------------------------------------- /PSFramework/tests/general/Help.Exceptions.ps1: -------------------------------------------------------------------------------- 1 | # List of functions that should be ignored 2 | $global:FunctionHelpTestExceptions = @( 3 | 'Get-PSFScriptblock' 4 | ) 5 | 6 | <# 7 | List of arrayed enumerations. These need to be treated differently. Add full name. 8 | Example: 9 | 10 | "Sqlcollaborative.Dbatools.Connection.ManagementConnectionType[]" 11 | #> 12 | $global:HelpTestEnumeratedArrays = @( 13 | 'PSFramework.License.ProductType[]' 14 | 'PSFramework.Message.MessageLevel[]' 15 | 'System.Management.Automation.PSLanguageMode[]' 16 | 'PSLanguageMode[]' 17 | ) 18 | 19 | <# 20 | Some types on parameters just fail their validation no matter what. 21 | For those it becomes possible to skip them, by adding them to this hashtable. 22 | Add by following this convention: = @() 23 | Example: 24 | 25 | "Get-DbaCmObject" = @("DoNotUse") 26 | #> 27 | $global:HelpTestSkipParameterType = @{ 28 | 29 | } 30 | -------------------------------------------------------------------------------- /PSFramework/internal/tepp/scripts/message.ps1: -------------------------------------------------------------------------------- 1 | Register-PSFTeppScriptblock -Name 'PSFramework.Message.Module' -ScriptBlock { 2 | Get-PSFMessage | Select-Object -ExpandProperty ModuleName | Select-Object -Unique 3 | } -Global 4 | 5 | Register-PSFTeppScriptblock -Name 'PSFramework.Message.Function' -ScriptBlock { 6 | Get-PSFMessage | Select-Object -ExpandProperty FunctionName | Select-Object -Unique 7 | } -Global 8 | 9 | Register-PSFTeppScriptblock -Name 'PSFramework.Message.Tags' -ScriptBlock { 10 | Get-PSFMessage | Select-Object -ExpandProperty Tags | Remove-PSFNull -Enumerate | Select-Object -Unique 11 | } -Global 12 | 13 | Register-PSFTeppScriptblock -Name 'PSFramework.Message.Runspace' -ScriptBlock { 14 | Get-PSFMessage | Select-Object -ExpandProperty Runspace | Select-Object -Unique 15 | } -Global 16 | 17 | Register-PSFTeppScriptblock -Name 'PSFramework.Message.Level' -ScriptBlock { 18 | Get-PSFMessage | Select-Object -ExpandProperty Level | Select-Object -Unique 19 | } -Global -------------------------------------------------------------------------------- /PSFramework/internal/tepp/scripts/filter.ps1: -------------------------------------------------------------------------------- 1 | Register-PSFTeppScriptblock -Name "PSFramework.Filter.Module" -ScriptBlock { 2 | (Get-PSFFilterCondition).Module | Select-Object -Unique 3 | } -Global 4 | 5 | Register-PSFTeppScriptblock -Name "PSFramework.Filter.SetModule" -ScriptBlock { 6 | (Get-PSFFilterConditionSet).Module | Select-Object -Unique 7 | } -Global 8 | 9 | Register-PSFTeppScriptblock -Name "PSFramework.Filter.Name" -ScriptBlock { 10 | $module = '*' 11 | if ($fakeBoundParameters.Module) { $module = $fakeBoundParameters.Module } 12 | (Get-PSFFilterCondition -Module $module).Name | Select-Object -Unique 13 | } -Global 14 | 15 | Register-PSFTeppScriptblock -Name "PSFramework.Filter.SetName" -ScriptBlock { 16 | $module = '*' 17 | if ($fakeBoundParameters.Module) { $module = $fakeBoundParameters.Module } 18 | if ($fakeBoundParameters.SetModule) { $module = $fakeBoundParameters.SetModule } 19 | (Get-PSFFilterConditionSet -Module $module).Name | Select-Object -Unique 20 | } -Global -------------------------------------------------------------------------------- /library/PSFramework/License/ProductType.cs: -------------------------------------------------------------------------------- 1 | namespace PSFramework.License 2 | { 3 | /// 4 | /// What kind of product is being licensed 5 | /// 6 | public enum ProductType 7 | { 8 | /// 9 | /// The product is a PowerShell module 10 | /// 11 | Module = 1, 12 | 13 | /// 14 | /// The Product is a Script of any kind 15 | /// 16 | Script = 2, 17 | 18 | /// 19 | /// The Product is a library, bringing functionality to the Shell 20 | /// 21 | Library = 3, 22 | 23 | /// 24 | /// The Product is a standalone application, that happens to utilize PowerShell 25 | /// 26 | Application = 4, 27 | 28 | /// 29 | /// The Product is anything other than the default types 30 | /// 31 | Other = 5, 32 | } 33 | } -------------------------------------------------------------------------------- /PSFramework/functions/runspace/Stop-PSFRunspaceWorker.ps1: -------------------------------------------------------------------------------- 1 | function Stop-PSFRunspaceWorker { 2 | <# 3 | .SYNOPSIS 4 | Stops a specific runspace worker, part of a Runspace Workflow. 5 | 6 | .DESCRIPTION 7 | Stops a specific runspace worker, part of a Runspace Workflow. 8 | This ends all associated runspaces, but does not affect any queue content. 9 | 10 | .PARAMETER InputObject 11 | The Worker object to stop. 12 | 13 | .EXAMPLE 14 | PS C:\> $worker | Stop-PSFRunspaceWorker 15 | 16 | Stops the worker object in $worker. 17 | 18 | .LINK 19 | https://psframework.org/documentation/documents/psframework/runspace-workflows.html 20 | #> 21 | [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseShouldProcessForStateChangingFunctions", "")] 22 | [CmdletBinding()] 23 | param ( 24 | [Parameter(ValueFromPipeline = $true)] 25 | [PSFramework.Runspace.RSWorker[]] 26 | $InputObject 27 | ) 28 | process { 29 | foreach ($item in $InputObject) { 30 | $item.Stop() 31 | } 32 | } 33 | } -------------------------------------------------------------------------------- /PSFramework/internal/configurationvalidation/secret.ps1: -------------------------------------------------------------------------------- 1 | Register-PSFConfigValidation -Name "secret" -ScriptBlock { 2 | param ( 3 | $Value 4 | ) 5 | 6 | $Result = [PSCustomObject]@{ 7 | Success = $True 8 | Value = $null 9 | Message = "" 10 | } 11 | 12 | if ($null -eq $Value) { 13 | $Result.Message = "Secrets cannot be empty!" 14 | $Result.Success = $False 15 | return $Result 16 | } 17 | 18 | if ($Value.GetType() -notin [string], [System.Security.SecureString], [System.Management.Automation.PSCredential]) { 19 | $Result.Message = "Secrets must be either a string, a securestring or a pscredential object!" 20 | $Result.Success = $False 21 | return $Result 22 | } 23 | 24 | if ($Value -is [string]) { 25 | $Value = $Value | ConvertTo-SecureString -AsPlainText -Force 26 | } 27 | if ($Value -is [System.Security.SecureString]) { 28 | $Value = New-Object System.Management.Automation.PSCredential('', $Value) 29 | } 30 | 31 | $Result.Value = $Value 32 | 33 | return $Result 34 | } -------------------------------------------------------------------------------- /PSFramework/internal/tepp/scripts/logging-provider.ps1: -------------------------------------------------------------------------------- 1 | Register-PSFTeppScriptblock -Name 'PSFramework-logging-provider' -ScriptBlock { 2 | (Get-PSFLoggingProvider).Name 3 | } -Global 4 | 5 | Register-PSFTeppScriptblock -Name 'PSFramework-logging-instance-provider' -ScriptBlock { 6 | (Get-PSFLoggingProviderInstance).Provider.Name | Select-Object -Unique 7 | } -Global 8 | 9 | Register-PSFTeppScriptblock -Name 'PSFramework-logging-instance-name' -ScriptBlock { 10 | if ($fakeBoundParameters.ProviderName) 11 | { 12 | return (Get-PSFLoggingProviderInstance -ProviderName $fakeBoundParameters.ProviderName).Name 13 | } 14 | (Get-PSFLoggingProviderInstance).Name | Select-Object -Unique 15 | } -Global 16 | 17 | Register-PSFTeppScriptblock -Name 'PSFramework-logging-instance-name2' -ScriptBlock { 18 | if ($fakeBoundParameters.Name) 19 | { 20 | return (Get-PSFLoggingProviderInstance -ProviderName $fakeBoundParameters.ProviderName).Name 21 | } 22 | (Get-PSFLoggingProviderInstance).Name | Select-Object -Unique 23 | } -Global -------------------------------------------------------------------------------- /PSFramework/internal/configurations/utility.ps1: -------------------------------------------------------------------------------- 1 | Set-PSFConfig -Module PSFramework -Name 'Utility.Size.Style' -Value ([PSFramework.Utility.SizeStyle]::Dynamic) -Initialize -Validation sizestyle -Handler { [PSFramework.Utility.UtilityHost]::SizeStyle = $args[0] } -Description "Controls how size objects are displayed by default. Generally, their string representation is calculated to be user friendly (dynamic), can be updated to 'plain' number or a specific size. Can be overriden on a per-object basis." 2 | Set-PSFConfig -Module PSFramework -Name 'Utility.Size.Digits' -Value 2 -Initialize -Validation integer0to9 -Handler { [PSFramework.Utility.UtilityHost]::SizeDigits = $args[0] } -Description "How many digits are used when displaying a size object." 3 | Set-PSFConfig -Module PSFramework -Name 'Utility.SupportPackage.TaskDumpLimit' -Value 10 -Initialize -Validation integerpositive -Description 'When using the automatic task handling of New-PSFSupportPackage, up to how many debug dumps per task should be retained? The latest X dumps will remain.' -------------------------------------------------------------------------------- /PSFramework/tests/general/FileIntegrity.Exceptions.ps1: -------------------------------------------------------------------------------- 1 | # List of forbidden commands 2 | $global:BannedCommands = @( 3 | 'Write-Host', 4 | 'Write-Verbose', 5 | 'Write-Warning', 6 | 'Write-Error', 7 | 'Write-Output', 8 | 'Write-Information', 9 | 'Write-Debug' 10 | ) 11 | 12 | <# 13 | Contains list of exceptions for banned cmdlets. 14 | Insert the file names of files that may contain them. 15 | 16 | Example: 17 | "Write-Host" = @('Write-PSFHostColor.ps1','Write-PSFMessage.ps1') 18 | #> 19 | $global:MayContainCommand = @{ 20 | "Write-Host" = @('Write-PSFHostColor.ps1') 21 | "Write-Verbose" = @() 22 | "Write-Warning" = @('assembly.ps1') 23 | "Write-Error" = @('Import-PSFJson.ps1', 'Import-PSFPowerShellDataFile.ps1', 'Invoke-PSFCommand.ps1', 'Set-PSFFileContent.ps1', 'Stop-PSFFunction.ps1') 24 | "Write-Output" = @('filesystem.provider.ps1', 'gelf.provider.ps1', 'Import-PSFPowerShellDataFile.ps1', 'logfile.provider.ps1', 'input.ps1', 'teppCoreCode.ps1') 25 | "Write-Information" = @() 26 | "Write-Debug" = @() 27 | } -------------------------------------------------------------------------------- /PSFramework/tests/readme.md: -------------------------------------------------------------------------------- 1 | # Description 2 | 3 | This is the folder, where all the tests go. 4 | 5 | Those are subdivided in two categories: 6 | 7 | - General 8 | - Function 9 | 10 | ## General Tests 11 | 12 | General tests are function generic and test for general policies. 13 | 14 | These test scan answer questions such as: 15 | 16 | - Is my module following my style guides? 17 | - Does any of my scripts have a syntax error? 18 | - Do my scripts use commands I do not want them to use? 19 | - Do my commands follow best practices? 20 | - Do my commands have proper help? 21 | 22 | Basically, these allow a general module health check. 23 | 24 | These tests are already provided as part of the template. 25 | 26 | ## Function Tests 27 | 28 | A healthy module should provide unit and integration tests for the commands & components it ships. 29 | Only then can be guaranteed, that they will actually perform as promised. 30 | 31 | However, as each such test must be specific to the function it tests, there cannot be much in the way of templates. -------------------------------------------------------------------------------- /library/PSFramework/License/LicenseType.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace PSFramework.License 4 | { 5 | /// 6 | /// What kind of License is this? By default, a license is a free license allowing modification but requiring attribution. 7 | /// 8 | [Flags] 9 | public enum LicenseType 10 | { 11 | /// 12 | /// No special type is present 13 | /// 14 | Free = 1, 15 | 16 | /// 17 | /// The license is for a commercial product. This means you have to acquire use permission, such as software licenses, user CALs et al. 18 | /// 19 | Commercial = 2, 20 | 21 | /// 22 | /// Reusing this product requires no attribution. Just use it and call it your own. 23 | /// 24 | NoAttribution = 4, 25 | 26 | /// 27 | /// This product may be used, but must not be modified in any way. 28 | /// 29 | NoModify = 8, 30 | } 31 | } -------------------------------------------------------------------------------- /library/PSFramework/Message/LogEntryType.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace PSFramework.Message 4 | { 5 | /// 6 | /// The kind of information the logged entry was. 7 | /// 8 | [Flags] 9 | public enum LogEntryType 10 | { 11 | /// 12 | /// This entry wasn't written to any stream 13 | /// 14 | None = 0, 15 | 16 | /// 17 | /// A message that was written to the current host equivalent, if available also to the information stream 18 | /// 19 | Information = 1, 20 | 21 | /// 22 | /// A message that was written to the verbose stream 23 | /// 24 | Verbose = 2, 25 | 26 | /// 27 | /// A message that was written to the Debug stream 28 | /// 29 | Debug = 4, 30 | 31 | /// 32 | /// A message written to the warning stream 33 | /// 34 | Warning = 8 35 | } 36 | } -------------------------------------------------------------------------------- /PSFramework/functions/taskengine/Get-PSFTaskEngineTask.ps1: -------------------------------------------------------------------------------- 1 | function Get-PSFTaskEngineTask 2 | { 3 | <# 4 | .SYNOPSIS 5 | Returns tasks registered for the task engine 6 | 7 | .DESCRIPTION 8 | Returns tasks registered for the task engine 9 | 10 | .PARAMETER Name 11 | Default: "*" 12 | Only tasks with similar names are returned. 13 | 14 | .EXAMPLE 15 | PS C:\> Get-PSFTaskEngineTask 16 | 17 | Returns all tasks registered to the task engine 18 | 19 | .EXAMPLE 20 | PS C:\> Get-PSFTaskEngineTask -Name 'mymodule.*' 21 | 22 | Returns all tasks registered to the task engine whose name starts with 'mymodule.' 23 | (It stands to reason that only tasks belonging to the module 'mymodule' would be returned that way) 24 | #> 25 | [CmdletBinding(HelpUri = 'https://psframework.org/documentation/commands/PSFramework/Get-PSFTaskEngineTask')] 26 | Param ( 27 | [string] 28 | $Name = "*" 29 | ) 30 | 31 | process 32 | { 33 | [PSFramework.TaskEngine.TaskHost]::Tasks.Values | Where-Object Name -Like $Name 34 | } 35 | } -------------------------------------------------------------------------------- /library/PSFramework/FlowControl/CallbackException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace PSFramework.FlowControl 8 | { 9 | /// 10 | /// A custom exception, including the callback that failed 11 | /// 12 | public class CallbackException : Exception 13 | { 14 | /// 15 | /// The callback that failed 16 | /// 17 | public Callback Callback; 18 | 19 | /// 20 | /// Creates a new callback exception, including the Callback that failed 21 | /// 22 | /// The callback that failed 23 | /// The exception it failed with 24 | public CallbackException(Callback Callback, Exception InnerException) 25 | : base(InnerException.Message, InnerException) 26 | { 27 | this.Callback = Callback; 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /PSFramework/tests/general/strings.Tests.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .DESCRIPTION 3 | This test verifies, that all strings that have been used, 4 | are listed in the language files and thus have a message being displayed. 5 | 6 | It also checks, whether the language files have orphaned entries that need cleaning up. 7 | #> 8 | 9 | 10 | 11 | Describe "Testing localization strings" { 12 | $moduleRoot = (Get-Module PSFramework).ModuleBase 13 | $stringsResults = Export-PSMDString -ModuleRoot $moduleRoot 14 | $exceptions = & "$global:testroot\general\strings.Exceptions.ps1" 15 | 16 | foreach ($stringEntry in $stringsResults) { 17 | if ($stringEntry.String -eq "key") { continue } # Skipping the template default entry 18 | It "Should be used & have text: $($stringEntry.String)" -TestCases @{ stringEntry = $stringEntry; exceptions = $exceptions } { 19 | if ($exceptions.LegalSurplus -notcontains $stringEntry.String) { 20 | $stringEntry.Surplus | Should -BeFalse 21 | } 22 | $stringEntry.Text | Should -Not -BeNullOrEmpty 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /library/PSFramework/Logging/LoggingState.cs: -------------------------------------------------------------------------------- 1 | namespace PSFramework.Logging 2 | { 3 | /// 4 | /// Used to signal the current processing state of the logging runspace 5 | /// 6 | public enum LoggingState 7 | { 8 | /// 9 | /// The initial state before the logging runspace is spun up 10 | /// 11 | Unstarted, 12 | 13 | /// 14 | /// Spinning up logging providers 15 | /// 16 | Initializing, 17 | 18 | /// 19 | /// Ready to process messages 20 | /// 21 | Ready, 22 | 23 | /// 24 | /// Currently busy writing messages 25 | /// 26 | Writing, 27 | 28 | /// 29 | /// A critical error in the logging runspaces has occured, logging has terminated 30 | /// 31 | Broken, 32 | 33 | /// 34 | /// The logging has been fully stopped 35 | /// 36 | Stopped 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /library/PSFramework/Utility/ThrottleBase.cs: -------------------------------------------------------------------------------- 1 | using PSFramework.Parameter; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace PSFramework.Utility 9 | { 10 | /// 11 | /// Base implementation of a throttling handler 12 | /// 13 | public abstract class ThrottleBase 14 | { 15 | /// 16 | /// This should only return when the next execution can happen 17 | /// 18 | /// Maximum time to wait. Throw an exception if expires before next slot becomes available 19 | public abstract void GetSlot(TimeSpanParameter Timeout = null); 20 | 21 | /// 22 | /// Any cleanup action to take without resetting the throttle. 23 | /// 24 | public abstract void Purge(); 25 | 26 | /// 27 | /// Reset the full throttling condition to base. 28 | /// 29 | public abstract void Reset(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /library/PSFramework/TabExpansion/TeppScriptMode.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace PSFramework.TabExpansion 8 | { 9 | /// 10 | /// Whether the user wants to use simple tepp, full tepp or auto-detect 11 | /// 12 | public enum TeppScriptMode 13 | { 14 | /// 15 | /// Simple mode. The scriptblock provided by the user is expected to provide a list of strings. All the rest is processed by the system 16 | /// 17 | Simple = 1, 18 | 19 | /// 20 | /// In full mode, the user is expected to provide the full TEPP scriptblock. 21 | /// 22 | Full = 2, 23 | 24 | /// 25 | /// In Auto-Detect mode, the system detects, whether the user intended to provide a simple mode or full mode script. This is determined by whether the scriptblock contains a parameter block or not. 26 | /// 27 | Auto = 4 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /PSFramework/functions/taskengine/Test-PSFTaskEngineTask.ps1: -------------------------------------------------------------------------------- 1 | function Test-PSFTaskEngineTask 2 | { 3 | <# 4 | .SYNOPSIS 5 | Tests, whether the specified task has already been executed. 6 | 7 | .DESCRIPTION 8 | Tests, whether the specified task has already been executed. 9 | Returns false, if the task doesn't exist. 10 | 11 | .PARAMETER Name 12 | Name of the task to test 13 | 14 | .EXAMPLE 15 | PS C:\> Test-PSFTaskEngineTask -Name 'mymodule.maintenance' 16 | 17 | Returns, whether the task named 'mymodule.maintenance' has already been executed at least once. 18 | #> 19 | [OutputType([System.Boolean])] 20 | [CmdletBinding(HelpUri = 'https://psframework.org/documentation/commands/PSFramework/Test-PSFTaskEngineTask')] 21 | Param ( 22 | [Parameter(Mandatory = $true)] 23 | [string] 24 | $Name 25 | ) 26 | 27 | process 28 | { 29 | if (-not ([PSFramework.TaskEngine.TaskHost]::Tasks.ContainsKey($Name))) 30 | { 31 | return $false 32 | } 33 | 34 | $task = [PSFramework.TaskEngine.TaskHost]::Tasks[$Name] 35 | $task.LastExecution -gt $task.Registered 36 | } 37 | } -------------------------------------------------------------------------------- /PSFramework/functions/runspace/Start-PSFRunspaceWorker.ps1: -------------------------------------------------------------------------------- 1 | function Start-PSFRunspaceWorker { 2 | <# 3 | .SYNOPSIS 4 | Start a runspace worker, part of the logic executing a Runspace Workflow. 5 | 6 | .DESCRIPTION 7 | Start a runspace worker, part of the logic executing a Runspace Workflow. 8 | This will have it start its workers and process any queued input. 9 | 10 | Use this to start only part of a Runspace Workflow, rather than all of it. 11 | 12 | .PARAMETER InputObject 13 | The Worker object to start. 14 | 15 | .EXAMPLE 16 | PS C:\> $worker | Start-PSFRunspaceWorker 17 | 18 | Starts the worker specified in $worker 19 | 20 | .LINK 21 | https://psframework.org/documentation/documents/psframework/runspace-workflows.html 22 | #> 23 | [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseShouldProcessForStateChangingFunctions", "")] 24 | [CmdletBinding()] 25 | param ( 26 | [Parameter(ValueFromPipeline = $true)] 27 | [PSFramework.Runspace.RSWorker[]] 28 | $InputObject 29 | ) 30 | process { 31 | foreach ($item in $InputObject) { 32 | $item.Start() 33 | } 34 | } 35 | } -------------------------------------------------------------------------------- /library/PSFramework/Parameter/ParameterClasses.cs: -------------------------------------------------------------------------------- 1 | namespace PSFramework.Parameter 2 | { 3 | /// 4 | /// List of available parameter classes 5 | /// 6 | public enum ParameterClasses 7 | { 8 | /// 9 | /// The computer parameter class allows easily targeting a computer 10 | /// 11 | Computer, 12 | 13 | /// 14 | /// The datetime parameter class allows for an easy way to specify a datetime 15 | /// 16 | DateTime, 17 | 18 | /// 19 | /// The timespan parameter class allows for an easy way to specify a timespan 20 | /// 21 | TimeSpan, 22 | 23 | /// 24 | /// The encoding parameter class allows to consistently accept encodings as input. 25 | /// 26 | Encoding, 27 | 28 | /// 29 | /// The set of path parameter classes allow to resolve file system path designations into absolute paths 30 | /// 31 | Path, 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /PSFramework/functions/message/Get-PSFMessageLevelModifier.ps1: -------------------------------------------------------------------------------- 1 | function Get-PSFMessageLevelModifier 2 | { 3 | <# 4 | .SYNOPSIS 5 | Returns all registered message level modifiers with similar name. 6 | 7 | .DESCRIPTION 8 | Returns all registered message level modifiers with similar name. 9 | 10 | Message level modifiers are created using New-PSFMessageLevelModifier and allow dynamically modifying the actual message level written by commands. 11 | 12 | .PARAMETER Name 13 | Default: "*" 14 | A name filter - only commands that are similar to the filter will be returned. 15 | 16 | .EXAMPLE 17 | PS C:\> Get-PSFMessageLevelModifier 18 | 19 | Returns all message level filters 20 | 21 | .EXAMPLE 22 | PS C:\> Get-PSFmessageLevelModifier -Name "mymodule.*" 23 | 24 | Returns all message level filters that start with "mymodule." 25 | #> 26 | [CmdletBinding(HelpUri = 'https://psframework.org/documentation/commands/PSFramework/Get-PSFMessageLevelModifier')] 27 | Param ( 28 | [string] 29 | $Name = "*" 30 | ) 31 | 32 | ([PSFramework.Message.MessageHost]::MessageLevelModifiers.Values) | Where-Object Name -Like $Name 33 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Friedrich Weinmann 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /library/PSFramework/Data/Converters/BoolConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Management.Automation; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace PSFramework.Data.Converters 9 | { 10 | /// 11 | /// Converts data structures into PSD1 Strings 12 | /// 13 | public class BoolConverter : IPsd1Converter 14 | { 15 | /// 16 | /// Converts to psd1 string 17 | /// 18 | /// The object to convert 19 | /// The indentation level 20 | /// The conversion runtime object, including its settings. 21 | /// The parent objects. Used in complex data types to prevent infinite recursion. 22 | /// The converted PSD1 representation of the value provided 23 | public string Convert(object Value, object[] Parents, int Depth, Psd1Converter Converter) 24 | { 25 | return $"${Value}"; 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /library/PSFramework/Data/Converters/DBNullConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Management.Automation; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace PSFramework.Data.Converters 9 | { 10 | /// 11 | /// Converts data structures into PSD1 Strings 12 | /// 13 | public class DBNullConverter : IPsd1Converter 14 | { 15 | /// 16 | /// Converts to psd1 string 17 | /// 18 | /// The object to convert 19 | /// The indentation level 20 | /// The conversion runtime object, including its settings. 21 | /// The parent objects. Used in complex data types to prevent infinite recursion. 22 | /// The converted PSD1 representation of the value provided 23 | public string Convert(object Value, object[] Parents, int Depth, Psd1Converter Converter) 24 | { 25 | return "$null"; 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /library/PSFramework/Data/Converters/IntConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Management.Automation; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace PSFramework.Data.Converters 9 | { 10 | /// 11 | /// Converts data structures into PSD1 Strings 12 | /// 13 | public class IntConverter : IPsd1Converter 14 | { 15 | /// 16 | /// Converts to psd1 string 17 | /// 18 | /// The object to convert 19 | /// The indentation level 20 | /// The conversion runtime object, including its settings. 21 | /// The parent objects. Used in complex data types to prevent infinite recursion. 22 | /// The converted PSD1 representation of the value provided 23 | public string Convert(object Value, object[] Parents, int Depth, Psd1Converter Converter) 24 | { 25 | return $"{Value}"; 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /library/PSFramework/Data/Converters/DoubleConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Management.Automation; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace PSFramework.Data.Converters 9 | { 10 | /// 11 | /// Converts data structures into PSD1 Strings 12 | /// 13 | public class DoubleConverter : IPsd1Converter 14 | { 15 | /// 16 | /// Converts to psd1 string 17 | /// 18 | /// The object to convert 19 | /// The indentation level 20 | /// The conversion runtime object, including its settings. 21 | /// The parent objects. Used in complex data types to prevent infinite recursion. 22 | /// The converted PSD1 representation of the value provided 23 | public string Convert(object Value, object[] Parents, int Depth, Psd1Converter Converter) 24 | { 25 | return $"{Value}"; 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /library/PSFramework/Data/Converters/VersionConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Management.Automation; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace PSFramework.Data.Converters 9 | { 10 | /// 11 | /// Converts data structures into PSD1 Strings 12 | /// 13 | public class VersionConverter : IPsd1Converter 14 | { 15 | /// 16 | /// Converts to psd1 string 17 | /// 18 | /// The object to convert 19 | /// The indentation level 20 | /// The conversion runtime object, including its settings. 21 | /// The parent objects. Used in complex data types to prevent infinite recursion. 22 | /// The converted PSD1 representation of the value provided 23 | public string Convert(object Value, object[] Parents, int Depth, Psd1Converter Converter) 24 | { 25 | return $"'{Value}'"; 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /library/PSFramework/Data/Converters/GuidConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Management.Automation; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace PSFramework.Data.Converters 9 | { 10 | /// 11 | /// Converts data structures into PSD1 Strings 12 | /// 13 | public class GuidConverter : IPsd1Converter 14 | { 15 | /// 16 | /// Converts to psd1 string 17 | /// 18 | /// The object to convert 19 | /// The indentation level 20 | /// The conversion runtime object, including its settings. 21 | /// The parent objects. Used in complex data types to prevent infinite recursion. 22 | /// The converted PSD1 representation of the value provided 23 | public string Convert(object Value, object[] Parents, int Depth, Psd1Converter Converter) 24 | { 25 | return $"'{Value.ToString()}'"; 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /library/PSFramework/Data/Converters/TimeSpanConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Management.Automation; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace PSFramework.Data.Converters 9 | { 10 | /// 11 | /// Converts data structures into PSD1 Strings 12 | /// 13 | public class TimeSpanConverter : IPsd1Converter 14 | { 15 | /// 16 | /// Converts to psd1 string 17 | /// 18 | /// The object to convert 19 | /// The indentation level 20 | /// The conversion runtime object, including its settings. 21 | /// The parent objects. Used in complex data types to prevent infinite recursion. 22 | /// The converted PSD1 representation of the value provided 23 | public string Convert(object Value, object[] Parents, int Depth, Psd1Converter Converter) 24 | { 25 | return String.Format("'{0:c}'", Value); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /library/PSFramework/Data/IPsd1Converter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Management.Automation; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace PSFramework.Data 9 | { 10 | /// 11 | /// Ruleset for types implementing PSD1 Conversion 12 | /// 13 | public interface IPsd1Converter 14 | { 15 | /// 16 | /// Convert an object to the string to insert into a psd1 document. 17 | /// 18 | /// The value to convert 19 | /// The parent objects. Used in complex data types to prevent infinite recursion. 20 | /// The current indentation depth. Can be ignored for plain value returns, if you do not need to return multiple lines. 21 | /// The conversion runtime object, including its settings. 22 | /// The converted PSD1 representation of the value provided 23 | string Convert(object Value, object[] Parents, int Depth, Psd1Converter Converter); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /library/PSFramework/Data/Converters/PSDriveInfoConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Management.Automation; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace PSFramework.Data.Converters 9 | { 10 | /// 11 | /// Converts data structures into PSD1 Strings 12 | /// 13 | public class PSDriveInfoConverter : IPsd1Converter 14 | { 15 | /// 16 | /// Converts to psd1 string 17 | /// 18 | /// The object to convert 19 | /// The indentation level 20 | /// The conversion runtime object, including its settings. 21 | /// The parent objects. Used in complex data types to prevent infinite recursion. 22 | /// The converted PSD1 representation of the value provided 23 | public string Convert(object Value, object[] Parents, int Depth, Psd1Converter Converter) 24 | { 25 | return $"'{((PSDriveInfo)Value).Name}'"; 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /library/PSFramework/Data/Converters/SwitchConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Management.Automation; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace PSFramework.Data.Converters 9 | { 10 | /// 11 | /// Converts data structures into PSD1 Strings 12 | /// 13 | public class SwitchConverter : IPsd1Converter 14 | { 15 | /// 16 | /// Converts to psd1 string 17 | /// 18 | /// The object to convert 19 | /// The indentation level 20 | /// The conversion runtime object, including its settings. 21 | /// The parent objects. Used in complex data types to prevent infinite recursion. 22 | /// The converted PSD1 representation of the value provided 23 | public string Convert(object Value, object[] Parents, int Depth, Psd1Converter Converter) 24 | { 25 | return $"${((SwitchParameter)Value).ToBool()}"; 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /library/PSFramework/Runspace/RSState.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace PSFramework.Runspace 8 | { 9 | /// 10 | /// The state of a worker 11 | /// 12 | public enum RSState 13 | { 14 | /// 15 | /// The worker has yet to be configured to run 16 | /// 17 | Pending = 1, 18 | 19 | /// 20 | /// The worker is currently starting up 21 | /// 22 | Starting = 2, 23 | 24 | /// 25 | /// The worker is busy doing its job 26 | /// 27 | Running = 3, 28 | 29 | /// 30 | /// The worker is in the process of shutting down 31 | /// 32 | Stopping = 4, 33 | 34 | /// 35 | /// The worker has completed its shutdown 36 | /// 37 | Stopped = 5, 38 | 39 | /// 40 | /// The worker failed otherwise. Check the errors. 41 | /// 42 | Failed = 6 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /PSFramework/functions/resultcache/Clear-PSFresultCache.ps1: -------------------------------------------------------------------------------- 1 | function Clear-PSFResultCache 2 | { 3 | <# 4 | .SYNOPSIS 5 | Clears the result cache 6 | 7 | .DESCRIPTION 8 | Clears the result cache, which can come in handy if you have a huge amount of data stored within and want to free the memory. 9 | 10 | .PARAMETER Confirm 11 | If this switch is enabled, you will be prompted for confirmation before executing any operations that change state. 12 | 13 | .PARAMETER WhatIf 14 | If this switch is enabled, no actions are performed but informational messages will be displayed that explain what would happen if the command were to run. 15 | 16 | .EXAMPLE 17 | PS C:\> Clear-PSFResultCache 18 | 19 | Clears the result cache, freeing up any used memory. 20 | #> 21 | [CmdletBinding(ConfirmImpact = 'Low', SupportsShouldProcess = $true, HelpUri = 'https://psframework.org/documentation/commands/PSFramework/Clear-PSFresultCache')] 22 | param ( 23 | 24 | ) 25 | 26 | process 27 | { 28 | if (Test-PSFShouldProcess -Target 'Result Cache' -ActionString 'Clear-PSFResultCache.Clear' -PSCmdlet $PSCmdlet) 29 | { 30 | [PSFramework.ResultCache.ResultCache]::Clear() 31 | } 32 | } 33 | } -------------------------------------------------------------------------------- /PSFramework/internal/tepp/scripts/Unregister-PSFConfig.ps1: -------------------------------------------------------------------------------- 1 | Register-PSFTeppScriptblock -Name "PSFramework-Unregister-PSFConfig-FullName" -ScriptBlock { 2 | switch ("$($fakeBoundParameter.Scope)") 3 | { 4 | "UserDefault" { $path = "HKCU:\SOFTWARE\Microsoft\WindowsPowerShell\PSFramework\Config\Default" } 5 | "UserMandatory" { $path = "HKCU:\SOFTWARE\Microsoft\WindowsPowerShell\PSFramework\Config\Enforced" } 6 | "SystemDefault" { $path = "HKLM:\SOFTWARE\Microsoft\WindowsPowerShell\PSFramework\Config\Default" } 7 | "SystemMandatory" { $path = "HKLM:\SOFTWARE\Microsoft\WindowsPowerShell\PSFramework\Config\Enforced" } 8 | default { $path = "HKCU:\SOFTWARE\Microsoft\WindowsPowerShell\PSFramework\Config\Default" } 9 | } 10 | 11 | if (Test-Path $path) 12 | { 13 | $properties = Get-ItemProperty -Path $path 14 | $common = 'PSPath', 'PSParentPath', 'PSChildName', 'PSDrive', 'PSProvider' 15 | $properties.PSObject.Properties.Name | Where-Object { $_ -notin $common } 16 | } 17 | } -Global 18 | 19 | Register-PSFTeppScriptblock -Name "PSFramework-Unregister-PSFConfig-Module" -ScriptBlock { 20 | [PSFramework.Configuration.ConfigurationHost]::Configurations.Values.Module | Select-Object -Unique 21 | } -Global -------------------------------------------------------------------------------- /library/PSFramework/Data/Converters/PSProviderInfoConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Management.Automation; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace PSFramework.Data.Converters 9 | { 10 | /// 11 | /// Converts data structures into PSD1 Strings 12 | /// 13 | public class PSProviderInfoConverter : IPsd1Converter 14 | { 15 | /// 16 | /// Converts to psd1 string 17 | /// 18 | /// The object to convert 19 | /// The indentation level 20 | /// The conversion runtime object, including its settings. 21 | /// The parent objects. Used in complex data types to prevent infinite recursion. 22 | /// The converted PSD1 representation of the value provided 23 | public string Convert(object Value, object[] Parents, int Depth, Psd1Converter Converter) 24 | { 25 | return $"'{((ProviderInfo)Value).Name}'"; 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /library/PSFramework/Data/Converters/DateTimeConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Management.Automation; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace PSFramework.Data.Converters 9 | { 10 | /// 11 | /// Converts data structures into PSD1 Strings 12 | /// 13 | public class DateTimeConverter : IPsd1Converter 14 | { 15 | /// 16 | /// Converts to psd1 string 17 | /// 18 | /// The object to convert 19 | /// The indentation level 20 | /// The conversion runtime object, including its settings. 21 | /// The parent objects. Used in complex data types to prevent infinite recursion. 22 | /// The converted PSD1 representation of the value provided 23 | public string Convert(object Value, object[] Parents, int Depth, Psd1Converter Converter) 24 | { 25 | return String.Format("'{0:yyyy-MM-dd HH:mm:ss.fffff zzz}'", Value); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /library/PSFramework/Data/Converters/AssemblyConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Management.Automation; 5 | using System.Reflection; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | 9 | namespace PSFramework.Data.Converters 10 | { 11 | /// 12 | /// Converts data structures into PSD1 Strings 13 | /// 14 | public class AssemblyConverter : IPsd1Converter 15 | { 16 | /// 17 | /// Converts to psd1 string 18 | /// 19 | /// The object to convert 20 | /// The indentation level 21 | /// The conversion runtime object, including its settings. 22 | /// The parent objects. Used in complex data types to prevent infinite recursion. 23 | /// The converted PSD1 representation of the value provided 24 | public string Convert(object Value, object[] Parents, int Depth, Psd1Converter Converter) 25 | { 26 | return $"'{((Assembly)Value).FullName}'"; 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /library/PSFramework/Data/Converters/TypeInfoConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Management.Automation; 5 | using System.Reflection; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | 9 | namespace PSFramework.Data.Converters 10 | { 11 | /// 12 | /// Converts data structures into PSD1 Strings 13 | /// 14 | public class TypeInfoConverter : IPsd1Converter 15 | { 16 | /// 17 | /// Converts to psd1 string 18 | /// 19 | /// The object to convert 20 | /// The indentation level 21 | /// The conversion runtime object, including its settings. 22 | /// The parent objects. Used in complex data types to prevent infinite recursion. 23 | /// The converted PSD1 representation of the value provided 24 | public string Convert(object Value, object[] Parents, int Depth, Psd1Converter Converter) 25 | { 26 | return $"'{((TypeInfo)Value).FullName}'"; 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /library/PSFramework/Data/Converters/TextConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Management.Automation; 5 | using System.Management.Automation.Language; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | 9 | namespace PSFramework.Data.Converters 10 | { 11 | /// 12 | /// Converts data structures into PSD1 Strings 13 | /// 14 | public class TextConverter : IPsd1Converter 15 | { 16 | /// 17 | /// Converts to psd1 string 18 | /// 19 | /// The object to convert 20 | /// The indentation level 21 | /// The conversion runtime object, including its settings. 22 | /// The parent objects. Used in complex data types to prevent infinite recursion. 23 | /// The converted PSD1 representation of the value provided 24 | public string Convert(object Value, object[] Parents, int Depth, Psd1Converter Converter) 25 | { 26 | return $"'{Converter.EscapeQuotes(Value)}'"; 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /PSFramework/functions/ComputerManagement/Register-PSFSessionObjectType.ps1: -------------------------------------------------------------------------------- 1 | function Register-PSFSessionObjectType 2 | { 3 | <# 4 | .SYNOPSIS 5 | Registers a new type as a live session object. 6 | 7 | .DESCRIPTION 8 | Registers a new type as a live session object. 9 | This is used in the session container object, used to pass through multiple types of connection objects to a single PSFComputer parameterclassed parameter. 10 | 11 | .PARAMETER DisplayName 12 | The display name for the type. 13 | Pick anything that intuitively points at what the object is. 14 | 15 | .PARAMETER TypeName 16 | The full name of the type. 17 | 18 | .EXAMPLE 19 | PS C:\> Register-PSFSessionObjectType -DisplayName 'PSSession' -TypeName 'System.Management.Automation.Runspaces.PSSession' 20 | 21 | Registers the type 'System.Management.Automation.Runspaces.PSSession' under the name of 'PSSession'. 22 | #> 23 | [CmdletBinding()] 24 | param ( 25 | [Parameter(Mandatory = $true)] 26 | [string] 27 | $DisplayName, 28 | 29 | [Parameter(Mandatory = $true)] 30 | [string] 31 | $TypeName 32 | ) 33 | 34 | process 35 | { 36 | [PSFramework.ComputerManagement.ComputerManagementHost]::KnownSessionTypes[$TypeName] = $DisplayName 37 | } 38 | } -------------------------------------------------------------------------------- /library/PSFramework/Filter/ConditionWrapper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace PSFramework.Filter 8 | { 9 | internal class ConditionWrapper 10 | { 11 | internal string Name; 12 | internal string Module; 13 | Dictionary Conditions = new Dictionary(); 14 | 15 | internal ConditionWrapper(Condition Condition) 16 | { 17 | Name = Condition.Name; 18 | Module = Condition.Module; 19 | Conditions[Condition.Version] = Condition; 20 | } 21 | 22 | internal Condition Get() 23 | { 24 | return Conditions[Conditions.Keys.OrderByDescending(o => o).First()]; 25 | } 26 | internal Condition Get(Version Version) 27 | { 28 | return Conditions[Version]; 29 | } 30 | internal List List() 31 | { 32 | return new List(Conditions.Values); 33 | } 34 | internal void Add(Condition Condition) 35 | { 36 | Conditions[Condition.Version] = Condition; 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /library/PSFramework/Parameter/ComputerParameterInputType.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace PSFramework.Parameter 8 | { 9 | /// 10 | /// The kind of object that was bound to the parameter class 11 | /// 12 | public enum ComputerParameterInputType 13 | { 14 | /// 15 | /// The input object is just any non-special kind of input. 16 | /// 17 | Default = 0, 18 | 19 | /// 20 | /// The input object is a PowerShell Session object 21 | /// 22 | PSSession = 1, 23 | 24 | /// 25 | /// The input object is a live SMO Server object 26 | /// 27 | SMOServer = 2, 28 | 29 | /// 30 | /// The input object is a live cim session object 31 | /// 32 | CimSession = 3, 33 | 34 | /// 35 | /// The input object is a session container object, potentially containing live session objects of various types at the same time. 36 | /// 37 | Container = 4, 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /PSFramework/tests/functions/configuration/Get-PSFConfig.Tests.ps1: -------------------------------------------------------------------------------- 1 | Describe "Get-PSFConfig Unit Tests" -Tag "CI", "Config", "Unit" { 2 | BeforeAll { 3 | Get-PSFConfig -Module PSFTests -Force | ForEach-Object { 4 | $null = [PSFramework.Configuration.ConfigurationHost]::Configurations.Remove($_.FullName) 5 | } 6 | } 7 | AfterAll { 8 | Get-PSFConfig -Module PSFTests -Force | ForEach-Object { 9 | $null = [PSFramework.Configuration.ConfigurationHost]::Configurations.Remove($_.FullName) 10 | } 11 | } 12 | 13 | # Catch any signature changes to force revisiting the command 14 | It "Should have the designed for parameters & sets" { 15 | (Get-Command Get-PSFConfig).ParameterSets.Name | Should -Be 'FullName', 'Module' 16 | Get-Command Get-PSFConfig | Should -HaveParameters 'FullName', 'Name', 'Module', 'Persisted', 'Force' 17 | } 18 | 19 | It "Should find the correct Configuration item" { 20 | $config = New-Object PSFramework.Configuration.Config 21 | $config.Module = "psftests" 22 | $config.Name = "get-psfconfig.test1" 23 | [PSFramework.Configuration.ConfigurationHost]::Configurations[$config.FullName] = $config 24 | (Get-PSFConfig -FullName 'PSFTests.Get-PSFConfig.Test1').GetHashCode() | Should -Be ($config.GetHashCode()) 25 | } 26 | } -------------------------------------------------------------------------------- /PSFramework/tests/functions/runspace/end-to-end.Tests.ps1: -------------------------------------------------------------------------------- 1 | Describe "Testing the End-To-End Workflows" -Tag "CI", "Pipeline", "Inegration" { 2 | BeforeEach { 3 | & (Get-Module PSFramework) { $script:runspaceWorkflows = @{ } } 4 | } 5 | AfterEach { 6 | Get-PSFRunspaceWorkflow | Remove-PSFRunspaceWorkflow 7 | & (Get-Module PSFramework) { $script:runspaceWorkflows = @{ } } 8 | } 9 | 10 | It "Should pass through input to output" { 11 | $workflow = New-PSFRunspaceWorkflow -Name "Test" 12 | $workflow | Add-PSFRunspaceWorker -Name Node1 -InQueue Q1 -OutQueue Q2 -Count 1 -ScriptBlock { 13 | param ($Value) 14 | $Value 15 | } 16 | $workflow | Add-PSFRunspaceWorker -Name Node2 -InQueue Q2 -OutQueue Q3 -Count 1 -ScriptBlock { 17 | $_ 18 | } 19 | $workflow | Add-PSFRunspaceWorker -Name Node3 -InQueue Q3 -OutQueue Q4 -Count 1 -ScriptBlock { 20 | param ($Value) 21 | $Value 22 | } 23 | 1..10 | ForEach-Object { Write-PSFRunspaceQueue -Name Q1 -Value $_ -InputObject $workflow } 24 | $workflow | Start-PSFRunspaceWorkflow 25 | Start-Sleep -Seconds 1 26 | 27 | $results = Read-PSFRunspaceQueue -InputObject $workflow -Name Q4 -All 28 | 29 | $results.Count | Should -Be 10 30 | ($results | Measure-Object -Sum).Sum | Should -Be 55 31 | } 32 | } -------------------------------------------------------------------------------- /library/PSFramework/TaskEngine/Priority.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace PSFramework.TaskEngine 8 | { 9 | /// 10 | /// How high the priority of the task. Higher priority tasks take precedence over low priority tasks. 11 | /// 12 | public enum Priority 13 | { 14 | /// 15 | /// This task is completely trivial and can be done whenever there is some spare time for it 16 | /// 17 | Trivial = 1, 18 | 19 | /// 20 | /// The task is not very significant, but should be dealt with at some point 21 | /// 22 | Low = 2, 23 | 24 | /// 25 | /// Average priority task 26 | /// 27 | Medium = 4, 28 | 29 | /// 30 | /// An important task that will take precedence over most other tasks 31 | /// 32 | High = 8, 33 | 34 | /// 35 | /// A task so critical, that it should be considered to move it to synchronous execution instead. 36 | /// 37 | Critical = 16 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /PSFramework/functions/logging/Get-PSFLoggingProvider.ps1: -------------------------------------------------------------------------------- 1 | function Get-PSFLoggingProvider 2 | { 3 | <# 4 | .SYNOPSIS 5 | Returns a list of the registered logging providers. 6 | 7 | .DESCRIPTION 8 | Returns a list of the registered logging providers. 9 | Those are used to log messages to whatever system they are designed to log to. 10 | 11 | PSFramework ships with a few default logging providers. 12 | Custom logging destinations can be created by implementing your own, custom provider and registering it using Register-PSFLoggingProvider. 13 | 14 | .PARAMETER Name 15 | Default: '*' 16 | The name to filter by 17 | 18 | .EXAMPLE 19 | PS C:\> Get-PSFLoggingProvider 20 | 21 | Returns all logging provider 22 | 23 | .EXAMPLE 24 | PS C:\> Get-PSFLoggingProvider -Name filesystem 25 | 26 | Returns the filesystem provider 27 | #> 28 | [CmdletBinding(HelpUri = 'https://psframework.org/documentation/commands/PSFramework/Get-PSFLoggingProvider')] 29 | [OutputType([PSFramework.Logging.Provider])] 30 | Param ( 31 | [Alias('Provider', 'ProviderName')] 32 | [string] 33 | $Name = "*" 34 | ) 35 | 36 | process 37 | { 38 | [PSFramework.Logging.ProviderHost]::Providers.Values | Where-Object Name -Like $Name | Sort-Object ProviderVersion, Name 39 | } 40 | } -------------------------------------------------------------------------------- /PSFramework/internal/configurations/tabexpansion.ps1: -------------------------------------------------------------------------------- 1 | # Settings around the Tab Expansion Experience 2 | Set-PSFConfig -Module PSFramework -Name 'TabExpansion.FuzzyMatch' -Value $false -Initialize -Handler { [PSFramework.TabExpansion.TabExpansionHost]::FuzzyMatch = $args[0] } -Validation 'bool' -Description 'Whether to match tab completions with Fuzzy-Matching by default.' 3 | Set-PSFConfig -Module PSFramework -Name 'TabExpansion.AlwaysQuote' -Value $false -Initialize -Handler { [PSFramework.TabExpansion.TabExpansionHost]::AlwaysQuote = $args[0] } -Validation 'bool' -Description 'Wrap all completion results into quotes, whitespace or not.' 4 | Set-PSFConfig -Module PSFramework -Name 'TabExpansion.MatchAnywhere' -Value $false -Initialize -Handler { [PSFramework.TabExpansion.TabExpansionHost]::MatchAnywhere = $args[0] } -Validation 'bool' -Description 'Whether to match tab completions with Fuzzy-Matching by default.' 5 | Set-PSFConfig -Module PSFramework -Name 'TabExpansion.MaxResults' -Value 0 -Initialize -Handler { [PSFramework.TabExpansion.TabExpansionHost]::MaxResults = $args[0] } -Validation integerpositive -Description 'The maximum number of results show for tab expansion. This is the global setting for ALL completions, specific setting defined via Register-PSFTeppScriptblock take precedence.' -------------------------------------------------------------------------------- /PSFramework/functions/utility/Register-PSFSupportDataProvider.ps1: -------------------------------------------------------------------------------- 1 | function Register-PSFSupportDataProvider { 2 | <# 3 | .SYNOPSIS 4 | Registers additional data collection logic for the PSFramework Support Package. 5 | 6 | .DESCRIPTION 7 | Registers additional data collection logic for the PSFramework Support Package. 8 | This allows your module to include its own debugging information for the support package. 9 | 10 | This logic is used in the New-PSFSupportPackage command. 11 | 12 | .PARAMETER Name 13 | Name of the support data provider. 14 | 15 | .PARAMETER ScriptBlock 16 | Code that generates support data. 17 | Should provide information helpful with troubleshooting your code. 18 | 19 | .EXAMPLE 20 | PS C:\> Register-PSFSupportDataProvider -Name MyModule.MyData -ScriptBlock $code 21 | 22 | Registers the code in $code as a data provider for the support package. 23 | In case of somebody running the "New-PSFSupportPackage" this code will be executed and its results included in the file. 24 | #> 25 | [CmdletBinding()] 26 | param ( 27 | [Parameter(Mandatory = $true)] 28 | [string] 29 | $Name, 30 | 31 | [Parameter(Mandatory = $true)] 32 | [scriptblock] 33 | $ScriptBlock 34 | ) 35 | process { 36 | $script:supportDataProviders[$Name] = $ScriptBlock 37 | } 38 | } -------------------------------------------------------------------------------- /PSFramework/tests/functions/runspace/New-PSFRunspaceDispatcher.Tests.ps1: -------------------------------------------------------------------------------- 1 | Describe "Testing the command New-PSFRunspaceWorkflow" -Tag "CI", "Pipeline", "Unit" { 2 | BeforeEach { 3 | & (Get-Module PSFramework) { $script:runspaceWorkflows = @{ } } 4 | } 5 | AfterAll { 6 | & (Get-Module PSFramework) { $script:runspaceWorkflows = @{ } } 7 | } 8 | 9 | It "Should create a new Runspace Workflow without error" { 10 | { New-PSFRunspaceWorkflow -Name "Test" } | Should -Not -Throw 11 | } 12 | It "Should return a workflow object with the correct name and no workers" { 13 | $workflow = New-PSFRunspaceWorkflow -Name "Test" 14 | $workflow | Should -Not -BeNullOrEmpty 15 | $workflow.Name | Should -Be 'Test' 16 | $workflow.Workers.Count | Should -Be 0 17 | } 18 | It "Should refuse creating a workflow that already exists" { 19 | $null = New-PSFRunspaceWorkflow -Name "Test" 20 | { New-PSFRunspaceWorkflow -Name "Test" } | Should -Throw 21 | } 22 | It "Should overwrite a workflow that already exists when using Force" { 23 | $workflow = New-PSFRunspaceWorkflow -Name "Test" 24 | $workflow.Queues.Test.Enqueue(42) 25 | { New-PSFRunspaceWorkflow -Name "Test" -Force } | Should -Not -Throw 26 | $newWorkflow = Get-PSFRunspaceWorkflow -Name Test 27 | $newWorkflow.Queues.Test.Count | Should -Be 0 28 | } 29 | } -------------------------------------------------------------------------------- /PSFramework/internal/parameters/ComputerParameter.ps1: -------------------------------------------------------------------------------- 1 | 2 | $mappings = @{ 3 | "deserialized.microsoft.activedirectory.management.addomaincontroller" = @("HostName", "Name") 4 | "microsoft.activedirectory.management.addomaincontroller" = @("HostName", "Name") 5 | "microsoft.sqlserver.management.smo.server" = @("NetName", "DomainInstanceName") 6 | "deserialized.microsoft.sqlserver.management.smo.server" = @("NetName", "DomainInstanceName") 7 | "microsoft.sqlserver.management.smo.linkedserver" = @("Name") 8 | "deserialized.microsoft.sqlserver.management.smo.linkedserver" = @("Name") 9 | "microsoft.activedirectory.management.adcomputer" = @("DNSHostName", "Name") 10 | "deserialized.microsoft.activedirectory.management.adcomputer" = @("DNSHostName", "Name") 11 | "Microsoft.DnsClient.Commands.DnsRecord_A" = @("Name", "IPAddress") 12 | "Deserialized.Microsoft.DnsClient.Commands.DnsRecord_A" = @("Name", "IPAddress") 13 | "Microsoft.DnsClient.Commands.DnsRecord_AAAA" = @("Name", "IPAddress") 14 | "Deserialized.Microsoft.DnsClient.Commands.DnsRecord_AAAA" = @("Name", "IPAddress") 15 | } 16 | 17 | 18 | foreach ($key in $mappings.Keys) 19 | { 20 | Register-PSFParameterClassMapping -ParameterClass 'Computer' -TypeName $key -Properties $mappings[$key] 21 | } -------------------------------------------------------------------------------- /library/PSFramework/Filter/ConditionSetWrapper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace PSFramework.Filter 8 | { 9 | internal class ConditionSetWrapper 10 | { 11 | internal string Name; 12 | internal string Module; 13 | Dictionary ConditionSets = new Dictionary(); 14 | 15 | internal ConditionSetWrapper(ConditionSet ConditionSet) 16 | { 17 | Name = ConditionSet.Name; 18 | Module = ConditionSet.Module; 19 | ConditionSets[ConditionSet.Version] = ConditionSet; 20 | } 21 | 22 | internal ConditionSet Get() 23 | { 24 | return ConditionSets[ConditionSets.Keys.OrderByDescending(o => o).First()]; 25 | } 26 | internal ConditionSet Get(Version Version) 27 | { 28 | return ConditionSets[Version]; 29 | } 30 | internal List List() 31 | { 32 | return new List(ConditionSets.Values); 33 | } 34 | 35 | internal void Add(ConditionSet ConditionSet) 36 | { 37 | ConditionSets[ConditionSet.Version] = ConditionSet; 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /PSFramework/functions/feature/Test-PSFFeature.ps1: -------------------------------------------------------------------------------- 1 | function Test-PSFFeature 2 | { 3 | <# 4 | .SYNOPSIS 5 | Tests whether a given feature has been enabled. 6 | 7 | .DESCRIPTION 8 | Tests whether a given feature has been enabled. 9 | Use this within the feature-owning module to determine, whether a feature should be enabled or not. 10 | 11 | .PARAMETER Name 12 | The feature to test for. 13 | 14 | .PARAMETER ModuleName 15 | The name of the module that seeks to use the feature. 16 | Must be specified in order to determine module-specific flags. 17 | 18 | .EXAMPLE 19 | PS C:\> Test-PSFFeature -Name PSFramework.InheritEnableException -ModuleName SPReplicator 20 | 21 | Tests whether the module SPReplicator has enabled the Enable Exception Inheritance feature. 22 | #> 23 | [OutputType([bool])] 24 | [CmdletBinding()] 25 | param ( 26 | #[PsfValidateSet(TabCompletion = 'PSFramework.Feature.Name')] 27 | [parameter(Mandatory = $true)] 28 | [string] 29 | $Name, 30 | 31 | [string] 32 | $ModuleName 33 | ) 34 | 35 | begin 36 | { 37 | $featureItem = Get-PSFFeature -Name $Name 38 | } 39 | process 40 | { 41 | if (-not $featureItem.Global) { [PSFramework.Feature.FeatureHost]::ReadModuleFlag($Name, $ModuleName) } 42 | else { [PSFramework.Feature.FeatureHost]::ReadFlag($Name, $ModuleName) } 43 | } 44 | } -------------------------------------------------------------------------------- /PSFramework/tests/general/PSScriptAnalyzer.Tests.ps1: -------------------------------------------------------------------------------- 1 | [CmdletBinding()] 2 | Param ( 3 | [switch] 4 | $SkipTest, 5 | 6 | [string[]] 7 | $CommandPath = @("$global:testroot\..\functions", "$global:testroot\..\internal\functions") 8 | ) 9 | 10 | if ($SkipTest) { return } 11 | 12 | $global:__pester_data.ScriptAnalyzer = New-Object System.Collections.ArrayList 13 | 14 | Describe 'Invoking PSScriptAnalyzer against commandbase' { 15 | $commandFiles = foreach ($path in $CommandPath) { Get-ChildItem -Path $path -Recurse | Where-Object Name -like "*.ps1" } 16 | $scriptAnalyzerRules = Get-ScriptAnalyzerRule 17 | 18 | foreach ($file in $commandFiles) 19 | { 20 | Context "Analyzing $($file.BaseName)" { 21 | $analysis = Invoke-ScriptAnalyzer -Path $file.FullName -ExcludeRule PSAvoidTrailingWhitespace, PSShouldProcess 22 | 23 | forEach ($rule in $scriptAnalyzerRules) 24 | { 25 | It "Should pass $rule" -TestCases @{ analysis = $analysis; rule = $rule } { 26 | If ($analysis.RuleName -contains $rule) 27 | { 28 | $analysis | Where-Object RuleName -EQ $rule -outvariable failures | ForEach-Object { $null = $global:__pester_data.ScriptAnalyzer.Add($_) } 29 | 30 | 1 | Should -Be 0 31 | } 32 | else 33 | { 34 | 0 | Should -Be 0 35 | } 36 | } 37 | } 38 | } 39 | } 40 | } -------------------------------------------------------------------------------- /PSFramework/tests/extensions/BeTrueFOrAll.ps1: -------------------------------------------------------------------------------- 1 | function BeTrueForAll 2 | { 3 | [CmdletBinding()] 4 | param ( 5 | $ActualValue, 6 | 7 | [scriptblock] 8 | $TestScript, 9 | 10 | [switch] 11 | $Negate 12 | ) 13 | end 14 | { 15 | foreach ($value in $ActualValue) 16 | { 17 | $variables = [System.Collections.Generic.List[psvariable]]( 18 | [psvariable]::new('_', $value)) 19 | 20 | $succeeded = $TestScript.InvokeWithContext( 21 | <# functionsToDefine: #> @{ }, 22 | <# variablesToDefine: #> $variables, 23 | <# args: #> $value) 24 | 25 | if ($Negate.IsPresent) 26 | { 27 | $succeeded = -not $succeeded 28 | } 29 | 30 | if (-not $succeeded) 31 | { 32 | break 33 | } 34 | } 35 | 36 | if ($Negate.IsPresent) 37 | { 38 | $failureMessage = 39 | 'Expected: All values to fail the evaluation script, ' + 40 | 'but value "{0}" returned true.' -f $value 41 | } 42 | else 43 | { 44 | $failureMessage = 45 | 'Expected: All values to pass the evaluation script, ' + 46 | 'but value "{0}" returned false.' -f $value 47 | } 48 | 49 | [PSCustomObject]@{ 50 | Succeeded = $succeeded 51 | FailureMessage = $failureMessage 52 | } 53 | } 54 | } 55 | Add-ShouldOperator -Name BeTrueForAll -Test $function:BeTrueForAll -Alias All -SupportsArrayInput -------------------------------------------------------------------------------- /library/PSFramework.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.31409.214 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PSFramework", "PSFramework\PSFramework.csproj", "{D07E0143-2198-4CF2-AF90-BF008A8EC685}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | PS4|Any CPU = PS4|Any CPU 12 | Release|Any CPU = Release|Any CPU 13 | EndGlobalSection 14 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 15 | {D07E0143-2198-4CF2-AF90-BF008A8EC685}.Debug|Any CPU.ActiveCfg = Release|Any CPU 16 | {D07E0143-2198-4CF2-AF90-BF008A8EC685}.Debug|Any CPU.Build.0 = Release|Any CPU 17 | {D07E0143-2198-4CF2-AF90-BF008A8EC685}.PS4|Any CPU.ActiveCfg = PS4|Any CPU 18 | {D07E0143-2198-4CF2-AF90-BF008A8EC685}.PS4|Any CPU.Build.0 = PS4|Any CPU 19 | {D07E0143-2198-4CF2-AF90-BF008A8EC685}.Release|Any CPU.ActiveCfg = Release|Any CPU 20 | {D07E0143-2198-4CF2-AF90-BF008A8EC685}.Release|Any CPU.Build.0 = Release|Any CPU 21 | EndGlobalSection 22 | GlobalSection(SolutionProperties) = preSolution 23 | HideSolutionNode = FALSE 24 | EndGlobalSection 25 | GlobalSection(ExtensibilityGlobals) = postSolution 26 | SolutionGuid = {647DEEEB-FCCF-48FE-8D5A-7C7C33220FE6} 27 | EndGlobalSection 28 | EndGlobal 29 | -------------------------------------------------------------------------------- /PSFramework/internal/loggingProviders/console.provider.ps1: -------------------------------------------------------------------------------- 1 | $message_event = { 2 | param ( 3 | $Message 4 | ) 5 | $style = Get-ConfigValue -Name Style 6 | $string = $style.Replace('%Time%',$Message.Timestamp.ToString('HH:mm:ss.fff')).Replace('%Date%',$Message.Timestamp.ToString('yyyy-MM-dd')).Replace('%Level%', $Message.Level).Replace('%Module%', $Message.ModuleName).Replace('%FunctionName%', $Message.FunctionName).Replace('%Line%', $Message.Line).Replace('%File%', $Message.File).Replace('%Tags%', ($Message.Tags -join ",")).Replace('%Message%', $Message.LogMessage) 7 | [System.Console]::WriteLine($string) 8 | } 9 | 10 | $configuration_Settings = { 11 | Set-PSFConfig -Module 'PSFramework' -Name 'Logging.Console.Style' -Value '%Message%' -Initialize -Validation string -Description 'The style in which the message is printed. Supports several placeholders: %Message%, %Time%, %Date%, %Tags%, %Level%, %Module%, %FunctionName%, %Line%, %File%. Supports newline and tabs.' 12 | } 13 | $paramRegisterPSFLoggingProvider = @{ 14 | Name = "console" 15 | Version2 = $true 16 | ConfigurationRoot = 'PSFramework.Logging.Console' 17 | InstanceProperties = 'Style' 18 | MessageEvent = $message_Event 19 | ConfigurationSettings = $configuration_Settings 20 | ConfigurationDefaultValues = @{ 21 | Style = '%Message%' 22 | } 23 | } 24 | 25 | # Register the Console logging provider 26 | Register-PSFLoggingProvider @paramRegisterPSFLoggingProvider -------------------------------------------------------------------------------- /library/PSFramework/ResultCache/ResultCache.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace PSFramework.ResultCache 4 | { 5 | /// 6 | /// The class containing all things related to the result cache functionality. 7 | /// 8 | public static class ResultCache 9 | { 10 | /// 11 | /// The actually cached result 12 | /// 13 | public static object Result 14 | { 15 | get { return _Result; } 16 | set 17 | { 18 | _Result = value; 19 | _Timestamp = DateTime.Now; 20 | } 21 | } 22 | private static object _Result; 23 | 24 | /// 25 | /// The function that wrote the cache. 26 | /// 27 | public static string Function; 28 | 29 | /// 30 | /// Returns, when the cache was last set 31 | /// 32 | public static DateTime Timestamp 33 | { 34 | get 35 | { 36 | return _Timestamp; 37 | } 38 | } 39 | private static DateTime _Timestamp; 40 | 41 | /// 42 | /// Clears all cache properties to null 43 | /// 44 | public static void Clear() 45 | { 46 | _Result = null; 47 | Function = null; 48 | _Timestamp = new DateTime(0); 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /PSFramework/functions/runspace/Get-PSFDynamicContentObject.ps1: -------------------------------------------------------------------------------- 1 | function Get-PSFDynamicContentObject 2 | { 3 | <# 4 | .SYNOPSIS 5 | Retrieves a named value object that can be updated from another runspace. 6 | 7 | .DESCRIPTION 8 | Retrieves a named value object that can be updated from another runspace. 9 | 10 | This comes in handy to have a variable that is automatically updated. 11 | Use this function to receive an object under a given name. 12 | Use Set-PSFDynamicContentObject to update the value of the object. 13 | 14 | It matters not from what runspace you update the object. 15 | 16 | Note: 17 | When planning to use such an object, keep in mind that it can easily change its content at any given time. 18 | 19 | .PARAMETER Name 20 | The name of the object to retrieve. 21 | Will create an empty value object if the object doesn't already exist. 22 | 23 | .EXAMPLE 24 | PS C:\> Get-PSFDynamicContentObject -Name "Test" 25 | 26 | Returns the Dynamic Content Object named "test" 27 | #> 28 | [OutputType([PSFramework.Utility.DynamicContentObject])] 29 | [CmdletBinding(HelpUri = 'https://psframework.org/documentation/commands/PSFramework/Get-PSFDynamicContentObject')] 30 | Param ( 31 | [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] 32 | [string[]] 33 | $Name 34 | ) 35 | 36 | process 37 | { 38 | foreach ($item in $Name) 39 | { 40 | [PSFramework.Utility.DynamicContentObject]::Get($item) 41 | } 42 | } 43 | } -------------------------------------------------------------------------------- /PSFramework/tests/functions/message/New-PSFMessageLevelModifier.Tests.ps1: -------------------------------------------------------------------------------- 1 | Describe "New-PSFMessageLevelModifier Unit Tests" -Tag "CI", "Pipeline", "Unit" { 2 | BeforeAll { 3 | [PSFramework.Message.MessageHost]::MessageLevelModifiers.Clear() 4 | } 5 | AfterAll { 6 | [PSFramework.Message.MessageHost]::MessageLevelModifiers.Clear() 7 | } 8 | It "Should create a new message level modifier without error and as defined" { 9 | { New-PSFMessageLevelModifier -Name Test -Modifier -3 -IncludeFunctionName Get-Test -IncludeModuleName TestModule -IncludeTags Foo, Bar -EnableException } | Should -Not -Throw 10 | { Write-PSFMessage -Message Test } | Should -Not -Throw 11 | 12 | $modifier = Get-PSFMessageLevelModifier 13 | $modifier.Name | Should -Be 'Test' 14 | $modifier.Modifier | Should -Be -3 15 | $modifier.IncludeFunctionName | Should -Be 'Get-Test' 16 | $modifier.IncludeModuleName | Should -Be TestModule 17 | $modifier.IncludeTags.Count | Should -Be 2 18 | $modifier.IncludeTags | Should -Contain Foo 19 | $modifier.IncludeTags | Should -Contain Bar 20 | } 21 | 22 | It "Should apply filters correctly" { 23 | $modifier = Get-PSFMessageLevelModifier 24 | $modifier.AppliesTo("Get-Test","TestModule", @('Foo', 'Test')) | Should -BeTrue 25 | $modifier.AppliesTo("Get-Test","TestModule", @('Test')) | Should -BeFalse 26 | $modifier.AppliesTo("Get-Test","TestModule", @('Bar', 'Test')) | Should -BeTrue 27 | $modifier.AppliesTo("Get-Test2","TestModule", @('Foo', 'Test')) | Should -BeFalse 28 | } 29 | } -------------------------------------------------------------------------------- /PSFramework/functions/runspace/Remove-PSFRunspaceWorkflow.ps1: -------------------------------------------------------------------------------- 1 | function Remove-PSFRunspaceWorkflow { 2 | <# 3 | .SYNOPSIS 4 | Removes a Runspace Workflow, stopping all processing. 5 | 6 | .DESCRIPTION 7 | Removes a Runspace Workflow, stopping all processing. 8 | This stops all workers, ends all runspaces and unlists the workflow object. 9 | 10 | The queues remain untouched, but will be garbage collected together with the workflow object, 11 | assuming no variable outside of the module retains it. 12 | 13 | .PARAMETER Name 14 | The name of the Runspace Workflow to remove. 15 | 16 | .EXAMPLE 17 | PS C:\> Get-PSFRunspaceWorkflow | Remove-PSFRunspaceWorkflow 18 | 19 | Stops and removes all runspace workflows. 20 | 21 | .LINK 22 | https://psframework.org/documentation/documents/psframework/runspace-workflows.html 23 | 24 | .LINK 25 | Get-PSFRunspaceWorkflow 26 | 27 | .LINK 28 | New-PSFRunspaceWorkflow 29 | #> 30 | [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseShouldProcessForStateChangingFunctions", "")] 31 | [CmdletBinding()] 32 | param ( 33 | [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] 34 | [PsfArgumentCompleter('PSFramework-runspace-workflow-name')] 35 | [string[]] 36 | $Name 37 | ) 38 | process { 39 | foreach ($entry in $Name) { 40 | if (-not $script:runspaceWorkflows[$entry]) { continue } 41 | $script:runspaceWorkflows[$entry].Stop() 42 | $script:runspaceWorkflows.Remove($entry) 43 | } 44 | } 45 | } -------------------------------------------------------------------------------- /PSFramework/functions/taskengine/Test-PSFTaskEngineCache.ps1: -------------------------------------------------------------------------------- 1 | function Test-PSFTaskEngineCache 2 | { 3 | <# 4 | .SYNOPSIS 5 | Tests, whether the specified task engine cache-entry has been written. 6 | 7 | .DESCRIPTION 8 | Tests, whether the specified task engine cache-entry has been written. 9 | 10 | .PARAMETER Module 11 | The name of the module that generated the task. 12 | Use scriptname in case of using this within a script. 13 | Note: Must be the same as the name used within the task when calling 'Set-PSFTaskEngineCache' 14 | 15 | .PARAMETER Name 16 | The name of the task for which the cache is. 17 | Note: Must be the same as the name used within the task when calling 'Set-PSFTaskEngineCache' 18 | 19 | .EXAMPLE 20 | PS C:\> Test-PSFTaskEngineCache -Module 'mymodule' -Name 'maintenancetask' 21 | 22 | Returns, whether the cache has been set for the module 'mymodule' and the task 'maintenancetask' 23 | Does not require the cache to actually contain a value, but must exist. 24 | #> 25 | [OutputType([System.Boolean])] 26 | [CmdletBinding(HelpUri = 'https://psframework.org/documentation/commands/PSFramework/Test-PSFTaskEngineCache')] 27 | Param ( 28 | [Parameter(Mandatory = $true)] 29 | [ValidateNotNullOrEmpty()] 30 | [string] 31 | $Module, 32 | 33 | [Parameter(Mandatory = $true)] 34 | [ValidateNotNullOrEmpty()] 35 | [string] 36 | $Name 37 | ) 38 | 39 | process 40 | { 41 | [PSFramework.TaskEngine.TaskHost]::TestCacheItem($Module, $Name) 42 | } 43 | } -------------------------------------------------------------------------------- /PSFramework/functions/runspace/Stop-PSFRunspaceWorkflow.ps1: -------------------------------------------------------------------------------- 1 | function Stop-PSFRunspaceWorkflow { 2 | <# 3 | .SYNOPSIS 4 | Stop a running Runspace Workflow. 5 | 6 | .DESCRIPTION 7 | Stop a running Runspace Workflow. 8 | This shuts down all running runspaces of all associated workers. 9 | Queues will remain unaffected, and the Workflow remains registered and available. 10 | 11 | To fully remove it, use Remove-PSFRunspaceWorkflow instead. 12 | 13 | .PARAMETER Name 14 | The name of the Runspace Workflow to stop. 15 | 16 | .PARAMETER InputObject 17 | The Runspace Workflow object to stop. 18 | 19 | .EXAMPLE 20 | PS C:\> $workflow | Stop-PSFRunspaceWorkflow 21 | 22 | Stops the specified Runspace Workflow. 23 | 24 | .LINK 25 | https://psframework.org/documentation/documents/psframework/runspace-workflows.html 26 | #> 27 | [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseShouldProcessForStateChangingFunctions", "")] 28 | [CmdletBinding()] 29 | param ( 30 | [Parameter(ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] 31 | [PsfArgumentCompleter('PSFramework-runspace-workflow-name')] 32 | [string[]] 33 | $Name, 34 | 35 | [Parameter(ValueFromPipeline = $true)] 36 | [PSFramework.Runspace.RSWorkflow[]] 37 | $InputObject 38 | ) 39 | process { 40 | $resolvedWorkflows = Resolve-PsfRunspaceWorkflow -Name $Name -InputObject $InputObject -Cmdlet $PSCmdlet 41 | 42 | foreach ($resolvedWorkflow in $resolvedWorkflows) { 43 | $resolvedWorkflow.Stop() 44 | } 45 | } 46 | } -------------------------------------------------------------------------------- /PSFramework/tests/extensions/BeTrueForAny.ps1: -------------------------------------------------------------------------------- 1 | function BeTrueForAny 2 | { 3 | [CmdletBinding()] 4 | param ( 5 | $ActualValue, 6 | 7 | [scriptblock] 8 | $TestScript, 9 | 10 | [switch] 11 | $Negate 12 | ) 13 | end 14 | { 15 | $succeeded = $false 16 | foreach ($value in $ActualValue) 17 | { 18 | $variables = [System.Collections.Generic.List[psvariable]]( 19 | [psvariable]::new('_', $value)) 20 | 21 | $succeeded = $TestScript.InvokeWithContext( 22 | <# functionsToDefine: #> @{ }, 23 | <# variablesToDefine: #> $variables, 24 | <# args: #> $value) 25 | 26 | if ($Negate.IsPresent) 27 | { 28 | $succeeded = -not $succeeded 29 | } 30 | 31 | if ($succeeded) 32 | { 33 | break 34 | } 35 | } 36 | 37 | if (-not $succeeded) 38 | { 39 | if ($Negate.IsPresent) 40 | { 41 | $failureMessage = 42 | 'Expected: Any value to fail the evaluation script, ' + 43 | 'but no value returned false. (ActualValue: {0})' -f ($ActualValue -join ', ') 44 | } 45 | else 46 | { 47 | $failureMessage = 48 | 'Expected: Any value to pass the evaluation script, ' + 49 | 'but no value returned true. (ActualValue: {0})' -f ($ActualValue -join ', ') 50 | } 51 | } 52 | 53 | [PSCustomObject]@{ 54 | Succeeded = $succeeded 55 | FailureMessage = $failureMessage 56 | } 57 | } 58 | } 59 | Add-ShouldOperator -Name BeTrueForAny -Test $function:BeTrueForAny -Alias Any -SupportsArrayInput -------------------------------------------------------------------------------- /PSFramework/functions/flowcontrol/Get-PSFCallback.ps1: -------------------------------------------------------------------------------- 1 | function Get-PSFCallback 2 | { 3 | <# 4 | .SYNOPSIS 5 | Returns a list of callback scripts. 6 | 7 | .DESCRIPTION 8 | Returns a list of callback scripts. 9 | Use Register-PSFCallback to register new callback scripts. 10 | Use Unregister-PSFCallback to remove callback scripts. 11 | Use Invoke-PSFCallback within a function of your module to execute all registered callback scripts that apply. 12 | 13 | .PARAMETER Name 14 | The name to filter by. 15 | 16 | .PARAMETER All 17 | Return all callback scripts, even those specific to other runspaces. 18 | 19 | .EXAMPLE 20 | PS C:\> Get-PSFCallback 21 | 22 | Returns all callback scripts relevant to the current runspace. 23 | 24 | .EXAMPLE 25 | PS C:\> Get-PSFCallback -All 26 | 27 | Returns all callback scripts in the entire process. 28 | 29 | .EXAMPLE 30 | PS C:\> Get-PSFCallback -Name MyModule.Configuration 31 | 32 | Returns the callback script named 'MyModule.Configuration' 33 | #> 34 | [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseOutputTypeCorrectly", "")] 35 | [OutputType([PSFramework.FlowControl.Callback])] 36 | [CmdletBinding()] 37 | param ( 38 | [Parameter(ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] 39 | [string[]] 40 | $Name = '*', 41 | 42 | [switch] 43 | $All 44 | ) 45 | 46 | process 47 | { 48 | foreach ($nameString in $Name) 49 | { 50 | [PSFramework.FlowControl.CallbackHost]::Get($nameString, $All.ToBool()) 51 | } 52 | } 53 | } -------------------------------------------------------------------------------- /PSFramework/en-us/stringsScriptblock.psd1: -------------------------------------------------------------------------------- 1 | @{ 2 | 'Validate.Filter.ConditionName' = 'Invalid filter name: {0}. Make sure the name specified only consists of numbers, letters and underscores (and equals neither 0 or 1)!' 3 | 4 | 'Validate.FSPath' = 'The specified input is not an existing filesystem path: {0}' 5 | 'Validate.FSPath.File' = 'The specified input is not a path to an existing file: {0}' 6 | 'Validate.FSPath.FileOrParent' = 'The specified input is not a path to an existing file, nor does its parent folder exist: {0}' 7 | 'Validate.FSPath.Folder' = 'The specified input is not a path to an existing folder: {0}' 8 | 'Validate.Path' = 'The specified input is not an existing path: {0}' 9 | 'Validate.Path.Container' = 'The specified input is not an existing container path (e.g: Folder): {0}' 10 | 'Validate.Path.Leaf' = 'The specified input is not an existing leaf path (e.g: File): {0}' 11 | 'Validate.Uri.Absolute' = 'The specified input is not an absolute uri: {0}' 12 | 'Validate.Uri.Absolute.File' = 'The specified input is not an absolute uri pointing at a file: {0}' 13 | 'Validate.Uri.Absolute.Https' = 'The specified input is not an absolute uri pointing at a weblink (https://...): {0}' 14 | 15 | 'Validate.TimeSpan.Positive' = 'The specified input is not a timespan with a value greater than 0: {0}' 16 | 17 | 'Validate.SafeName' = 'Illegal name! This parameter only allows letters, numbers, dots, dashes and underscores. Value provided: "{0}"' 18 | } -------------------------------------------------------------------------------- /PSFramework/functions/taskengine/Disable-PSFTaskEngineTask.ps1: -------------------------------------------------------------------------------- 1 | function Disable-PSFTaskEngineTask 2 | { 3 | <# 4 | .SYNOPSIS 5 | Disables a task registered to the PSFramework task engine. 6 | 7 | .DESCRIPTION 8 | Disables a task registered to the PSFramework task engine. 9 | 10 | .PARAMETER Name 11 | Name of the task to disable. 12 | 13 | .PARAMETER Task 14 | The task registered. Must be a task object returned by Get-PSFTaskEngineTask. 15 | 16 | .EXAMPLE 17 | PS C:\> Get-PSFTaskEngineTask -Name 'mymodule.maintenance' | Disable-PSFTaskEngineTask 18 | 19 | Disables the task named 'mymodule.maintenance' 20 | #> 21 | [CmdletBinding(HelpUri = 'https://psframework.org/documentation/commands/PSFramework/Disable-PSFTaskEngineTask')] 22 | param ( 23 | [string[]] 24 | $Name, 25 | 26 | [Parameter(ValueFromPipeline = $true)] 27 | [PSFramework.TaskEngine.PsfTask[]] 28 | $Task 29 | ) 30 | 31 | process 32 | { 33 | foreach ($item in $Task) 34 | { 35 | if ($item.Enabled) 36 | { 37 | Write-PSFMessage -Level Verbose -String 'Disable-PSFTaskEngineTask.Disabling' -StringValues $item.Name -Tag 'disable', 'taskengine', 'task' 38 | $item.Enabled = $false 39 | } 40 | } 41 | foreach ($taskName in $Name) 42 | { 43 | foreach ($taskObject in Get-PSFTaskEngineTask -Name $taskName) 44 | { 45 | Write-PSFMessage -Level Verbose -String 'Disable-PSFTaskEngineTask.Disabling' -StringValues $taskObject.Name -Tag 'disable', 'taskengine', 'task' 46 | $taskObject.Enabled = $false 47 | } 48 | } 49 | } 50 | } -------------------------------------------------------------------------------- /PSFramework/functions/import/Export-PSFModuleClass.ps1: -------------------------------------------------------------------------------- 1 | function Export-PSFModuleClass 2 | { 3 | <# 4 | .SYNOPSIS 5 | Exports a module-defined PowerShell class irrespective of how the module is being imported. 6 | 7 | .DESCRIPTION 8 | Exports a module-defined PowerShell class irrespective of how the module is being imported. 9 | This avoids having to worry about how the module is being imported. 10 | 11 | Please beware the risk of class-name-collisions however. 12 | 13 | .PARAMETER ClassType 14 | The types to publish. 15 | 16 | .EXAMPLE 17 | PS C:\> Export-PSFModuleClass -ClassType ([MyModule_MyClass]) 18 | 19 | Publishes the class MyModule_MyClass, making it available outside of your module. 20 | #> 21 | [CmdletBinding()] 22 | Param ( 23 | [Parameter(Mandatory = $true, ValueFromPipeline = $true)] 24 | [System.Type[]] 25 | $ClassType 26 | ) 27 | 28 | begin 29 | { 30 | $internalExecutionContext = [PSFramework.Utility.UtilityHost]::GetExecutionContextFromTLS() 31 | $topLevelSessionState = [PSFramework.Utility.UtilityHost]::GetPrivateProperty('TopLevelSessionState', $internalExecutionContext) 32 | $globalScope = [PSFramework.Utility.UtilityHost]::GetPrivateProperty('GlobalScope', $topLevelSessionState) 33 | $addMethod = $globalScope.GetType().GetMethod('AddType', [System.Reflection.BindingFlags]'Instance, NonPublic') 34 | } 35 | process 36 | { 37 | foreach ($typeObject in $ClassType) 38 | { 39 | $arguments = @($typeObject.Name, $typeObject) 40 | $addMethod.Invoke($globalScope, $arguments) 41 | } 42 | } 43 | } -------------------------------------------------------------------------------- /library/PSFramework/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("PSFramework")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("PSFramework")] 13 | [assembly: AssemblyCopyright("Copyright © 2017")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("d07e0143-2198-4cf2-af90-bf008a8ec685")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.1")] 36 | [assembly: AssemblyFileVersion("1.0.0.1")] 37 | -------------------------------------------------------------------------------- /PSFramework/functions/runspace/Get-PSFRunspaceWorker.ps1: -------------------------------------------------------------------------------- 1 | function Get-PSFRunspaceWorker { 2 | <# 3 | .SYNOPSIS 4 | Retrieve workers associated with a Runspace Workflow. 5 | 6 | .DESCRIPTION 7 | Retrieve workers associated with a Runspace Workflow. 8 | 9 | .PARAMETER Name 10 | Name of the worker to filter by. 11 | Defaults to * 12 | 13 | .PARAMETER WorkflowName 14 | Name of the Runspace Workflow from which to retrieve workers. 15 | The workflow contains all the workers, queues and management tools for the Runspace Workflow. 16 | 17 | .PARAMETER InputObject 18 | Workflow object from which to retrieve workers. 19 | The workflow contains all the workers, queues and management tools for the Runspace Workflow. 20 | 21 | .EXAMPLE 22 | PS C:\> Get-PSFRunspaceWorkflow | Get-PSFRunspaceWorker 23 | 24 | Get all workers of all runspace workflows. 25 | 26 | .LINK 27 | https://psframework.org/documentation/documents/psframework/runspace-workflows.html 28 | #> 29 | [CmdletBinding()] 30 | param ( 31 | [string] 32 | $Name = '*', 33 | 34 | [Parameter(ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] 35 | [PsfArgumentCompleter('PSFramework-runspace-workflow-name')] 36 | [string[]] 37 | $WorkflowName, 38 | 39 | [Parameter(ValueFromPipeline = $true)] 40 | [PSFramework.Runspace.RSWorkflow[]] 41 | $InputObject 42 | ) 43 | process { 44 | $resolvedWorkflows = Resolve-PsfRunspaceWorkflow -Name $WorkflowName -InputObject $InputObject -Cmdlet $PSCmdlet 45 | 46 | $resolvedWorkflows.Workers.Values | Where-Object Name -Like $Name 47 | } 48 | } -------------------------------------------------------------------------------- /PSFramework/functions/flowcontrol/Test-PSFFunctionInterrupt.ps1: -------------------------------------------------------------------------------- 1 | function Test-PSFFunctionInterrupt 2 | { 3 | <# 4 | .SYNOPSIS 5 | Tests whether the calling function should be interrupted. 6 | 7 | .DESCRIPTION 8 | This helper function is designed to work in tandem with Stop-PSFFunction. 9 | When gracefully terminating a function, there is a major issue: 10 | "Return" will only stop the current one of the three blocks (Begin, Process, End). 11 | All other statements have side effects or produce lots of red text. 12 | 13 | So, Stop-PSFFunction writes a variable into the parent scope, that signals the function should cease. 14 | This function then checks for that very variable and returns true if it is set. 15 | 16 | This avoids having to handle odd variables in the parent function and causes the least impact on contributors. 17 | 18 | For a more detailed explanation - including commented full-scale implementation examples - see the associated help article: 19 | Get-Help about_psf_flowcontrol 20 | 21 | .EXAMPLE 22 | if (Test-PSFFunctionInterrupt) { return } 23 | 24 | The calling function will stop if this function returns true. 25 | #> 26 | [OutputType([System.Boolean])] 27 | [CmdletBinding(HelpUri = 'https://psframework.org/documentation/commands/PSFramework/Test-PSFFunctionInterrupt')] 28 | Param ( 29 | 30 | ) 31 | 32 | $psframework_killqueue -contains (Get-PSCallStack)[1].InvocationInfo.GetHashCode() 33 | } -------------------------------------------------------------------------------- /library/PSFramework/ComputerManagement/PSSessionContainer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Management.Automation.Runspaces; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace PSFramework.ComputerManagement 9 | { 10 | /// 11 | /// A class designed to contain PSSessionInfo objects 12 | /// 13 | public class PSSessionContainer : Dictionary 14 | { 15 | /// 16 | /// Creeates a session container dictionary, that is not opinionated about casing. 17 | /// 18 | public PSSessionContainer() 19 | : base(StringComparer.InvariantCultureIgnoreCase) 20 | { 21 | 22 | } 23 | 24 | /// 25 | /// Returns a list of all expired sessions 26 | /// 27 | /// The list of expired sessions 28 | public IEnumerable GetExpired() 29 | { 30 | return from a in Values where a.IsExpired select a; 31 | } 32 | 33 | /// 34 | /// Returns a list of all sessions that have broken (generally by having hit the hard wsman limits or the remote computer being down) 35 | /// 36 | /// The list of broken sessions. 37 | public IEnumerable GetBroken() 38 | { 39 | return from a in Values where a.Availability == RunspaceAvailability.None select a; 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /PSFramework/xml/readme.md: -------------------------------------------------------------------------------- 1 | # XML 2 | 3 | This is the folder where project XML files go, notably: 4 | 5 | - Format XML 6 | - Type Extension XML 7 | 8 | External help files should _not_ be placed in this folder! 9 | 10 | ## Notes on Files and Naming 11 | 12 | There should be only one format file and one type extension file per project, as importing them has a notable impact on import times. 13 | 14 | - The Format XML should be named `PSFramework.Format.ps1xml` 15 | - The Type Extension XML should be named `PSFramework.Types.ps1xml` 16 | 17 | ## Tools 18 | 19 | ### New-PSMDFormatTableDefinition 20 | 21 | This function will take an input object and generate format xml for an auto-sized table. 22 | 23 | It provides a simple way to get started with formats. 24 | 25 | ### Get-PSFTypeSerializationData 26 | 27 | ``` 28 | C# Warning! 29 | This section is only interest if you're using C# together with PowerShell. 30 | ``` 31 | 32 | This function generates type extension XML that allows PowerShell to convert types written in C# to be written to file and restored from it without being 'Deserialized'. Also works for jobs or remoting, if both sides have the `PSFramework` module and type extension loaded. 33 | 34 | In order for a class to be eligible for this, it needs to conform to the following rules: 35 | 36 | - Have the `[Serializable]` attribute 37 | - Be public 38 | - Have an empty constructor 39 | - Allow all public properties/fields to be set (even if setting it doesn't do anything) without throwing an exception. 40 | 41 | ``` 42 | non-public properties and fields will be lost in this process! 43 | ``` -------------------------------------------------------------------------------- /library/PSFramework/Data/Converters/ScriptblockConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Management.Automation; 5 | using System.Management.Automation.Language; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | 9 | namespace PSFramework.Data.Converters 10 | { 11 | /// 12 | /// Converts data structures into PSD1 Strings 13 | /// 14 | internal class ScriptblockConverter : IPsd1Converter 15 | { 16 | /// 17 | /// Converts to psd1 string 18 | /// 19 | /// The object to convert 20 | /// The indentation level 21 | /// The conversion runtime object, including its settings. 22 | /// The parent objects. Used in complex data types to prevent infinite recursion. 23 | /// The converted PSD1 representation of the value provided 24 | public string Convert(object Value, object[] Parents, int Depth, Psd1Converter Converter) 25 | { 26 | ScriptBlock code = (ScriptBlock)Value; 27 | StringBuilder sb = new StringBuilder(); 28 | sb.AppendLine("{"); 29 | foreach (string line in code.Ast.Extent.Text.Substring(1, code.Ast.Extent.Text.Length - 2).Split('\n')) 30 | sb.AppendLine($" {line}"); 31 | sb.Append($"{new String(' ', 4 * Depth)}}}"); 32 | 33 | return sb.ToString(); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /PSFramework/functions/filter/Get-PSFFilterConditionSet.ps1: -------------------------------------------------------------------------------- 1 | function Get-PSFFilterConditionSet { 2 | <# 3 | .SYNOPSIS 4 | Retrieve defined filter condition sets. 5 | 6 | .DESCRIPTION 7 | Retrieve defined filter condition sets. 8 | Filter condition sets are a grouped set of conditions used in filter expressions. 9 | Create a filter expression by using New-PSFFilter. 10 | 11 | .PARAMETER Module 12 | The module to filter by. 13 | Defaults to '*' 14 | 15 | .PARAMETER Name 16 | The name of the condition set to retrieve. 17 | Defaults to '*' 18 | 19 | .PARAMETER Version 20 | Retrieve a specific version of the filter condition set. 21 | By default, the latest version only is returned. 22 | 23 | .PARAMETER AllVersions 24 | Retrieve all versions of a given filter condition set. 25 | 26 | .EXAMPLE 27 | PS C:\> Get-PSFFilterConditionSet 28 | 29 | List all defined filter condition sets. 30 | 31 | .EXAMPLE 32 | PS C:\> Get-PSFFilterConditionSet -Module PSFramework -Name Environment 33 | 34 | Returns the filter condition set "Environment" from the module PSFramework. 35 | #> 36 | [OutputType([PSFramework.Filter.ConditionSet])] 37 | [CmdletBinding()] 38 | param ( 39 | [PsfArgumentCompleter('PSFramework.Filter.SetModule')] 40 | [string] 41 | $Module = '*', 42 | 43 | [PsfArgumentCompleter('PSFramework.Filter.SetName')] 44 | [string] 45 | $Name = '*', 46 | 47 | [System.Version] 48 | $Version, 49 | 50 | [switch] 51 | $AllVersions 52 | ) 53 | 54 | process { 55 | $script:filterContainer.FindConditionSet($Module, $Name, $Version, $AllVersions) 56 | } 57 | } -------------------------------------------------------------------------------- /library/PSFramework/Data/Converters/ArrayConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Management.Automation; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | 9 | namespace PSFramework.Data.Converters 10 | { 11 | /// 12 | /// Converts data structures into PSD1 Strings 13 | /// 14 | public class ArrayConverter : IPsd1Converter 15 | { 16 | /// 17 | /// Converts to psd1 string 18 | /// 19 | /// The object to convert 20 | /// The indentation level 21 | /// The conversion runtime object, including its settings. 22 | /// The parent objects. Used in complex data types to prevent infinite recursion. 23 | /// The converted PSD1 representation of the value provided 24 | public string Convert(object Value, object[] Parents, int Depth, Psd1Converter Converter) 25 | { 26 | StringBuilder sb = new StringBuilder(); 27 | string indent = new string(' ', Depth * 4); 28 | string newIndent = new string(' ', (Depth + 1) * 4); 29 | sb.AppendLine("@("); 30 | 31 | foreach (object item in (IEnumerable)Value) 32 | sb.AppendLine($"{newIndent}{DataHost.Convert(item, Parents, Depth + 1, Converter)}"); 33 | 34 | sb.Append($"{indent})"); 35 | return sb.ToString(); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /PSFramework/functions/flowcontrol/Test-PSFLanguageMode.ps1: -------------------------------------------------------------------------------- 1 | function Test-PSFLanguageMode 2 | { 3 | <# 4 | .SYNOPSIS 5 | Tests, in what language mode a specified scriptblock is in. 6 | 7 | .DESCRIPTION 8 | Tests, in what language mode a specified scriptblock is in. 9 | Use this to determine the trustworthyness of a scriptblock, or for insights, into what its capabilities are. 10 | 11 | .PARAMETER ScriptBlock 12 | The scriptblock to test. 13 | 14 | .PARAMETER Mode 15 | The Languagemode(s) to compare it to. 16 | The scriptblock must be in one of the specified modes. 17 | Defaults to 'FullLanguage' 18 | 19 | .PARAMETER Not 20 | Reverses the test results - now the scriptblock may NOT be in one of the specified language modes. 21 | 22 | .EXAMPLE 23 | PS C:\> Test-PSFLanguageMode -ScriptBlock $ScriptBlock 24 | 25 | Returns, whether the $Scriptblock is in FullLanguage mode. 26 | 27 | .EXAMPLE 28 | PS C:\> Test-PSFLanguageMode -ScriptBlock $code -Mode ConstrainedLanguage -Not 29 | 30 | Returns $true if the specified scriptblock is NOT inconstrained language mode. 31 | #> 32 | [OutputType([boolean])] 33 | [CmdletBinding()] 34 | param ( 35 | [parameter(Mandatory = $true)] 36 | [System.Management.Automation.ScriptBlock] 37 | $ScriptBlock, 38 | 39 | [System.Management.Automation.PSLanguageMode[]] 40 | $Mode = 'FullLanguage', 41 | 42 | [switch] 43 | $Not 44 | ) 45 | 46 | process 47 | { 48 | $languageMode = [PSFramework.Utility.UtilityHost]::GetPrivateProperty("LanguageMode", $ScriptBlock) 49 | if ($Not) { $languageMode -notin $Mode } 50 | else { $languageMode -in $Mode } 51 | } 52 | } -------------------------------------------------------------------------------- /PSFramework/functions/flowcontrol/Unregister-PSFCallback.ps1: -------------------------------------------------------------------------------- 1 | function Unregister-PSFCallback 2 | { 3 | <# 4 | .SYNOPSIS 5 | Removes a callback from the list of registered callbacks. 6 | 7 | .DESCRIPTION 8 | Removes a callback from the list of registered callbacks. 9 | 10 | .PARAMETER Name 11 | The name of the callback to remove. 12 | Does NOT support wildcards. 13 | 14 | .PARAMETER Callback 15 | A full callback object to remove. 16 | Use Get-PSFCallback to get the list of relevant callback objects. 17 | 18 | .EXAMPLE 19 | PS C:\> Unregister-PSFCallback -Name 'MyModule.Configuration' 20 | 21 | Unregisters the 'MyModule.Configuration' callback script. 22 | 23 | .EXAMPLE 24 | PS C:\> Get-PSFCallback | Unregister-PSFCallback 25 | 26 | Removes all callback scripts applicable to the current runspace. 27 | #> 28 | [CmdletBinding(DefaultParameterSetName = 'Name')] 29 | param ( 30 | [Parameter(Mandatory = $true, ParameterSetName = 'Name')] 31 | [string[]] 32 | $Name, 33 | 34 | [Parameter(ValueFromPipeline = $true, ParameterSetName = 'Object', Mandatory = $true)] 35 | [PSFramework.FlowControl.Callback[]] 36 | $Callback 37 | ) 38 | 39 | process 40 | { 41 | foreach ($callbackItem in $Callback) 42 | { 43 | [PSFramework.FlowControl.CallbackHost]::Remove($callbackItem) 44 | } 45 | foreach ($nameString in $Name) 46 | { 47 | foreach ($callbackItem in ([PSFramework.FlowControl.CallbackHost]::Get($nameString, $false))) 48 | { 49 | if ($callbackItem.Name -ne $nameString) { continue } 50 | [PSFramework.FlowControl.CallbackHost]::Remove($callbackItem) 51 | } 52 | } 53 | } 54 | } -------------------------------------------------------------------------------- /library/PSFramework/Logging/Error.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Management.Automation; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace PSFramework.Logging 9 | { 10 | /// 11 | /// Container for errors that happened during logging 12 | /// 13 | public class Error 14 | { 15 | /// 16 | /// The logging provider that had the issue 17 | /// 18 | public string Provider; 19 | 20 | /// 21 | /// The specific instance of the logging provider that encounter the issue 22 | /// 23 | public string Instance; 24 | 25 | /// 26 | /// When it all happened 27 | /// 28 | public DateTime Timestamp; 29 | 30 | /// 31 | /// The error that happened 32 | /// 33 | public ErrorRecord ErrorRecord; 34 | 35 | /// 36 | /// Create a new error object 37 | /// 38 | /// Logging Provider with the issue 39 | /// Instance of the Logging Provider with the issue 40 | /// The Issue 41 | public Error(string Provider, string Instance, ErrorRecord ErrorRecord) 42 | { 43 | this.Provider = Provider; 44 | this.Instance = Instance; 45 | this.ErrorRecord = ErrorRecord; 46 | Timestamp = DateTime.Now; 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /library/PSFramework/Utility/TypeTransformationAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Management.Automation; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace PSFramework.Utility 9 | { 10 | /// 11 | /// Tries to convert input type into the target type, using PowerShell type coercion. 12 | /// Implemented to have a bool parameter accept a switch value. 13 | /// 14 | public class TypeTransformationAttribute : ArgumentTransformationAttribute 15 | { 16 | /// 17 | /// The type to convert to 18 | /// 19 | public Type TargetType; 20 | 21 | /// 22 | /// Converts input to output 23 | /// 24 | /// 25 | /// 26 | /// 27 | public override object Transform(EngineIntrinsics engineIntrinsics, object inputData) 28 | { 29 | try 30 | { 31 | return LanguagePrimitives.ConvertTo(inputData, TargetType); 32 | } 33 | catch 34 | { 35 | throw; 36 | } 37 | } 38 | 39 | /// 40 | /// Creates the basic attribute specifying the target type 41 | /// 42 | /// The type to convert to 43 | public TypeTransformationAttribute(Type TargetType) 44 | { 45 | this.TargetType = TargetType; 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /library/PSFramework/Parameter/ParameterContractAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace PSFramework.Parameter 4 | { 5 | /// 6 | /// The attribute used to define the elements of a ParameterClass contract 7 | /// 8 | [AttributeUsage(AttributeTargets.All)] 9 | public class ParameterContractAttribute : Attribute 10 | { 11 | private ParameterContractType type; 12 | private ParameterContractBehavior behavior; 13 | 14 | /// 15 | /// Returns the type of the element this attribute is supposed to be attached to. 16 | /// 17 | public ParameterContractType Type 18 | { 19 | get 20 | { 21 | return type; 22 | } 23 | } 24 | 25 | /// 26 | /// Returns the behavior to expect from the contracted element. This sets the expectations on how this element is likely to act. 27 | /// 28 | public ParameterContractBehavior Behavior 29 | { 30 | get 31 | { 32 | return behavior; 33 | } 34 | } 35 | 36 | /// 37 | /// Ceates a perfectly common parameter contract attribute. For use with all parameter classes' public elements. 38 | /// 39 | /// 40 | /// 41 | public ParameterContractAttribute(ParameterContractType Type, ParameterContractBehavior Behavior) 42 | { 43 | type = Type; 44 | behavior = Behavior; 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /PSFramework/tests/functions/pipeline/Remove-PSFNull.Tests.ps1: -------------------------------------------------------------------------------- 1 | Describe "Remove-PSFNull Unit Tests" -Tag "CI", "Pipeline", "Unit" { 2 | # Catch any signature changes to force revisiting the command 3 | It "Should have the designed for parameters & sets" { 4 | (Get-Command Remove-PSFNull).ParameterSets.Name | Should -Be '__AllParameterSets' 5 | foreach ($key in (Get-Command Remove-PSFNull).Parameters.Keys) 6 | { 7 | $key | Should -BeIn 'InputObject', 'AllowEmptyStrings', 'AllowEmptyCollections', 'Enumerate', 'Verbose', 'Debug', 'ErrorAction', 'WarningAction', 'InformationAction', 'ErrorVariable', 'WarningVariable', 'InformationVariable', 'OutVariable', 'OutBuffer', 'PipelineVariable', 'ProgressAction' 8 | } 9 | } 10 | 11 | It "Should allow only non-null values through" { 12 | 1, 2, 3, $null, 4 | Remove-PSFNull | Should -Be 1, 2, 3, 4 13 | 1, 2, 3, "", 4 | Remove-PSFNull | Should -Be 1, 2, 3, 4 14 | 1, 2, 3, @(), 4 | Remove-PSFNull | Should -Be 1, 2, 3, 4 15 | } 16 | 17 | It "Should properly implement exceptions" { 18 | 1, $null, 2, "", 3, @(), 4 | Remove-PSFNull | Should -Be 1, 2, 3, 4 19 | 1, $null, 2, "", 3, @(), 4 | Remove-PSFNull -AllowEmptyStrings | Should -Be 1, 2, "", 3, 4 20 | 1, $null, 2, "", 3, @(), 4 | Remove-PSFNull -AllowEmptyCollections | Should -Be 1, 2, 3, @(), 4 21 | 1, $null, 2, "", 3, @(), 4 | Remove-PSFNull -AllowEmptyStrings -AllowEmptyCollections | Should -Be 1, 2, "", 3, @(), 4 22 | } 23 | 24 | It "Should not enumerate objects unless asked to" { 25 | ( ,@(1, 2, 3) | Remove-PSFNull | Measure-Object).Count | Should -Be 1 26 | ( ,@(1, 2, 3) | Remove-PSFNull -Enumerate | Measure-Object).Count | Should -Be 3 27 | } 28 | } -------------------------------------------------------------------------------- /PSFramework/internal/scripts/cmdlets.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | Registers the cmdlets published by this module. 3 | Necessary for full hybrid module support. 4 | #> 5 | $commonParam = @{ 6 | HelpFile = (Resolve-Path "$($script:ModuleRoot)\en-us\PSFramework.dll-Help.xml") 7 | Module = $ExecutionContext.SessionState.Module 8 | } 9 | 10 | Import-PSFCmdlet @commonParam -Name Assert-PSFInternalCommand -Type ([PSFramework.Commands.AssertPSFInternalCommandCommand]) 11 | Import-PSFCmdlet @commonParam -Name ConvertTo-PSFHashtable -Type ([PSFramework.Commands.ConvertToPSFHashtableCommand]) 12 | Import-PSFCmdlet @commonParam -Name Invoke-PSFCallback -Type ([PSFramework.Commands.InvokePSFCallbackCommand]) 13 | Import-PSFCmdlet @commonParam -Name Invoke-PSFProtectedCommand -Type ([PSFramework.Commands.InvokePSFProtectedCommand]) 14 | Import-PSFCmdlet @commonParam -Name Remove-PSFNull -Type ([PSFramework.Commands.RemovePSFNullCommand]) 15 | Import-PSFCmdlet @commonParam -Name Select-PSFObject -Type ([PSFramework.Commands.SelectPSFObjectCommand]) 16 | Import-PSFCmdlet @commonParam -Name Set-PSFObjectOrder -Type ([PSFramework.Commands.SortPSFObjectCommand]) 17 | Import-PSFCmdlet @commonParam -Name Set-PSFConfig -Type ([PSFramework.Commands.SetPSFConfigCommand]) 18 | Import-PSFCmdlet @commonParam -Name Test-PSFShouldProcess -Type ([PSFramework.Commands.TestPSFShouldProcessCommand]) 19 | Import-PSFCmdlet @commonParam -Name Write-PSFMessage -Type ([PSFramework.Commands.WritePSFMessageCommand]) 20 | Import-PSFCmdlet @commonParam -Name Update-PSFTeppCompletion -Type ([PSFramework.Commands.UpdatePSFTeppCompletionCommand]) 21 | 22 | Set-Alias -Name Sort-PSFObject -Value Set-PSFObjectOrder -Force -ErrorAction SilentlyContinue -------------------------------------------------------------------------------- /PSFramework/functions/utility/Remove-PSFAlias.ps1: -------------------------------------------------------------------------------- 1 | function Remove-PSFAlias 2 | { 3 | <# 4 | .SYNOPSIS 5 | Removes an alias from the global scope. 6 | 7 | .DESCRIPTION 8 | Removes an alias from the global* scope. 9 | Please note that this always affects the global scope and should not be used lightly. 10 | This has the potential to break code that does not comply with PowerShell best practices and relies on the use of aliases. 11 | 12 | Refuses to delete constant aliases. 13 | Requires the '-Force' parameter to delete ReadOnly aliases. 14 | 15 | *This includes aliases exported by modules. 16 | 17 | .PARAMETER Name 18 | The name of the alias to remove. 19 | 20 | .PARAMETER Force 21 | Enforce removal of aliases. Required to remove ReadOnly aliases (including default aliases such as "select" or "group"). 22 | 23 | .EXAMPLE 24 | PS C:\> Remove-PSFAlias -Name 'grep' 25 | 26 | Removes the global alias 'grep' 27 | 28 | .EXAMPLE 29 | PS C:\> Remove-PSFAlias -Name 'select' -Force 30 | 31 | Removes the default alias 'select' 32 | #> 33 | [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseShouldProcessForStateChangingFunctions", "")] 34 | [CmdletBinding()] 35 | param ( 36 | [Parameter(ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, Mandatory = $true)] 37 | [string[]] 38 | $Name, 39 | 40 | [switch] 41 | $Force 42 | ) 43 | 44 | process 45 | { 46 | foreach ($alias in $Name) 47 | { 48 | try { [PSFramework.Utility.UtilityHost]::RemovePowerShellAlias($alias, $Force.ToBool()) } 49 | catch { Stop-PSFFunction -Message $_ -EnableException $true -Cmdlet $PSCmdlet -ErrorRecord $_ -OverrideExceptionMessage } 50 | } 51 | } 52 | } -------------------------------------------------------------------------------- /PSFramework/internal/functions/flowcontrol/Invoke-PsfTerminatingException.ps1: -------------------------------------------------------------------------------- 1 | function Invoke-PsfTerminatingException 2 | { 3 | <# 4 | .SYNOPSIS 5 | Executes a terminating error. 6 | 7 | .DESCRIPTION 8 | Executes a terminating error in the context of the caller. 9 | 10 | .PARAMETER Message 11 | Message to include in the terminating error. 12 | 13 | .PARAMETER ErrorId 14 | Error ID to make part of the error record. 15 | 16 | .PARAMETER Category 17 | The error category. 18 | 19 | .PARAMETER TargetObject 20 | The target of the error. 21 | 22 | .PARAMETER Cmdlet 23 | The $PSCmdlet variable of the caller 24 | 25 | .EXAMPLE 26 | PS C:\> Invoke-PsfTerminatingException -Message 'Failed to do XYZ' -ErrorId 'FatalFail' -Category InvalidOperation -TargetObject $TargetObject -Cmdlet $PSCmdlet 27 | 28 | Executes a terminating error in the context of the caller. 29 | #> 30 | [CmdletBinding()] 31 | param ( 32 | [Parameter(Mandatory = $true)] 33 | [string] 34 | $Message, 35 | 36 | [Parameter(Mandatory = $true)] 37 | [string] 38 | $ErrorId, 39 | 40 | [Parameter(Mandatory = $true)] 41 | [System.Management.Automation.ErrorCategory] 42 | $Category, 43 | 44 | [Parameter(Mandatory = $true)] 45 | $TargetObject, 46 | 47 | [Parameter(Mandatory = $true)] 48 | $Cmdlet 49 | ) 50 | 51 | process{ 52 | $exception = switch ("$Category") { 53 | "InvalidArgument" { New-Object System.ArgumentException($Message) } 54 | default { New-Object System.Exception($Message) } 55 | } 56 | $errorRecord = New-Object System.Management.Automation.ErrorRecord($exception, $ErrorId, $Category, $TargetObject) 57 | $Cmdlet.ThrowTerminatingError($errorRecord) 58 | } 59 | } -------------------------------------------------------------------------------- /PSFramework/functions/data/ConvertTo-PSFPsd1.ps1: -------------------------------------------------------------------------------- 1 | function ConvertTo-PSFPsd1 { 2 | <# 3 | .SYNOPSIS 4 | Converts objects into PSD1 configuration text. 5 | 6 | .DESCRIPTION 7 | Converts objects into PSD1 configuration text. 8 | 9 | Use Register-PSFPsd1Converter to extend/customize how this conversion happens. 10 | 11 | .PARAMETER Depth 12 | How many levels deep do you want to process sub-properties? 13 | Defaults to 2 14 | 15 | .PARAMETER EnableVerbose 16 | Enables deep verbosity when processing objects. 17 | By default, individual conversion steps are not tracked for performance reasons. 18 | Enable this for extensive amounts of debug messages. 19 | 20 | .PARAMETER Configuration 21 | Additional configuration settings to provide for the conversion. 22 | Custom converters may use these as implemented in their custom conversion. 23 | 24 | .PARAMETER InputObject 25 | The object(s) to convert. 26 | 27 | .EXAMPLE 28 | PS C:\> Get-ChildItem | ConvertTo-PSFPsd1 29 | 30 | Takes all files and folders and converts the data into psd1-style data structures. 31 | #> 32 | [OutputType([string])] 33 | [CmdletBinding()] 34 | param ( 35 | [int] 36 | $Depth = 2, 37 | 38 | [switch] 39 | $EnableVerbose, 40 | 41 | [Hashtable] 42 | $Configuration = @{}, 43 | 44 | [Parameter(Mandatory = $true, ValueFromPipeline = $true)] 45 | [AllowNull()] 46 | $InputObject 47 | ) 48 | begin { 49 | $converter = [PSFramework.Data.Psd1Converter]::new() 50 | $converter.MaxDepth = $Depth 51 | $converter.EnableVerbose = $EnableVerbose 52 | $converter.Config = $Configuration 53 | $converter.Cmdlet = $PSCmdlet 54 | } 55 | process { 56 | $converter.Convert($InputObject) 57 | } 58 | } -------------------------------------------------------------------------------- /PSFramework/functions/localization/Get-PSFLocalizedString.ps1: -------------------------------------------------------------------------------- 1 | function Get-PSFLocalizedString 2 | { 3 | <# 4 | .SYNOPSIS 5 | Returns the localized strings of a module. 6 | 7 | .DESCRIPTION 8 | Returns the localized strings of a module. 9 | By default, it creates a variable that has access to each localized string in the module (with string name as propertyname). 10 | Alternatively, by specifying a specific string, that string can instead be returned. 11 | 12 | .PARAMETER Module 13 | The name of the module to map. 14 | 15 | .PARAMETER Name 16 | The name of the string to return 17 | 18 | .EXAMPLE 19 | PS C:\> Get-PSFLocalizedString -Module 'MyModule' 20 | 21 | Returns an object that can be used to access any localized string. 22 | 23 | .EXAMPLE 24 | PS C:\> Get-PSFLocalizedString -Module 'MyModule' -Name 'ErrorValidation' 25 | 26 | Returns the string for the module 'MyModule' that is stored under the 'ErrorValidation' name. 27 | #> 28 | [OutputType([PSFramework.Localization.LocalStrings], ParameterSetName = 'Default')] 29 | [OutputType([System.String], ParameterSetName = 'Name')] 30 | [CmdletBinding(DefaultParameterSetName = 'Default')] 31 | param ( 32 | [Parameter(Mandatory = $true, ParameterSetName = 'Name')] 33 | [Parameter(Mandatory = $true, ParameterSetName = 'Default')] 34 | [string] 35 | $Module, 36 | 37 | [Parameter(Mandatory = $true, ParameterSetName = 'Name')] 38 | [string] 39 | $Name 40 | ) 41 | 42 | process 43 | { 44 | switch ($PSCmdlet.ParameterSetName) 45 | { 46 | 'Default' { New-Object PSFramework.Localization.LocalStrings($Module) } 47 | 'Name' { (New-Object PSFramework.Localization.LocalStrings($Module)).$Name } 48 | } 49 | } 50 | } -------------------------------------------------------------------------------- /library/PSFramework/PSFCore/DebugData.cs: -------------------------------------------------------------------------------- 1 | using PSFramework.Message; 2 | using PSFramework.Utility; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | 9 | namespace PSFramework.PSFCore 10 | { 11 | /// 12 | /// Debug data container 13 | /// 14 | public class DebugData 15 | { 16 | /// 17 | /// TImestamp the data was created at 18 | /// 19 | public readonly DateTime Timestamp = DateTime.Now; 20 | 21 | /// 22 | /// Label for the data written 23 | /// 24 | public string Label; 25 | 26 | /// 27 | /// Data submitted by the writer 28 | /// 29 | public object Data; 30 | 31 | /// 32 | /// Callstack at the moment of the call 33 | /// 34 | public CallStack ScriptCallstack = new CallStack(UtilityHost.Callstack); 35 | 36 | /// 37 | /// Runspace the message was written from 38 | /// 39 | public Guid Runspace = System.Management.Automation.Runspaces.Runspace.DefaultRunspace.InstanceId; 40 | 41 | /// 42 | /// Create debug information for troubleshooting purposes 43 | /// 44 | /// The data to write 45 | /// A label to store with the data to better track its origin 46 | public DebugData(string Label, object Data) 47 | { 48 | this.Label = Label; 49 | this.Data = Data; 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /PSFramework/tests/functions/runspace/Get-PSFRunspaceWorker.Tests.ps1: -------------------------------------------------------------------------------- 1 | Describe "Testing the command Get-PSFRunspaceWorker" -Tag "CI", "Pipeline", "Unit" { 2 | BeforeAll { 3 | Get-PSFRunspaceWorkflow | Remove-PSFRunspaceWorkflow 4 | 5 | $null = New-PSFRunspaceWorkflow -Name "Test1" 6 | Add-PSFRunspaceWorker -Name Node1 -InQueue Q1 -OutQueue Q2 -Count 1 -WorkflowName 'Test1' -ScriptBlock {} 7 | Add-PSFRunspaceWorker -Name Node2 -InQueue Q2 -OutQueue Q3 -Count 1 -WorkflowName 'Test1' -ScriptBlock {} 8 | Add-PSFRunspaceWorker -Name Node3 -InQueue Q3 -OutQueue Q4 -Count 1 -WorkflowName 'Test1' -ScriptBlock {} 9 | $null = New-PSFRunspaceWorkflow -Name "Test2" 10 | Add-PSFRunspaceWorker -Name NodeB1 -InQueue Q1 -OutQueue Q2 -Count 1 -WorkflowName 'Test2' -ScriptBlock {} 11 | Add-PSFRunspaceWorker -Name NodeB2 -InQueue Q2 -OutQueue Q3 -Count 1 -WorkflowName 'Test2' -ScriptBlock {} 12 | } 13 | AfterAll { 14 | Get-PSFRunspaceWorkflow | Remove-PSFRunspaceWorkflow 15 | } 16 | 17 | It "Should simply work (by name)" { 18 | Get-PSFRunspaceWorker -WorkflowName Test1 | Should -HaveCount 3 19 | Get-PSFRunspaceWorker -WorkflowName Test2 | Should -HaveCount 2 20 | } 21 | It "Should simply work (by object)" { 22 | Get-PSFRunspaceWorkflow -Name Test1 | Get-PSFRunspaceWorker | Should -HaveCount 3 23 | Get-PSFRunspaceWorkflow -Name Test2 | Get-PSFRunspaceWorker | Should -HaveCount 2 24 | } 25 | It "Should retrieve them all" { 26 | Get-PSFRunspaceWorkflow | Get-PSFRunspaceWorker | Should -HaveCount 5 27 | } 28 | It "Should filter correctly" { 29 | Get-PSFRunspaceWorkflow | Get-PSFRunspaceWorker -Name '*1' | Should -HaveCount 2 30 | Get-PSFRunspaceWorkflow | Get-PSFRunspaceWorker -Name 'NodeB*' | Should -HaveCount 2 31 | } 32 | } -------------------------------------------------------------------------------- /PSFramework/functions/utility/Register-PSFArgumentTransformationScriptblock.ps1: -------------------------------------------------------------------------------- 1 | function Register-PSFArgumentTransformationScriptblock { 2 | <# 3 | .SYNOPSIS 4 | Registers an input conversion scriptblock for use in Parameter Binding. 5 | 6 | .DESCRIPTION 7 | Registers an input conversion scriptblock for use in Parameter Binding. 8 | It receives exactly one input - the parameter input to convert. 9 | The scriptblock is expected to return the result in the expected type - only the first value returned is used. 10 | 11 | If this conversion failes, it will still try to convert it with the default PowerShell type conversion. 12 | 13 | The scriptblock registered here can later be referenced in your commands as a parameter attribute like this: 14 | [PsfScriptTransformation("MyModule.User", [MyModule.User])] 15 | 16 | - The first value is the name specified here. 17 | - The second value is the expected data type. 18 | 19 | .PARAMETER Name 20 | Name of the scriptblock. 21 | The name can be arbitrary, but naming should consider the potential to conflict with other modules. 22 | 23 | .PARAMETER Scriptblock 24 | The script logic performing the conversion. 25 | 26 | .EXAMPLE 27 | PS C:\> Register-PSFArgumentTransformationScriptblock -Name MyModule.User -Scriptblock $conversion 28 | 29 | Registers the input conversion as defined in $conversion under "MyModule.User" 30 | #> 31 | [CmdletBinding()] 32 | param ( 33 | [Parameter(Mandatory = $true, Position = 0)] 34 | [string] 35 | $Name, 36 | 37 | [Parameter(Mandatory = $true, Position = 1)] 38 | [scriptblock] 39 | $Scriptblock 40 | ) 41 | process { 42 | [PSFramework.Utility.ScriptTransformationAttribute]::Conversions[$Name] = $Scriptblock 43 | } 44 | } -------------------------------------------------------------------------------- /PSFramework/internal/scripts/taskEngine.ps1: -------------------------------------------------------------------------------- 1 | $scriptBlock = { 2 | $script:___ScriptName = 'psframework.taskengine' 3 | 4 | try 5 | { 6 | #region Main Execution 7 | while ($true) 8 | { 9 | # This portion is critical to gracefully closing the script 10 | if ([PSFramework.Runspace.RunspaceHost]::Runspaces[$___ScriptName].State -notlike "Running") 11 | { 12 | break 13 | } 14 | 15 | $task = $null 16 | $tasksDone = @() 17 | while ($task = [PSFramework.TaskEngine.TaskHost]::GetNextTask($tasksDone)) 18 | { 19 | $task.State = 'Running' 20 | try 21 | { 22 | [PSFramework.Utility.UtilityHost]::ImportScriptBlock($task.ScriptBlock) 23 | $task.ScriptBlock.Invoke() 24 | $task.State = 'Pending' 25 | } 26 | catch 27 | { 28 | $task.State = 'Error' 29 | $task.LastError = $_ 30 | Write-PSFMessage -EnableException $false -Level Warning -Message "[Maintenance] Task '$($task.Name)' failed to execute" -ErrorRecord $_ -FunctionName "task:TaskEngine" -Target $task -ModuleName PSFramework 31 | } 32 | $task.LastExecution = Get-Date 33 | if (-not $task.Pending -and ($task.Status -eq "Pending")) { $task.Status = 'Completed' } 34 | $tasksDone += $task.Name 35 | } 36 | 37 | # If there will no more tasks need executing in the future, might as well kill the runspace 38 | if (-not ([PSFramework.TaskEngine.TaskHost]::HasPendingTasks)) { break } 39 | 40 | Start-Sleep -Seconds 5 41 | } 42 | #endregion Main Execution 43 | } 44 | catch { } 45 | finally 46 | { 47 | [PSFramework.Runspace.RunspaceHost]::Runspaces[$___ScriptName].SignalStopped() 48 | } 49 | } 50 | 51 | Register-PSFRunspace -ScriptBlock $scriptBlock -Name 'psframework.taskengine' -NoMessage -------------------------------------------------------------------------------- /PSFramework/functions/configuration/Register-PSFConfigValidation.ps1: -------------------------------------------------------------------------------- 1 | function Register-PSFConfigValidation 2 | { 3 | <# 4 | .SYNOPSIS 5 | Registers a validation scriptblock for use with the configuration system. 6 | 7 | .DESCRIPTION 8 | Registers a validation scriptblock for use with the configuration system. 9 | 10 | The scriptblock must be designed according to a few guidelines: 11 | - It must not throw exceptions 12 | - It must accept a single parameter (the value to be tested) 13 | - It must return an object with two properties: 'Message', 'Value' and 'Success'. 14 | The Success property should be boolean and indicate whether the value is valid. 15 | The Value property contains the validated input. The scriptblock may legally convert the input (For example from string to int in case of integer validation) 16 | The message contains a string that will be passed along to an exception in case the input is NOT valid. 17 | 18 | .PARAMETER Name 19 | The name under which to register the validation scriptblock 20 | 21 | .PARAMETER ScriptBlock 22 | The scriptblock to register 23 | 24 | .EXAMPLE 25 | PS C:\> Register-PSFConfigValidation -Name IntPositive -ScriptBlock $scriptblock 26 | 27 | Registers the scriptblock stored in $scriptblock as validation with the name IntPositive 28 | #> 29 | [CmdletBinding(HelpUri = 'https://psframework.org/documentation/commands/PSFramework/Register-PSFConfigValidation')] 30 | Param ( 31 | [Parameter(Mandatory = $true)] 32 | [string] 33 | $Name, 34 | 35 | [Parameter(Mandatory = $true)] 36 | [ScriptBlock] 37 | $ScriptBlock 38 | ) 39 | process 40 | { 41 | [PSFramework.Configuration.ConfigurationHost]::Validation[$Name] = $ScriptBlock 42 | } 43 | } -------------------------------------------------------------------------------- /PSFramework/functions/taskengine/Get-PSFTaskEngineCache.ps1: -------------------------------------------------------------------------------- 1 | function Get-PSFTaskEngineCache 2 | { 3 | <# 4 | .SYNOPSIS 5 | Retrieve values from the cache for a task engine task. 6 | 7 | .DESCRIPTION 8 | Retrieve values from the cache for a task engine task. 9 | Tasks scheduled under the PSFramework task engine do not have a way to directly pass information to the primary runspace. 10 | Using Set-PSFTaskEngineCache, they can store the information somewhere where the main runspace can retrieve it using this function. 11 | 12 | .PARAMETER Module 13 | The name of the module that generated the task. 14 | Use scriptname in case of using this within a script. 15 | Note: Must be the same as the name used within the task when calling 'Set-PSFTaskEngineCache' 16 | 17 | .PARAMETER Name 18 | The name of the task for which the cache is. 19 | Note: Must be the same as the name used within the task when calling 'Set-PSFTaskEngineCache' 20 | 21 | .EXAMPLE 22 | PS C:\> Get-PSFTaskEngineCache -Module 'mymodule' -Name 'maintenancetask' 23 | 24 | Retrieves the information stored under 'mymodule.maintenancetask' 25 | #> 26 | [CmdletBinding(HelpUri = 'https://psframework.org/documentation/commands/PSFramework/Get-PSFTaskEngineCache')] 27 | Param ( 28 | [Parameter(Mandatory = $true)] 29 | [ValidateNotNullOrEmpty()] 30 | [string] 31 | $Module, 32 | 33 | [Parameter(Mandatory = $true)] 34 | [ValidateNotNullOrEmpty()] 35 | [string] 36 | $Name 37 | ) 38 | 39 | process 40 | { 41 | $cacheItem = [PSFramework.TaskEngine.TaskHost]::GetCacheItem($Module, $Name) 42 | if (-not $cacheItem) { return } 43 | 44 | $value = $cacheItem.GetValue() 45 | if ($null -ne $value) { $value } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /PSFramework/functions/logging/Remove-PSFLoggingProviderRunspace.ps1: -------------------------------------------------------------------------------- 1 | function Remove-PSFLoggingProviderRunspace 2 | { 3 | <# 4 | .SYNOPSIS 5 | Removes a runspace from the list of dynamically included runspaces of an active logging provider instance. 6 | 7 | .DESCRIPTION 8 | Removes a runspace from the list of dynamically included runspaces of an active logging provider instance. 9 | See the help on Add-PSFLoggingProviderRunspace for details on how and why this is desirable. 10 | 11 | .PARAMETER ProviderName 12 | Name of the logging provider the instance is part of. 13 | 14 | .PARAMETER InstanceName 15 | Name of the logging provider instance to target. 16 | Default: "default" (the instance created when you omit the instancename parameter on Set-PSFLoggingProvider) 17 | 18 | .PARAMETER Runspace 19 | The Runspace ID of the runspace to remove. 20 | Defaults to the current runspace. 21 | 22 | .EXAMPLE 23 | PS C:\> Remove-PSFLoggingProviderRunspace -ProviderName 'logfile' -InstanceName UpdateTask 24 | 25 | Removes the current runspace from the list of included runspaces on the logfile instance "UpdateTask". 26 | #> 27 | [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '')] 28 | [CmdletBinding()] 29 | Param ( 30 | [Parameter(Mandatory = $true)] 31 | [string] 32 | $ProviderName, 33 | 34 | [string] 35 | $InstanceName = 'default', 36 | 37 | [guid] 38 | $Runspace = [System.Management.Automation.Runspaces.Runspace]::DefaultRunspace.InstanceId 39 | ) 40 | 41 | process 42 | { 43 | $instance = Get-PSFLoggingProviderInstance -ProviderName $ProviderName -Name $InstanceName 44 | if ($instance) { 45 | $instance.RemoveRunspace($Runspace) 46 | } 47 | } 48 | } -------------------------------------------------------------------------------- /PSFramework/functions/runspace/Start-PSFRunspaceWorkflow.ps1: -------------------------------------------------------------------------------- 1 | function Start-PSFRunspaceWorkflow { 2 | <# 3 | .SYNOPSIS 4 | Starts a Runspace Workflow. 5 | 6 | .DESCRIPTION 7 | Starts a Runspace Workflow. 8 | This will launch all workers and their associated runspaces. 9 | 10 | Consider queuing input first (Write-PSFRunspaceQueue) before starting the workflow. 11 | 12 | .PARAMETER Name 13 | Name of the Runspace Workflow to launch. 14 | 15 | .PARAMETER InputObject 16 | Runspace Workflow object to launch. 17 | 18 | .PARAMETER PassThru 19 | Return the runspace workflow just started. 20 | 21 | .EXAMPLE 22 | PS C:\> Start-PSFRunspaceWorkflow -Name MailboxAnalysis 23 | 24 | Starts the Runspace Workflow "MailboxAnalysis" 25 | 26 | .EXAMPLE 27 | PS C:\> Get-PSFRunspaceWorkflow | Start-PSFRunspaceWorkflow 28 | 29 | Start all Runspace Worklflow. 30 | 31 | .LINK 32 | https://psframework.org/documentation/documents/psframework/runspace-workflows.html 33 | #> 34 | [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseShouldProcessForStateChangingFunctions", "")] 35 | [CmdletBinding()] 36 | param ( 37 | [Parameter(ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] 38 | [PsfArgumentCompleter('PSFramework-runspace-workflow-name')] 39 | [string[]] 40 | $Name, 41 | 42 | [Parameter(ValueFromPipeline = $true)] 43 | [PSFramework.Runspace.RSWorkflow[]] 44 | $InputObject, 45 | 46 | [switch] 47 | $PassThru 48 | ) 49 | process { 50 | $resolvedWorkflows = Resolve-PsfRunspaceWorkflow -Name $Name -InputObject $InputObject -Cmdlet $PSCmdlet 51 | 52 | foreach ($resolvedWorkflow in $resolvedWorkflows) { 53 | $resolvedWorkflow.Start() 54 | if ($PassThru) { $resolvedWorkflow } 55 | } 56 | } 57 | } -------------------------------------------------------------------------------- /library/PSFramework/Runspace/RSWorkflowRunespaceReport.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Management.Automation.Runspaces; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace PSFramework.Runspace 9 | { 10 | /// 11 | /// Information for a specific runspace of a worker. 12 | /// 13 | public class RSWorkflowRunespaceReport 14 | { 15 | /// 16 | /// The overall workflow this belongs to 17 | /// 18 | public readonly RSWorkflow Workflow; 19 | /// 20 | /// The worker that manages the runspace 21 | /// 22 | public readonly RSWorker Worker; 23 | /// 24 | /// ID of the runspace 25 | /// 26 | public int Id => Runspace.Id; 27 | /// 28 | /// Current state of the runspace. Should always be busy until the worker closes down. 29 | /// 30 | public RunspaceAvailability State => Runspace.RunspaceAvailability; 31 | /// 32 | /// Name of the runspace. Should be "PSF-<workflow>-<worker>-<index> 33 | /// 34 | public string Name => Runspace.Name; 35 | /// 36 | /// PowerShell runspace executing the actual code of the worker 37 | /// 38 | public readonly System.Management.Automation.Runspaces.Runspace Runspace; 39 | 40 | internal RSWorkflowRunespaceReport(RSWorkflow workflow, RSWorker worker, System.Management.Automation.Runspaces.Runspace runspace) 41 | { 42 | Workflow = workflow; 43 | Worker = worker; 44 | Runspace = runspace; 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /PSFramework/en-us/stringsLogging.psd1: -------------------------------------------------------------------------------- 1 | @{ 2 | 'Add-PSFLoggingProviderRunspace.Instance.NotFound' = 'Unable to find logging provider instance {1} of provider {0}' # $ProviderName, $InstanceName 3 | 4 | 'Import-PSFLoggingProvider.Import.Error' = "Error loading json data from {0}" # $effectivePath 5 | 'Import-PSFLoggingProvider.Datum.Error' = "Error processing logging provider entry" # 6 | 7 | 'Install-PSFLoggingProvider.Provider.NotFound' = "Provider {0} not found!" # $Name 8 | 'Install-PSFLoggingProvider.Installation.Error' = "Failed to install provider '{0}'" # $Name 9 | 10 | 'Register-PSFLoggingProvider.RegistrationEvent.Failed' = "Failed to register logging provider '{0}' - Registration event failed." # $Name 11 | 'Register-PSFLoggingProvider.Installation.Failed' = "Failed to install logging provider '{0}'" # $Name 12 | 'Register-PSFLoggingProvider.NotInstalled.Termination' = "Failed to enable logging provider {0} on registration! It was not recognized as installed. Consider running 'Install-PSFLoggingProvider' to properly install the prerequisites." # $Name 13 | 14 | 'Register-PSFMessageColorTransform.Level.Invalid' = 'Invalid level for a message color rule: {0}! The levels "Warning" and "Error" cannot be selected as warning messages cannot be colored.' # $Level 15 | 16 | 'Set-PSFLoggingProvider.Provider.NotFound' = 'Provider {0} not found!' # $Name 17 | 'Set-PSFLoggingProvider.Provider.V1NoInstance' = 'The Provider {0} is a first generation logging provider and does not support instances!' # $Name 18 | 'Set-PSFLoggingProvider.Provider.NotInstalled' = 'Provider {0} not installed! Run "Install-PSFLoggingProvider" first' # $Name 19 | 'Set-PSFLoggingProvider.Wait.Timeout' = 'Timeout waiting for {0} > {1} to be created. Logs may not be written as expected!' # $Name, $InstanceName 20 | } -------------------------------------------------------------------------------- /library/PSFramework/Feature/FeatureItem.cs: -------------------------------------------------------------------------------- 1 | namespace PSFramework.Feature 2 | { 3 | /// 4 | /// Represents a feature a module offers 5 | /// 6 | public class FeatureItem 7 | { 8 | /// 9 | /// The name of the feature 10 | /// 11 | public string Name; 12 | 13 | /// 14 | /// The owning module 15 | /// 16 | public string Owner; 17 | 18 | /// 19 | /// Whether the feature can be set globally 20 | /// 21 | public bool Global; 22 | 23 | /// 24 | /// Whether the feature can be overridden on a per module bases. 25 | /// 26 | public bool ModuleSpecific; 27 | 28 | /// 29 | /// The general description of the feature for human consumption 30 | /// 31 | public string Description; 32 | 33 | /// 34 | /// Creates an empty feature 35 | /// 36 | public FeatureItem() 37 | { 38 | 39 | } 40 | 41 | /// 42 | /// Creates a feature all fileld out. 43 | /// 44 | /// 45 | /// 46 | /// 47 | /// 48 | /// 49 | public FeatureItem(string Name, string Owner, bool Global, bool ModuleSpecific, string Description) 50 | { 51 | this.Name = Name; 52 | this.Owner = Owner; 53 | this.Global = Global; 54 | this.ModuleSpecific = ModuleSpecific; 55 | this.Description = Description; 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /PSFramework/functions/license/Remove-PSFLicense.ps1: -------------------------------------------------------------------------------- 1 | function Remove-PSFLicense 2 | { 3 | <# 4 | .SYNOPSIS 5 | Removes a registered license from the license store 6 | 7 | .DESCRIPTION 8 | Removes a registered license from the license store 9 | 10 | .PARAMETER License 11 | The license to remove 12 | 13 | .PARAMETER EnableException 14 | This parameters disables user-friendly warnings and enables the throwing of exceptions. 15 | This is less user friendly, but allows catching exceptions in calling scripts. 16 | 17 | .PARAMETER Confirm 18 | If this switch is enabled, you will be prompted for confirmation before executing any operations that change state. 19 | 20 | .PARAMETER WhatIf 21 | If this switch is enabled, no actions are performed but informational messages will be displayed that explain what would happen if the command were to run. 22 | 23 | .EXAMPLE 24 | PS C:\> Get-PSFLicense "FooBar" | Remove-PSFLicense 25 | 26 | Removes the license for the product "FooBar" from the license store. 27 | #> 28 | [CmdletBinding(SupportsShouldProcess = $true, ConfirmImpact = 'Low', HelpUri = 'https://psframework.org/documentation/commands/PSFramework/Remove-PSFLicense')] 29 | Param ( 30 | [Parameter(Mandatory = $true, ValueFromPipeline = $true)] 31 | [PSFramework.License.License[]] 32 | $License, 33 | 34 | [switch] 35 | $EnableException 36 | ) 37 | 38 | Process 39 | { 40 | foreach ($licenseObject in $License) 41 | { 42 | if (Test-PSFShouldProcess -Action 'Remove License' -Target $licenseObject -PSCmdlet $PSCmdlet) 43 | { 44 | try { [PSFramework.License.LicenseHost]::Remove($licenseObject) } 45 | catch 46 | { 47 | Stop-PSFFunction -Message "Failed to remove license" -ErrorRecord $_ -EnableException $EnableException -Target $licenseObject -Continue 48 | } 49 | } 50 | } 51 | } 52 | } 53 | --------------------------------------------------------------------------------