| external help file | PSScriptTools-help.xml |
|---|---|
| Module Name | PSScriptTools |
| online version | https://jdhitsolutions.com/yourls/c5336b |
| schema | 2.0.0 |
Convert a PowerShell expression into a splatting equivalent.
Convert-CommandToHashtable [-Text] <String> [<CommonParameters>]This command is intended to convert a long PowerShell expression with named parameters into a splatting alternative. The central concept is that you are editing a script file with a lengthy PowerShell expression with multiple parameters and you would like to turn it into splatting code. For best results, the command expression should use parameter names and not rely on positional parameters.
The command may produce an invalid hashtable with complex expressions as parameter values.
PS C:\> $text = "Get-WinEvent -ListLog p* -computername SRV1 -ErrorAction stop"
PS C:\> Convert-CommandToHashtable -Text $text | Set-ClipboardThe $text variable might be a line of code from your script. The second line converts into a splatting sequence and copies it to the Windows clipboard so you can paste it back into your script. You could create a VS Code task sequence using this function.
PS C:\> Convert-CommandToHashtable -Text (h 149).Commandline
$paramHash = @{
path = "c:\work"
filter = "*.ps1"
recurse = $True
}
Get-ChildItem @paramHashConvert command 149 from command history into a hashtable.
A PowerShell command using a single cmdlet or function, preferably with named parameters.
Type: String
Parameter Sets: (All)
Aliases:
Required: True
Position: 0
Default value: None
Accept pipeline input: False
Accept wildcard characters: FalseThis cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216).
Learn more about PowerShell: https://jdhitsolutions.com/yourls/newsletter