To install the PlasterTemplates module use the following command.
Install-Module -Name PlasterTemplates
To get help use the following command.
Get-Help about_PlasterTemplates
PowerShellModule – create a new PowerShell module with Visual Studio Code, Pester, and Azure Pipelines support.
Use the following command to create a new module with a PowerShellModule template.
Invoke-Plaster -TemplatePath 'C:\Program Files\PowerShell\Modules\PlasterTemplates\Templates\PowerShellModule' -DestinationPath c:\PlasterCreatedModule\ -ModuleName PlasterCreatedModule -Description "Module created by Plaster" -Version 1.0 -Options VSCode, Pester, AzurePipelines, Helpers
The TemplatePath parameter value depends on the folder the PlasterTemplates module was installed into.
To list templates available on the machine invoke the following cmdlet from Plaster module.
Get-PlasterTemplate -IncludeInstalledModules
sthArgumentCompleter – is a module that allows you to manage argument completers registered by Register-ArgumentCompleter cmdlet.
It contains following functions:
Get-CustomArgumentCompleter – Gets registered custom argument completers.
Get-NativeArgumentCompleter – Gets registered native argument completers.
Get-CustomArgumentCompleterScriptBlock – Gets scriptblock of the registered custom argument completer.
Get-NativeArgumentCompleterScriptBlock – Gets scriptblock of the registered native argument completer.
Remove-CustomArgumentCompleter – Removes specified registered custom argument completers.
Remove-NativeArgumentCompleter – Removes specified registered native argument completers.
Clear-CustomArgumentCompleters – Clears all of the registered custom argument completers.
Clear-NativeArgumentCompleters – Clears all of the registered native argument completers.
You can install sthArgumentCompleter module from PowerShell Gallery:
Install-Module sthArgumentCompleter
Also, you can find it on GitHub:
https://github.com/sethvs/sthArgumentCompleter
Example 1: Get all custom argument completers
The command gets all custom argument completers registered in the current session.
Get-CustomArgumentCompleter
CommandName ParameterName ScriptBlock
----------- ------------- -----------
Get-Something Name …
Do-Something Action …
SomeParameter …
Example 2: Get specified custom argument completers
The command gets specified custom argument completer.
Get-CustomArgumentCompleter -Name Get-Something:Name CommandName ParameterName ScriptBlock ----------- ------------- ----------- Get-Something Name …
Example 3: Get custom argument completers and expand scriptblocks
The command gets specified custom argument completer and expands its scriptblock.
Get-CustomArgumentCompleter -Name Get-Something:Name -ExpandScriptBlocks
CommandName ParameterName ScriptBlock
----------- ------------- -----------
Get-Something Name
$names = 'NameOne', 'NameTwo', 'NameThree'
foreach ($name in $names)
{
if ($name -like "$wordToComplete*")
{
[System.Management.Automation.CompletionResult]::new($name)
}
}
Example 1: Get all native argument completers
The command gets all native argument completers registered in the current session.
Get-NativeArgumentCompleter CommandName ScriptBlock ----------- ----------- somecommand … anothercommand …
Example 2: Get specified native argument completers
The command gets specified native argument completer.
Get-NativeArgumentCompleter -Name somecommand CommandName ScriptBlock ----------- ----------- somecommand …
Example 3: Get native argument completers and expand scriptblocks
The command gets specified native argument completer and expands its scriptblock.
Get-NativeArgumentCompleter -Name somecommand -ExpandScriptBlocks
CommandName ScriptBlock
----------- -----------
somecommand
$arguments = 'ArgumentOne', 'ArgumentTwo', 'ArgumentThree'
foreach ($argument in $arguments)
{
if ($argument -like "$wordToComplete*")
{
[System.Management.Automation.CompletionResult]::new($argument)
}
}
Example 1: Get scriptblock of the specified custom argument completer
The command gets scriptblock of the specified custom argument completer.
Get-CustomArgumentCompleterScriptBlock -Name Get-Something:Name
$names = 'NameOne', 'NameTwo', 'NameThree'
foreach ($name in $names)
{
if ($name -like "$wordToComplete*")
{
[System.Management.Automation.CompletionResult]::new($name)
}
}
Example 2: Get scriptblock of custom argument completer using the pipeline
The command gets scriptblock of the custom argument completer sent through the pipeline.
Get-CustomArgumentCompleter -Name Do-Something:Action | Get-CustomArgumentCompleterScriptBlock
$actions = 'ActionOne', 'ActionTwo'
foreach ($action in $actions)
{
if ($action -like "$wordToComplete*")
{
[System.Management.Automation.CompletionResult]::new($action)
}
}
Example 1: Get scriptblock of the specified native argument completer
The command gets scriptblock of the specified native argument completer.
Get-NativeArgumentCompleterScriptBlock -Name somecommand
$arguments = 'ArgumentOne', 'ArgumentTwo', 'ArgumentThree'
foreach ($argument in $arguments)
{
if ($argument -like "$wordToComplete*")
{
[System.Management.Automation.CompletionResult]::new($argument)
}
}
Example 2: Get scriptblock of native argument completer using the pipeline
The command gets scriptblock of the native argument completer sent through the pipeline.
Get-NativeArgumentCompleter -Name anothercommand | Get-NativeArgumentCompleterScriptBlock
$arguments = 'ArgumentOne', 'ArgumentTwo'
foreach ($argument in $arguments)
{
if ($argument -like "$wordToComplete*")
{
[System.Management.Automation.CompletionResult]::new($argument)
}
}
Example 1: Remove specified custom argument completer
The command removes specified custom argument completer.
Remove-CustomArgumentCompleter -Name Get-Something:Name
Example 2: Remove custom argument completer using the pipeline
The command removes custom argument completer sent through the pipeline.
Get-CustomArgumentCompleter -Name Do-Something:Action | Remove-CustomArgumentCompleter
Example 1: Remove specified native argument completer
The command removes specified native argument completer.
Remove-NativeArgumentCompleter -Name somecommand
Example 2: Remove native argument completer using the pipeline
The command removes native argument completer sent through the pipeline.
Get-NativeArgumentCompleter -Name anothercommand | Remove-NativeArgumentCompleter
Example 1: Clear all of the registered custom argument completers
The command clears all of the registered custom argument completers.
Clear-CustomArgumentCompleters
Example 1: Clear all of the registered native argument completers
The command clears all of the registered native argument completers.
Clear-NativeArgumentCompleters
More PowerShell modules at:
https://sergeyvasin.com/modules/
Links:
GitHub: https://github.com/sethvs
Twitter: https://twitter.com/vsseth
Facebook: https://fb.com/inpowershell
VK: https://vk.com/inpowershell
It contains following functions:
Function Enter-sthCulture – enters specified culture ‘scope’.
Function Invoke-sthUsingCulture invokes command using specified culture.
Function Set-sthCulture – sets specified culture for the current session.
Function Reset-sthCulture – resets culture for the current session to its original value.
You can install sthInvokeUsingCulture module from PowerShell Gallery:
Install-Module sthInvokeUsingCulture
Also, you can find it on GitHub:
https://github.com/sethvs/sthInvokeUsingCulture
Example 1: Enter the specified culture ‘scope’
The commands enter the specified culture ‘scope’ and invoke a command.
The first command enters the de-DE culture ‘scope’.
The second command uses -f operator to format the number.
The third command exits the de-DE culture ‘scope’.
PS C:\> Enter-sthCulture -Culture de-DE
[de-DE] PS C:\>> "{0:n}" -f 1234567890
1.234.567.890,00
[de-DE] PS C:\>> exit
PS C:\>
Example 1: Invoke command using specified culture
The command invokes the scriptblock using culture de-DE.
Invoke-sthUsingCulture -Culture de-DE -ScriptBlock {"{0:n}" -f 1234567890}
1.234.567.890,00
Example 2: Invoke Get-Help command using specified culture
The command invokes the Get-Help command for the Enter-sthCulture function using culture ru-RU.
Invoke-sthUsingCulture -Culture ru-ru -ScriptBlock { Get-Help Enter-sthCulture }
NAME
Enter-sthCulture
SYNOPSIS
Входит в 'область' указанных региональных настроек.
...
If you have already invoked the Get-Help command for the function using default culture, and now the result of the aforementioned command still uses that default culture, just re-import the module, which contain the command you are getting help for, like this: Import-Module sthInvokeUsingCulture and invoke the command again.
Example 1: Change the current culture
The first command sets culture to de-DE for the current session.
The second command uses -f operator to format the number.
Set-sthCulture -Culture de-DE
"{0:n}" -f 1234567890
1.234.567.890,00
Example 1: Reset culture to its original value
The first command gets current culture. It is en-US.
The second command changes culture to fr-FR for the current session.
The third command gets current culture. Now it is fr-FR.
The fourth command resets culture.
The fifth command gets current culture. Now it is en-US again.
LCID Name DisplayName ---- ---- ----------- 1033 en-US English (United States) Set-sthCulture -Culture fr-FR Get-Culture LCID Name DisplayName ---- ---- ----------- 1036 fr-FR French (France) Reset-sthCulture Get-Culture LCID Name DisplayName ---- ---- ----------- 1033 en-US English (United States)
More PowerShell modules at:
https://sergeyvasin.com/modules/
Links:
GitHub: https://github.com/sethvs
Twitter: https://twitter.com/vsseth
Facebook: https://fb.com/inpowershell
VK: https://vk.com/inpowershell
Get-sthVault – Function gets existing vaults or displays content of the specified vault.
New-sthVault – Function creates the vault with the properties specified.
Set-sthVaultProperty – Function adds new properties or changes values of the existing properties in the vault.
Remove-sthVaultProperty – Function removes specified properties from the vault.
Remove-sthVault – Function removes the vault specified.
Vault is an .xml file, containing Name-Value pairs.
The vaults can be useful when you need to store some values, be it in the plain text form, SecureStrings or PSCredential object and then use them in automation scripts and workflows.
You can create the vault by using the New-sthVault function with the -VaultName or -VaultFilePath parameter.
-VaultName parameter creates an .xml file with the specified name under the Vaults folder in the module’s directory.
-VaultFilePath parameters accepts path and name of the file, i.e. C:\Folder\file.xml, and creates it in the specified location.
Values can be of three types: PlainText, SecureString, and Credential.
You can use the -PlainText, -SecureString, and -Credential parameters to specify needed vaules.
Each of these parameters accepts HashTable as an argument, which contains the Name-Value pairs.
For example:
$PlainText = @{PlainTextOne = 'One'; PlainTextTwo = 'Two'}
$SecureStringOne = ConvertTo-SecureString -String 'One' -AsPlainText -Force
$SecureString = @{SecureStringOne = $SecureStringOne; SecureStringTwo = 'Two'}
$CredentialOne = New-Object System.Management.Automation.PSCredential -ArgumentList 'One', $(ConvertTo-SecureString -String 'OnePassword' -AsPlainText -Force)
$Credential = @{CredentialOne = $CredentialOne; CredentialTwo = 'Two', 'TwoPassword'}
New-sthVault -VaultName TheVault -PlainText $PlainText -SecureString $SecureString -Credential $Credential
You can get the vault’s content by using the Get-sthVault function.
For example:
$Settings = Get-sthVault -VaultName TheVault
Then you can use it in automation scripts and workflows.
For example:
Get-SomeInfo -UserName $Settings.PlainTextOne -PasswordAsSecureString $Settings.SecureStringOne ConnectTo-Something -Credential $Settings.CredentialOne Get-SomeData -Credential $Settings.CredentialTwo
SecureString and PSCredential objects use DPAPI, which means that the vault, containing SecureStrings or PSCredentials can only be used on the computer it was created on, and under the user account, that created it.
You can install sthVault module from PowerShell Gallery:
Install-Module sthVault
Example 1: Get vault list
This command returns previously created vault’s names from the Vaults folder in the module’s directory.
Get-sthVault SomeVault AnotherVault
Example 2: Get vault content
This command returns data from the previously created vault named TheVault, which contains two plaintext values – PlainTextOne and PlainTextTwo, two SecureString values – SecureStringOne and SecureStringTwo, and two Credential values – CredentialOne and CredentialTwo.
Get-sthVault -VaultName TheVault Name Value ---- ----- PlainTextOne One PlainTextTwo Two SecureStringOne System.Security.SecureString SecureStringTwo System.Security.SecureString CredentialOne System.Management.Automation.PSCredential CredentialTwo System.Management.Automation.PSCredential
Example 3: Get vault content and show encrypted data
This command returns data from the previously created vault named TheVault, showing encrypted values like SecureStrings and Credentials in plain text.
Get-sthVault -VaultName TheVault -ShowSecureData
Name Value
---- -----
PlainTextOne One
PlainTextTwo Two
SecureStringOne One
SecureStringTwo Two
CredentialOne {One, OnePassword}
CredentialTwo {Two, TwoPassword}
Example 4: Get vault content from the vault file in alternate location
This command returns data from the previously created vault file C:\Vaults\SomeVault.xml.
Get-sthVault -VaultFilePath C:\Vaults\SomeVault.xml Name Value ---- ----- PlainText SomeValue SecureString System.Security.SecureString Credential System.Management.Automation.PSCredential
Example 5: Get vault properties of specified type only
This command returns data from the previously created vault named TheVault, showing only properties with PlainText and SecureString values.
Get-sthVault -VaultName TheVault -PropertyType PlainText, SecureString Name Value ---- ----- PlainTextOne One PlainTextTwo Two SecureStringOne System.Security.SecureString SecureStringTwo System.Security.SecureString
Example 6: Get vault properties with specified names only
This command returns data from the previously created vault named TheVault, showing only PlainTextOne and SecureStringTwo properties.
Get-sthVault -VaultName TheVault -PropertyName PlainTextOne, SecureStringTwo Name Value ---- ----- PlainTextOne One SecureStringTwo System.Security.SecureString
Example 7: Get vault properties with specified names using wildcards
This command returns data from the previously created vault named TheVault, showing only properties which names end with One.
Get-sthVault -VaultName $VaultName -PropertyName *One Name Value ---- ----- PlainTextOne One SecureStringOne System.Security.SecureString CredentialOne System.Management.Automation.PSCredential
Example 1: Create the vault
This command creates the vault with the name TheVault, which contains two plaintext values - PlainTextOne and PlainTextTwo, two SecureString values - SecureStringOne and SecureStringTwo, and two Credential values - CredentialOne and CredentialTwo.
The vault is created under the Vaults folder in the module's directory.
$PlainText = @{PlainTextOne = 'One'; PlainTextTwo = 'Two'}
$SecureStringOne = ConvertTo-SecureString -String 'One' -AsPlainText -Force
$SecureString = @{SecureStringOne = $SecureStringOne; SecureStringTwo = 'Two'}
$CredentialOne = New-Object System.Management.Automation.PSCredential -ArgumentList 'One', $(ConvertTo-SecureString -String 'OnePassword' -AsPlainText -Force)
$Credential = @{CredentialOne = $CredentialOne; CredentialTwo = 'Two','TwoPassword'}
New-sthVault -VaultName TheVault -PlainText $PlainText -SecureString $Securestring -Credential $Credential
Example 2: Create the vault file at the specified path
This command creates the vault file with the name SomeVault.xml in the C:\Vaults directory.
$PlainText = @{PlainTextOne = 'One'; PlainTextTwo = 'Two'}
$SecureStringOne = ConvertTo-SecureString -String 'One' -AsPlainText -Force
$SecureString = @{SecureStringOne = $SecureStringOne; SecureStringTwo = 'Two'}
$CredentialOne = New-Object System.Management.Automation.PSCredential -ArgumentList 'One', $(ConvertTo-SecureString -String 'OnePassword' -AsPlainText -Force)
$Credential = @{CredentialOne = $CredentialOne; CredentialTwo = 'Two','TwoPassword'}
New-sthVault -VaultFilePath C:\Vaults\SomeVault.xml -PlainText $PlainText -SecureString $Securestring -Credential $Credential
Example 1: Change several properties and add new ones to the vault
This command changes PlainTextOne, SecureStringOne, and CredentialOne properties and adds PlainTextThree, SecureStringThree, and CredentialThree properties to the vault.
$PlainText = @{PlainTextOne = '1'; PlainTextThree = 'Three'}
$SecureStringOne = ConvertTo-SecureString -String '1' -AsPlainText -Force
$SecureString = @{SecureStringOne = $SecureStringOne; SecureStringThree = 'Three'}
$CredentialOne = New-Object System.Management.Automation.PSCredential -ArgumentList '1', $(ConvertTo-SecureString -String '1' -AsPlainText -Force)
$Credential = @{CredentialOne = $CredentialOne; CredentialThree = 'Three', 'ThreePassword'}
Set-sthVaultProperty -VaultName TheVault -PlainText $PlainText -SecureString $Securestring -Credential $Credential
Get-sthVault -VaultName TheVault -ShowSecureData
Name Value
---- -----
PlainTextOne 1
PlainTextThree Three
PlainTextTwo Two
SecureStringOne 1
SecureStringThree Three
SecureStringTwo Two
CredentialOne {1, 1}
CredentialThree {Three, ThreePassword}
CredentialTwo {Two, TwoPassword}
Example 2: Change several properties and add new ones to the vault file at the path specified
This command changes PlainTextOne, SecureStringOne, and CredentialOne properties and adds PlainTextThree, SecureStringThree, and CredentialThree properties to the vault file with the name SomeVault.xml in the C:\Vaults directory.
$PlainText = @{PlainTextOne = '1'; PlainTextThree = 'Three'}
$SecureStringOne = ConvertTo-SecureString -String '1' -AsPlainText -Force
$SecureString = @{SecureStringOne = $SecureStringOne; SecureStringThree = 'Three'}
$CredentialOne = New-Object System.Management.Automation.PSCredential -ArgumentList '1', $(ConvertTo-SecureString -String '1' -AsPlainText -Force)
$Credential = @{CredentialOne = $CredentialOne; CredentialThree = 'Three', 'ThreePassword'}
Set-sthVaultProperty -VaultFilePath C:\Vaults\SomeVault.xml -PlainText $PlainText -SecureString $Securestring -Credential $Credential
Get-sthVault -VaultFilePath C:\Vaults\SomeVault.xml -ShowSecureData
Name Value
---- -----
PlainTextOne 1
PlainTextThree Three
PlainTextTwo Two
SecureStringOne 1
SecureStringThree Three
SecureStringTwo Two
CredentialOne {1, 1}
CredentialThree {Three, ThreePassword}
CredentialTwo {Two, TwoPassword}
Example 1: Remove properties from the vault
This command removes the PropertyOne and PropertyTwo properties from the vault TheVault located under the Vaults folder in the module's directory.
Remove-sthVaultProperty -VaultName TheVault -PropertyName PropertyOne, PropertyTwo
Example 2: Remove properties from the vault file at the path specified
This command removes the PropertyOne and PropertyTwo properties from the vault file with the name SomeVault.xml in the C:\Vaults directory.
Remove-sthVaultProperty -VaultFilePath C:\Vaults\SomeVault.xml -PropertyName PropertyOne, PropertyTwo
Example 1: Remove the vault
This command removes the vault with the specified name from the Vaults folder in the module's directory.
Remove-sthVault -VaultName TheVault
Example 2: Remove the vault file at the specified path
This command removes the vault file with the name SomeVault.xml in the C:\Vaults directory.
Remove-sthVault -VaultFilePath C:\Vaults\SomeVault.xml
More PowerShell modules at:
https://sergeyvasin.com/modules/
Links:
GitHub: https://github.com/sethvs
Twitter: https://twitter.com/vsseth
Facebook: https://fb.com/inpowershell
VK: https://vk.com/inpowershell
Function Send-sthMailMessage sends mail message using settings from the profile specified.
Function New-sthMailProfile creates mail profile containing specified settings.
Function Get-sthMailProfile gets existing mail profiles and displays their settings.
Function Remove-sthMailProfile removes specified profiles.
Profile is an xml file, containing settings, such as: From, To, Credential, SmtpServer, Port, UseSSL, Encoding, BodyAsHtml, CC, BCC, DeliveryNotificationOption, and Priority.
You can create the profile by using the New-sthMailProfile function with the -ProfileName or -ProfileFilePath parameter.
-ProfileName parameter creates an .xml file with the specified name under the Profiles folder in the module’s directory.
-ProfileFilePath parameter accepts path and name of the file, i.e. C:\Folder\file.xml, and creates it in the specified location.
You can install sthMailProfile module from PowerShell Gallery:
Install-Module sthMailProfile
Also, you can find it on GitHub:
https://github.com/sethvs/sthMailProfile
Example 1: Send mail message using previously created profile
The first command gets the result of the Get-Process cmdlet and assigns it to the $ps variable.
The second command sends it using previously created profile “MailProfile”.
$ps = Get-Process Send-sthMailMessage -ProfileName "MailProfile" -Subject "Process List" -Message $ps
Example 2: Send mail message using positional parameters
The first command gets the result of the Get-Process cmdlet and assigns it to the $ps variable.
The second command sends it using previously created profile “MailProfile”.
The command uses positional parameters.
$ps = Get-Process Send-sthMailMessage "MailProfile" "Process List" $ps
Example 3: Send mail message using profile file at the path specified
The first command gets the result of the Get-Process cmdlet and assigns it to the $ps variable.
The second command sends it using previously created profile file SomeProfile.xml located in the C:\Profiles directory.
$ps = Get-Process Send-sthMailMessage -ProfileFilePath C:\Profiles\SomeProfile.xml -Subject "Process List" -Message $ps
Example 4: Send mail message using pipeline and previously created profile
The command gets the result of the Get-Process cmdlet and sends it using previously created profile “MailProfile”.
It uses pipeline for sending message content to the function.
Get-Process | Send-sthMailMessage -ProfileName "MailProfile" -Subject "Process List"
Example 5: Send mail message with attachments using pipeline and previously created profile
The command gets the result of the Get-Process cmdlet and sends it with specified files as attachments using previously created profile “MailProfile”.
It uses pipeline for sending message content to the function.
Get-Process | Send-sthMailMessage -ProfileName "MailProfile" -Subject "Process List" -Attachments "file1.txt, file2.txt"
Example 1: Create a new profile
The command creates mail profile with name “MailProfile”, which contains settings: From, To and SmtpServer.
New-sthMailProfile -ProfileName "MailProfile" -From [email protected] -To [email protected] -SmtpServer smtp.domain.com
Example 2: Create a new profile using positional parameters
The command creates mail profile with name “MailProfile”, which contains settings: From, To and SmtpServer using positional parameters.
New-sthMailProfile "MailProfile" [email protected] [email protected] smtp.domain.com
Example 3: Create a new profile file at the specified path
The command creates the profile file with the name SomeProfile.xml in the C:\Profiles directory.
New-sthMailProfile -ProfileFilePath "C:\Profiles\SomeProfile.xml" -From [email protected] -To [email protected] -SmtpServer smtp.domain.com
Example 4: Create a new profile using additional parameters
The command creates mail profile with name “SendEmpty” and settings: From, To, SmtpServer, Subject, Port, UseSSL, Encoding, BodyAsHtml, CC, BCC, DeliveryNotificationOption, and Priority.
New-sthMailProfile -ProfileName "MailProfile" -From [email protected] -To [email protected] -SmtpServer smtp.domain.com -Subject "TheSubject" -Port 587 -UseSSL -Encoding UTF-8 -BodyAsHtml -CC [email protected] -BCC [email protected] -DeliveryNotificationOption OnSuccess -Priority High
Example 5: Create a new profile with credential
The command creates mail profile with name “MailProfile” and settings: From, To, SmtpServer, UserName and Password.
The -Password parameter is not used, so the command requests for it.
New-sthMailProfile -ProfileName "MailProfile" -From [email protected] -To [email protected] -SmtpServer smtp.domain.com -UserName [email protected] Type the password:
Since SecureString uses DPAPI, if you create mail profile containing credential without -StorePasswordInPlainText parameter, it can only be used on the computer it was created on and by the user account that created it.
Example 6: Create a new profile by specifying the password as string
The command creates mail profile with name “MailProfile” and settings: From, To, SmtpServer, UserName and Password.
Password is specified as string.
New-sthMailProfile -ProfileName "MailProfile" -From [email protected] -To [email protected] -SmtpServer smtp.domain.com -UserName [email protected] -Password 'password'
Since SecureString uses DPAPI, if you create mail profile containing credential without -StorePasswordInPlainText parameter, it can only be used on the computer it was created on and by the user account that created it.
Example 7: Create a new profile with credential by specifying password as secure string
The first command creates secure string from plain text password and assigns it to the $Password variable.
The second command creates mail profile with name “MailProfile” and settings: From, To, SmtpServer, UserName and Password.
Password is specified as secure string.
$Password = ConvertTo-SecureString -String 'password' -AsPlainText -Force New-sthMailProfile -ProfileName "MailProfile" -From [email protected] -To [email protected] -SmtpServer smtp.domain.com -UserName [email protected] -Password $Password
Since SecureString uses DPAPI, if you create mail profile containing credential without -StorePasswordInPlainText parameter, it can only be used on the computer it was created on and by the user account that created it.
Example 8: Create a new profile by specifying credential as PSCredential object
The first command creates secure string from plain text password and assigns it to the $Password variable.
The second command creates PSCredential object using ‘UserName’ and previously created password as arguments.
The third command creates mail profile with name “MailProfile” and settings: From, To, SmtpServer and Credential.
$Password = ConvertTo-SecureString -String 'password' -AsPlainText -Force $Credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList 'UserName', $Password New-sthMailProfile -ProfileName "MailProfile" -From [email protected] -To [email protected] -SmtpServer smtp.domain.com -Credential $Credential
Since SecureString uses DPAPI, if you create mail profile containing credential without -StorePasswordInPlainText parameter, it can only be used on the computer it was created on and by the user account that created it.
Example 9: Create a new profile by specifying credential as an array of two elements
The command creates mail profile with name “MailProfile” and settings: From, To, SmtpServer and Credential.
Credential parameter value is specified as an array of two elements.
New-sthMailProfile -ProfileName "MailProfile" -From [email protected] -To [email protected] -SmtpServer smtp.domain.com -Credential @('UserName', 'password')
Since SecureString uses DPAPI, if you create mail profile containing credential without -StorePasswordInPlainText parameter, it can only be used on the computer it was created on and by the user account that created it.
Example 10: Create a new profile and store password in plain text
The command creates mail profile with name “MailProfile” and settings: From, To, SmtpServer, UserName and Password.
Since the -StorePasswordInPlainText parameter is used, password will be stored in plain text.
It allows you to use the profile on computers other than one it was created on, and under different user accounts, other than it was created by.
New-sthMailProfile -ProfileName "MailProfile" -From [email protected] -To [email protected] -SmtpServer smtp.domain.com -UserName [email protected] -Password 'password' -StorePasswordInPlainText
Example 11: Create a new profile with subject
The first command creates mail profile with name “MailProfile” and settings: From, To, SmtpServer, and Subject.
The second command sends mail message using subject from the profile.
The third command sends mail message using subject defined by the Send-sthMailMessage -Subject parameter.
New-sthMailProfile -ProfileName "MailProfile" -From [email protected] -To [email protected] -SmtpServer smtp.domain.com -Subject "TheSubject" Send-sthMailMessage -ProfileName "MailProfile" -Message "TheMessage" Send-sthMailMessage -ProfileName "MailProfile" -Subject "AnotherSubject" -Message "TheMessage"
Example 12: Create a new profile with -DoNotSendIfMessageIsEmpty parameter
The first command creates mail profile with name “SendEmpty” and settings: From, To, and SmtpServer.
The second command creates mail profile with name “NoNotSendEmpty” and settings: From, To, SmtpServer, and DoNotSendIfMessageIsEmpty.
The third command tries to send mail message with empty body. The message will be sent.
The fourth command tries to send mail message with empty body. The message will not be sent.
New-sthMailProfile -ProfileName "SendEmpty" -From [email protected] -To [email protected] -SmtpServer smtp.domain.com New-sthMailProfile -ProfileName "DoNotSendEmpty" -From [email protected] -To [email protected] -SmtpServer smtp.domain.com -DoNotSendIfMessageIsEmpty '' | Send-sthMailMessage -ProfileName "SendEmpty" -Subject "TheSubject" '' | Send-sthMailMessage -ProfileName "DoNotSendEmpty" -Subject "TheSubject"
Example 1: Get all profiles
The command gets all profiles and displays their settings.
Get-sthMailProfile
ProfileName : MailProfile
From : [email protected]
To : {[email protected]}
PasswordIs : NotExist
SmtpServer : smtp.domain.com
ProfileName : MailProfile2
From : [email protected]
To : {[email protected]}
UserName : [email protected]
PasswordIs : PlainText
SmtpServer : smtp.domain.com
ProfileName : MailProfile3
From : [email protected]
To : {[email protected]}
UserName : [email protected]
PasswordIs : Secured
SmtpServer : smtp.domain.com
Example 2: Get profile by name
The command gets profile “MailProfile” and displays its settings.
Get-sthMailProfile MailProfile
ProfileName : MailProfile
From : [email protected]
To : {[email protected]}
PasswordIs : NotExist
SmtpServer : smtp.domain.com
Example 3: Get profiles by using wildcards
The command gets profiles which name starts with “Mail” and displays their settings.
Get-sthMailProfile -ProfileName Mail*
ProfileName : MailProfile
From : [email protected]
To : {[email protected]}
PasswordIs : NotExist
SmtpServer : smtp.domain.com
ProfileName : MailProfile2
From : [email protected]
To : {[email protected]}
UserName : [email protected]
PasswordIs : PlainText
SmtpServer : smtp.domain.com
ProfileName : MailProfile3
From : [email protected]
To : {[email protected]}
UserName : [email protected]
PasswordIs : Secured
SmtpServer : smtp.domain.com
Example 4: Get profile content from the profile file in alternate location
The command gets settings from the profile file located at C:\Profiles\SomeProfile.xml.
Get-sthMailProfile -ProfileFilePath C:\Profiles\SomeProfile.xml
ProfileName : SomeProfile
From : [email protected]
To : {[email protected]}
PasswordIs : NotExist
SmtpServer : smtp.domain.com
Example 5: Get profiles and display their settings including password
The command gets all profiles and displays their settings including password.
Get-sthMailProfile -ShowPassword
ProfileName : MailProfile
From : [email protected]
To : {[email protected]}
PasswordIs : NotExist
SmtpServer : smtp.domain.com
ProfileName : MailProfile2
From : [email protected]
To : {[email protected]}
UserName : [email protected]
Password : password
PasswordIs : PlainText
SmtpServer : smtp.domain.com
ProfileName : MailProfile3
From : [email protected]
To : {[email protected]}
UserName : [email protected]
Password : password
PasswordIs : Secured
SmtpServer : smtp.domain.com
Example 1: Remove a profile
The command removes the profile “MailProfile”.
Remove-sthMailProfile -ProfileName "MailProfile"
Example 2: Remove profiles by using wildcards
The command removes the profiles which name starts with “Mail”.
Remove-sthMailProfile -ProfileName "Mail*"
Example 3: Remove all profiles
The command removes all profiles.
Remove-sthMailProfile -ProfileName *
Example 4: Remove profiles file at the specified path
The command removes the profile file with the name SomeProfile.xml in the C:\Profiles directory.
Remove-sthMailProfile -ProfileFilePath C:\Profiles\SomeProfile.xml
More PowerShell modules at:
https://sergeyvasin.com/modules/
Links:
GitHub: https://github.com/sethvs
Twitter: https://twitter.com/vsseth
Facebook: https://fb.com/inpowershell
VK: https://vk.com/inpowershell
Function Enter-sthModuleScope allows entering the scope of a specified module and invoking command in that scope. This provides means to call internal module functions and access nonexported module variables. When you enter a module scope, command prompt changes to include the name of the module. To exit from the module scope type ‘exit’.
Function Get-sthModuleScopeFunction returns all the functions, defined in the module specified by -Module parameter, or the module, the scope of which was entered by using the Enter-sthModuleScope function. By default, Get-sthModuleScopeFunction gets all functions – public and private, but you can specify which functions you are interested in by using -PublicOnly and -PrivateOnly parameters.
Function Get-sthModuleScopeVariable returns all the variables, defined in the module specified by -Module parameter, or the module, the scope of which was entered by using the Enter-sthModuleScope function. Like the former function, Get-sthModuleScopeVariable by default gets all variables – public and private, but you can specify which variables you are interested in by using -PublicOnly and -PrivateOnly parameters.
Function Get-sthScopeDepth returns current scope depth, where 0 means, that you are in the global scope, 1 – you are one scope deeper than global, 2 – you are two scopes deeper than global, etc.
You can install sthModuleScope module from PowerShell Gallery:
Install-Module sthModuleScope
Also, you can find it on GitHub:
https://github.com/sethvs/sthModuleScope
But how to use it?
This command enters the scope of the module.
When enter, the command prompt changes to include the name of the module.
After that, the ‘exit’ command issued to exit the module’s scope.
PS C:\> Enter-sthModuleScope -Module module_name [module_name] PS C:\>> exit PS C:\>
These commands enter the scope of the module using PSModuleInfo object.
The first command uses the Get-Module cmdlet to get PSModuleInfo object for the module ‘module_name’.
The second command enters the scope of the module ‘module_name’.
The third command exits the module’s scope.
PS C:\> $Module = Get-Module -Name 'module_name' -ListAvailable PS C:\> Enter-sthModuleScope -Module $Module [module_name] PS C:\>> exit PS C:\>
This command enters the scope of the module using pipeline.
PS C:\> 'module_name' | Enter-sthModuleScope [module_name] PS C:\>>
This command enters the scope of the module by sending PSModuleInfo object through the pipeline.
PS C:\> Get-Module module_name -ListAvailable | Enter-sthModuleScope [module_name] PS C:\>>
These commands get all functions, defined in the module ‘module_name’.
The first command enters the scope of the module ‘module_name’.
The second command gets all the module’s functions.
PS C:\> Enter-sthModuleScope -Module module_name [module_name] PS C:\>> Get-sthModuleScopeFunction
These commands get all public functions, defined in the module ‘module_name’.
The first command enters the scope of the module ‘module_name’.
The second command gets all the module’s public functions.
PS C:\> Enter-sthModuleScope -Module module_name [module_name] PS C:\>> Get-sthModuleScopeFunction -PublicOnly
These commands get all private functions, defined in the module ‘module_name’.
The first command enters the scope of the module ‘module_name’.
The second command gets all the module’s private functions.
PS C:\> Enter-sthModuleScope -Module module_name [module_name] PS C:\>> Get-sthModuleScopeFunction -PrivateOnly
This command gets all functions, defined in the module ‘module_name’.
PS C:\> Get-sthModuleScopeFunction -Module 'module_name'
These commands get all functions, defined in the module ‘module_name’ by using PSModuleInfo object.
PS C:\> $Module = Get-Module -Name 'module_info' -ListAvailable PS C:\> Get-sthModuleScopeFunction -Module $Module
This command gets all functions, defined in the module ‘module_name’ by using pipeline.
PS C:\> 'module_name' | Get-sthModuleScopeFunction
This command gets all functions, defined in the module ‘module_name’ by accepting PSModuleInfo object from the pipeline.
PS C:\> Get-Module -Name 'module_name' -ListAvailable | Get-sthModuleScopeFunction
These commands get all variables, defined in the module ‘module_name’.
The first command enters the scope of the module ‘module_name’.
The second command gets all the module’s variables.
PS C:\> Enter-sthModuleScope -Module module_name [module_name] PS C:\>> Get-sthModuleScopeVariable
These commands get all public variables, defined in the module ‘module_name’.
The first command enters the scope of the module ‘module_name’.
The second command gets all the module’s public variables.
PS C:\> Enter-sthModuleScope -Module module_name [module_name] PS C:\>> Get-sthModuleScopeVariable -PublicOnly
These commands get all private variables, defined in the module ‘module_name’.
The first command enters the scope of the module ‘module_name’.
The second command gets all the module’s private variables.
PS C:\> Enter-sthModuleScope -Module module_name [module_name] PS C:\>> Get-sthModuleScopeVariable -PrivateOnly
This command gets all variables, defined in the module ‘module_name’.
PS C:\> Get-sthModuleScopeVariable -Module 'module_name'
These commands get all variables, defined in the module ‘module_name’ by using PSModuleInfo object.
PS C:\> $Module = Get-Module -Name 'module_info' -ListAvailable PS C:\> Get-sthModuleScopeVariable -Module $Module
This command gets all variables, defined in the module ‘module_name’ by using pipeline.
PS C:\> 'module_name' | Get-sthModuleScopeVariable
This command gets all variables, defined in the module ‘module_name’ by accepting PSModuleInfo object from the pipeline.
PS C:\> Get-Module -Name 'module_name' -ListAvailable | Get-sthModuleScopeVariable
This command gets current scope depth.
The result is 0, which means – you are in the global scope.
PS C:\> Get-sthScopeDepth 0
These commands get current scope depth from the module’s scope.
The first command enters the scope of the module ‘module_name’.
The second command gets current scope depth.
The result is 1, which means – you are one scope deeper than the global scope.
PS C:\> Enter-sthModuleScope -Module module_name [module_name] PS C:\>> Get-sthScopeDepth 1
These commands get current module scope depth while debugging the Get-sthModuleScopeFunction function.
The first command enables script debugging.
The second command invokes the Get-sthModuleScopeFunction function with ‘sthModuleScope’ as the -Module parameter value.
Then, on the first debug request ‘Y’ is specified, which means continuing function execution.
On the second debug request ‘S’ is specified, which means suspending execution.
Then, at the debug prompt the Get-sthScopeDepth function invoked.
The result is 2, which means – you are two scopes deeper, than the global scope.
PS C:\> Set-PSDebug -Step
PS C:\> Get-sthModuleScopeFunction -Module sthModuleScope
Continue with this operation?
1+ >>>> Get-sthModuleScopeFunction -Module sthModuleScope
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "Y"): Y
Continue with this operation?
26+ >>>> {
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "Y"): S
PS C:\>> Get-sthScopeDepth
2
Links:
Twitter: https://twitter.com/vsseth
Facebook: https://fb.com/inpowershell
VK: https://vk.com/inpowershell
Russian version of the blog:
https://sergeyvasin.net
User account object’s attribute adminCount is set to ‘1’ and access rights become that of the AdminSDHolder container (CN=AdminSDHolder,CN=System,DC=domain,DC=com).
By default, access rights inheritance for AdminSDHolder is disabled. And so it is for protected user objects.
When you remove user from protected group, adminCount attribute is not removed and its value is not changed. Also, permissions inheritance for the object is not enabled.
To remove adminCount attribute and enable access rights inheritance you can use this module’s functions: Get-sthAdminSDHolderProtectedUserAccount and Remove-sthAdminSDHolderUserAccountProtection.
Also, you can exclude ‘Account Operators’, ‘Server Operators’, ‘Print Operators’ or ‘Backup Operators’ groups from protection (and include again) by adjusting dsHeuristics attribute of ‘Directory Service’ container (CN=Directory Service,CN=Windows NT,CN=Services,CN=Configuration,DC=domain,DC=com).
You can do this using functions: Get-sthAdminSDHolderGroup, Disable-sthAdminSDHolderGroupProtection, Enable-sthAdminSDHolderGroupProtection.
Get-sthAdminSDHolderProtectedUserAccount – Function gets Active Directory user accounts, protected by AdminSDHolder. It returns Name, SamAccountName, UserPrincipalName, whether account is enabled, adminCount attribute value, whether access rights inheritance is enabled and list of protected groups the user is member of.
Remove-sthAdminSDHolderUserAccountProtection – Function removes adminCount attribute and enables access rules inheritance for the user object, that no longer belongs to groups, protected by AdminSDHolder container.
Get-sthAdminSDHolderGroup – Function gets the Active Directory groups, protected by AdminSDHolder container. It returns dsHeuristics attribute value, protected groups, and also groups, excluded from protection, if any.
Disable-sthAdminSDHolderGroupProtection – Function disables protection by AdminSDHolder container for Account Operators, Server Operators, Print Operators or Backup Operators groups.
Enable-sthAdminSDHolderGroupProtection – Function enables protection by AdminSDHolder container for Account Operators, Server Operators, Print Operators or Backup Operators groups.
You can install sthAdminSDHolder module from PowerShell Gallery:
Install-Module sthAdminSDHolder
Also, you can find it on GitHub:
https://github.com/sethvs/sthAdminSDHolder
How to use it?
The command returns information about user accounts, protected by AdminSDHolder container. Output includes disabled user accounts.
Get-sthAdminSDHolderProtectedUserAccount
Name SamAccountName UserPrincipalName Enabled AdminCountAttribute InheritanceEnabled AdminSDHolderGroups
---- -------------- ----------------- ------- ------------------- ------------------ -------------------
admin admin [email protected] True 1 False {Administrators, Domain Admins, Enterprise Admins, Schema Admins}
user user [email protected] True 1 False {Account Operators}
disableduser disableduser [email protected] False 1 False {Print Operators}
The command returns information about user accounts, protected by AdminSDHolder container. Output includes only enabled user accounts.
Get-sthAdminSDHolderProtectedUserAccount -EnabledOnly
Name SamAccountName UserPrincipalName Enabled AdminCountAttribute InheritanceEnabled AdminSDHolderGroups
---- -------------- ----------------- ------- ------------------- ------------------ -------------------
admin admin [email protected] True 1 False {Administrators, Domain Admins, Enterprise Admins, Schema Admins}
user user [email protected] True 1 False {Account Operators}
The command returns information about user accounts, protected by AdminSDHolder container, using ambiguous name resolution.
Get-sthAdminSDHolderProtectedUserAccount -ANR u
Name SamAccountName UserPrincipalName Enabled AdminCountAttribute InheritanceEnabled AdminSDHolderGroups
---- -------------- ----------------- ------- ------------------- ------------------ -------------------
user user [email protected] True 1 False {Account Operators}
The command returns information about user account, protected by AdminSDHolder container, using SamAccountName user object attribute.
Get-sthAdminSDHolderProtectedUserAccount -SamAccountName user
Name SamAccountName UserPrincipalName Enabled AdminCountAttribute InheritanceEnabled AdminSDHolderGroups
---- -------------- ----------------- ------- ------------------- ------------------ -------------------
user user [email protected] True 1 False {Account Operators}
The command returns information about user account, protected by AdminSDHolder container, using UserPrincipalName user object attribute.
Get-sthAdminSDHolderProtectedUserAccount -UserPrincipalName [email protected]
Name SamAccountName UserPrincipalName Enabled AdminCountAttribute InheritanceEnabled AdminSDHolderGroups
---- -------------- ----------------- ------- ------------------- ------------------ -------------------
user user [email protected] True 1 False {Account Operators}
The command removes adminCount attribute and enables access rules inheritance for the user account. The account was specified by using its SamAccountName.
Remove-sthAdminSDHolderUserAccountProtection -SamAccountName user -Remove -YesRemove
Removing adminCount attribute and enabling access rules inheritance.
Name SamAccountName UserPrincipalName Enabled AdminCountAttribute InheritanceEnabled AdminSDHolderGroups
---- -------------- ----------------- ------- ------------------- ------------------ -------------------
user user [email protected] True 1 False {}
adminCount attribute removed.
Access rules inheritance enabled.
The command removes adminCount attribute and enables access rules inheritance for the user account. The account was specified by using its UserPrincipalName.
Remove-sthAdminSDHolderUserAccountProtection -UserPrincipalName [email protected] -Remove -YesRemove
Removing adminCount attribute and enabling access rules inheritance.
Name SamAccountName UserPrincipalName Enabled AdminCountAttribute InheritanceEnabled AdminSDHolderGroups
---- -------------- ----------------- ------- ------------------- ------------------ -------------------
user user [email protected] True 1 False {}
adminCount attribute removed.
Access rules inheritance enabled.
The command does not make changes to user account, because it still is a member of a protected group.
Remove-sthAdminSDHolderUserAccountProtection -SamAccountName username -Remove -YesRemove
Account is a member of AdminSDHolder protected groups.
Name SamAccountName UserPrincipalName Enabled AdminCountAttribute InheritanceEnabled AdminSDHolderGroups
---- -------------- ----------------- ------- ------------------- ------------------ -------------------
user user [email protected] True 1 False {Account Operators}
No changes were made.
The command gets the value of dsHeuristics attribute and a list of groups, protected by AdminSDHolder container.
Get-sthAdminSDHolderGroup
dsHeuristics: null
Protected Groups:
Name SID distinguishedName
---- --- -----------------
Account Operators S-1-5-32-548 CN=Account Operators,CN=Builtin,DC=domain,DC=com
Administrators S-1-5-32-544 CN=Administrators,CN=Builtin,DC=domain,DC=com
Backup Operators S-1-5-32-551 CN=Backup Operators,CN=Builtin,DC=domain,DC=com
Domain Admins S-1-5-21-1234567890-1234567890-1234567890-512 CN=Domain Admins,CN=Users,DC=domain,DC=com
Domain Controllers S-1-5-21-1234567890-1234567890-1234567890-516 CN=Domain Controllers,CN=Users,DC=domain,DC=com
Enterprise Admins S-1-5-21-1234567890-1234567890-1234567890-519 CN=Enterprise Admins,CN=Users,DC=domain,DC=com
Print Operators S-1-5-32-550 CN=Print Operators,CN=Builtin,DC=domain,DC=com
Read-only Domain Controllers S-1-5-21-1234567890-1234567890-1234567890-521 CN=Read-only Domain Controllers,CN=Users,DC=domain,DC=com
Replicator S-1-5-32-552 CN=Replicator,CN=Builtin,DC=domain,DC=com
Schema Admins S-1-5-21-1234567890-1234567890-1234567890-518 CN=Schema Admins,CN=Users,DC=domain,DC=com
Server Operators S-1-5-32-549 CN=Server Operators,CN=Builtin,DC=domain,DC=com
The command gets the value of dsHeuristics attribute and a list of groups protected by AdminSDHolder container. Also function returns the list of groups, excluded from protection by virtue of 16’th character’s value of dsHeuristics attribute.
Get-sthAdminSDHolderGroup
dsHeuristics: 000000000100000f
Protected Groups:
Name SID distinguishedName
---- --- -----------------
Administrators S-1-5-32-544 CN=Administrators,CN=Builtin,DC=domain,DC=com
Domain Admins S-1-5-21-1234567890-1234567890-1234567890-512 CN=Domain Admins,CN=Users,DC=domain,DC=com
Domain Controllers S-1-5-21-1234567890-1234567890-1234567890-516 CN=Domain Controllers,CN=Users,DC=domain,DC=com
Enterprise Admins S-1-5-21-1234567890-1234567890-1234567890-519 CN=Enterprise Admins,CN=Users,DC=domain,DC=com
Read-only Domain Controllers S-1-5-21-1234567890-1234567890-1234567890-521 CN=Read-only Domain Controllers,CN=Users,DC=domain,DC=com
Replicator S-1-5-32-552 CN=Replicator,CN=Builtin,DC=domain,DC=com
Schema Admins S-1-5-21-1234567890-1234567890-1234567890-518 CN=Schema Admins,CN=Users,DC=domain,DC=com
Excluded Groups:
Name SID distinguishedName
---- --- -----------------
Account Operators S-1-5-32-548 CN=Account Operators,CN=Builtin,DC=domain,DC=com
Server Operators S-1-5-32-549 CN=Server Operators,CN=Builtin,DC=domain,DC=com
Print Operators S-1-5-32-550 CN=Print Operators,CN=Builtin,DC=domain,DC=com
Backup Operators S-1-5-32-551 CN=Backup Operators,CN=Builtin,DC=domain,DC=com
The command disables protection by AdminSDHolder container for Account Operators group.
Disable-sthAdminSDHolderGroupProtection -AccountOperators -Disable -YesDisable
Current dsHeuristics value: null DISABLED: Account Operators Resulting dsHeuristics value: 0000000001000001
The command disables protection by AdminSDHolder container for Account Operators, Server Operators, Print Operators and Backup Operators groups.
Disable-sthAdminSDHolderGroupProtection -AccountOperators -ServerOperators -PrintOperators -BackupOperators -Disable -YesDisable
Current dsHeuristics value: null DISABLED: Account Operators DISABLED: Server Operators DISABLED: Print Operators DISABLED: Backup Operators Resulting dsHeuristics value: 000000000100000f
The command enables protection by AdminSDHolder container for Account Operators group.
Enable-sthAdminSDHolderGroupProtection -AccountOperators -Enable -YesEnable
Current dsHeuristics value: 000000000100000f ENABLED: Account Operators Resulting dsHeuristics value: 000000000100000e
The command enables protection by AdminSDHolder container for Account Operators, Server Operators, Print Operators and Backup Operators groups.
Enable-sthAdminSDHolderGroupProtection -AccountOperators -ServerOperators -PrintOperators -BackupOperators -Enable -YesEnable
Current dsHeuristics value: 000000000100000f ENABLED: Account Operators ENABLED: Server Operators ENABLED: Print Operators ENABLED: Backup Operators Resulting dsHeuristics value: 0000000001000000]]>
Function Get-sthPipelineCommand checks whether a specified command supports pipelining.
Function Get-sthPipelineParameter discovers parameters of the specified command, that accept pipeline input and displays their Names, Aliases, Types, Parameter Sets, whether it is a default Parameter Set, whether it is a Mandatory parameter as well as supported methods of accepting pipeline input – ByValue and ByPropertyName.
You can install sthPipelineTools module from PowerShell Gallery:
Install-Module sthPipelineTools
Also, you can find it on GitHub:
https://github.com/sethvs/sthPipelineTools
But how to use it?
This command checks, whether Get-Process cmdlet supports pipelining.
Get-sthPipelineCommand -Command Get-Process
Command SupportsPipeline ------- ---------------- Get-Process True
This command checks, whether Get-Verb function supports pipelining.
Get-sthPipelineCommand -Command Get-Verb
Command SupportsPipeline ------- ---------------- Get-Verb True
Command checks, whether Get-Service cmdlet supports pipelining.
We used its alias ‘gsv’ as a parameter value.
Get-sthPipelineCommand -Command gsv
Command SupportsPipeline ------- ---------------- Get-Service True
The first command gets [CmdletInfo] object for Get-Process cmdlet.
The second command gets [FunctionInfo] object for Get-Verb function.
The third command gets [AliasInfo] object for gsv alias.
The fourth command checks, whether these commands support pipelining.
$command = Get-Command -Name Get-Process $function = Get-Command -Name Get-Verb $alias = Get-Command gsv Get-sthPipelineCommand -Command $command, $function, $alias
Command SupportsPipeline ------- ---------------- Get-Process True Get-Verb True Get-Service True
The first command gets [CmdletInfo] object for Get-Process cmdlet.
The second command gets [FunctionInfo] object for Get-Verb function.
The third command gets [AliasInfo] object for gsv alias.
The fourth command checks, whether these commands and Get-PSDrive and Get-Content (we used its alias – ‘cat’) support pipelining.
This time we provide commands to Get-sthPipelineCommand using pipeline.
$command = Get-Command -Name Get-Process $function = Get-Command -Name Get-Verb $alias = Get-Command gsv $command, $function, $alias, 'Get-PSDrive', 'cat' | Get-sthPipelineCommand
Command SupportsPipeline ------- ---------------- Get-Process True Get-Verb True Get-Service True Get-PSDrive True Get-Content True
The first command gets array of cmdlets, that are members of ‘Microsoft.PowerShell.Management’ module.
The second command displays whether these commands support pipelining.
$commands = Get-Command -Module 'Microsoft.PowerShell.Management' Get-sthPipelineCommand -Command $commands
This command checks if two commands support pipeline – Get-Process and some nonexisting command.
Result displays information about Get-Process cmdlet and also shows that Non-ExistingCommand was not found.
Get-sthPipelineCommand -Command Get-Process, Non-ExistingCommand
Command SupportsPipeline ------- ---------------- Get-Process True Commands not found: Non-ExistingCommand
This command checks if two commands support pipeline – Get-Process and some nonexisting command.
Because -HideNotFoundCommands switch parameter was used, Get-sthPipelineCommand doesn’t show information about non-existing command.
Get-sthPipelineCommand -Command Get-Process, Non-ExistingCommand -HideNotFoundCommands
Command SupportsPipeline ------- ---------------- Get-Process True
This command displays information about parameters of Get-Process cmdlet, that can accept pipeline input.
Get-sthPipelineParameter -Command Get-Process
Command: Get-Process ParameterName Aliases ParameterType ParameterSet Mandatory ByValue ByPropertyName ------------- ------- ------------- ------------ --------- ------- -------------- Name ProcessName System.String[] NameWithUserName False False True Name ProcessName System.String[] Name (IsDefault) False False True Id PID System.Int32[] IdWithUserName True False True Id PID System.Int32[] Id True False True InputObject System.Diagnostics.Process[] InputObjectWithUserName True True False InputObject System.Diagnostics.Process[] InputObject True True False ComputerName Cn System.String[] Id False False True ComputerName Cn System.String[] Name (IsDefault) False False True ComputerName Cn System.String[] InputObject False False True
This command displays information about parameters of Get-Verb function, that can accept pipeline input.
Get-sthPipelineParameter -Command Get-Verb
Command: Get-Verb ParameterName Aliases ParameterType ParameterSet Mandatory ByValue ByPropertyName ------------- ------- ------------- ------------ --------- ------- -------------- verb System.String[] __AllParameterSets False True False
Command displays information about parameters of Get-Service cmdlet, that can accept pipeline input.
We used its alias ‘gsv’ as a parameter value.
Get-sthPipelineParameter -Command gsv
Command: Get-Service ParameterName Aliases ParameterType ParameterSet Mandatory ByValue ByPropertyName ------------- ------- ------------- ------------ --------- ------- -------------- Name ServiceName System.String[] Default (IsDefault) False True True ComputerName Cn System.String[] __AllParameterSets False False True InputObject System.ServiceProcess.ServiceController[] InputObject False True False
The first command gets [CmdletInfo] object for Get-Process cmdlet.
The second command gets [FunctionInfo] object for Get-Verb function.
The third command gets [AliasInfo] object for gsv alias.
The fourth command displays information about parameters of specified cmdlets and functions, that support pipeline input.
$command = Get-Command -Name Get-Process $function = Get-Command -Name Get-Verb $alias = Get-Command gsv Get-sthPipelineParameter -Command $command, $function, $alias
The first command gets [CmdletInfo] object for Get-Process cmdlet.
The second command gets [FunctionInfo] object for Get-Verb function.
The third command gets [AliasInfo] object for gsv alias.
The fourth command displays information about parameters of specified cmdlets and functions, that support pipeline input.
This time we provide commands to Get-sthPipelineParameter using pipeline.
$command = Get-Command -Name Get-Process $function = Get-Command -Name Get-Verb $alias = Get-Command gsv $command, $function, $alias, 'Get-PSDrive', 'cat' | Get-sthPipelineParameter
This command displays information about parameters of Get-Process cmdlet, that can accept pipeline input.
Also, output contains information about non-existing command.
Get-sthPipelineParameter -Command Get-Process, Non-ExistingCommand
Command: Get-Process ParameterName Aliases ParameterType ParameterSet Mandatory ByValue ByPropertyName ------------- ------- ------------- ------------ --------- ------- -------------- Name ProcessName System.String[] NameWithUserName False False True Name ProcessName System.String[] Name (IsDefault) False False True Id PID System.Int32[] IdWithUserName True False True Id PID System.Int32[] Id True False True InputObject System.Diagnostics.Process[] InputObjectWithUserName True True False InputObject System.Diagnostics.Process[] InputObject True True False ComputerName Cn System.String[] Id False False True ComputerName Cn System.String[] Name (IsDefault) False False True ComputerName Cn System.String[] InputObject False False True Commands not found: Non-ExistingCommand
This command displays information about parameters of Get-Process cmdlet, that can accept pipeline input.
Because -HideNotFoundCommands switch parameter was used, Get-sthPipelineParameter doesn’t show information about non-existing command.
Get-sthPipelineParameter -Command Get-Process, Non-ExistingCommand -HideNotFoundCommands
Command: Get-Process ParameterName Aliases ParameterType ParameterSet Mandatory ByValue ByPropertyName ------------- ------- ------------- ------------ --------- ------- -------------- Name ProcessName System.String[] NameWithUserName False False True Name ProcessName System.String[] Name (IsDefault) False False True Id PID System.Int32[] IdWithUserName True False True Id PID System.Int32[] Id True False True InputObject System.Diagnostics.Process[] InputObjectWithUserName True True False InputObject System.Diagnostics.Process[] InputObject True True False ComputerName Cn System.String[] Id False False True ComputerName Cn System.String[] Name (IsDefault) False False True ComputerName Cn System.String[] InputObject False False True
Function Get-sthPipelineCommand gets information about whether Get-Process, Start-Process and Stop-Process cmdlets support pipelining.
Then it sends results to Get-sthPipelineParameter function, which returns information about parameters, that can accept objects from pipeline.
Of these three commands, only two – Get-Process and Stop-Process – support pipelining, therefore Get-sthPipelineParameter results don’t contain information about Start-Process.
Get-sthPipelineCommand -Command Get-Process, Start-Process, Stop-Process | Get-sthPipelineParameter
Command: Get-Process ParameterName Aliases ParameterType ParameterSet Mandatory ByValue ByPropertyName ------------- ------- ------------- ------------ --------- ------- -------------- Name ProcessName System.String[] NameWithUserName False False True Name ProcessName System.String[] Name (IsDefault) False False True Id PID System.Int32[] IdWithUserName True False True Id PID System.Int32[] Id True False True InputObject System.Diagnostics.Process[] InputObjectWithUserName True True False InputObject System.Diagnostics.Process[] InputObject True True False ComputerName Cn System.String[] Id False False True ComputerName Cn System.String[] Name (IsDefault) False False True ComputerName Cn System.String[] InputObject False False True Command: Stop-Process ParameterName Aliases ParameterType ParameterSet Mandatory ByValue ByPropertyName ------------- ------- ------------- ------------ --------- ------- -------------- Name ProcessName System.String[] Name True False True Id System.Int32[] Id (IsDefault) True False True InputObject System.Diagnostics.Process[] InputObject True True False
Links:
Twitter: https://twitter.com/vsseth
Facebook: https://fb.com/inpowershell
VK: https://vk.com/inpowershell
Russian version of the blog:
https://sergeyvasin.net