SplattingTools.psm1
|
function New-SplatTable { <# .SYNOPSIS This creates a Splat Table from the existing cmdlet parameters .DESCRIPTION This command lists all of the parameters for a given command and allows you to select which of these will be added to the splat table .PARAMETER Cmdlet This parameter specifies which command will be used to create the splat table .PARAMETER NoClipboard By default this command will create a splat table and store it in the clipboard so that it can be easily added to other scripts, If you use this parameter, the splat table will be sent to standard output .NOTES Created By: Brent Denny Cerated On: 20-Jan-2026 Change Log ---------- 21-Jan-2026 - Added the help content .EXAMPLE New-SplatTable -Cmdlet New-ADUser This will create a list of the parameters available for the New-ADUser command and then request that you select which of those get added to the splat table it will then create the splat table and add it to the clipboard, where it can be easily pasted into a new script. .EXAMPLE New-SplatTable -Cmdlet New-ADUser -NoClipboard This will create a list of the parameters available for the New-ADUser command and then request that you select which of those get added to the splat table it will then display the splat table on screen #> [CmdletBinding()] Param ( [string]$Cmdlet = 'Get-Service', [switch]$NoClipboard ) try {$CommandInfo = Get-Command -Name $Cmdlet -ErrorAction stop} catch {write-warning "$Cmdlet is not a PowerShell Command"; break} $ParameterSets = $CommandInfo.ParameterSets # $ParameterSetNames = $ParameterSets.name # this will be for future reference when we can choose which parameter set to use # $ParamSetCount = $ParameterSetNames.count # this will be for future reference when we can choose which parameter set to use $Parameters = $ParameterSets.Parameters $ChosenParamNames = $Parameters.Name | Out-GridView -Title 'Select the parameters for the splat table' -OutputMode Multiple $MaxLengthParamName = ($ChosenParamNames | Measure-Object -Property Length -Maximum).Maximum + 1 if ($NoClipboard -eq $true) { # Send output to screen '@{' foreach ($ParameterName in $ChosenParamNames) { $SpaceMultipler = $MaxLengthParamName - ($ParameterName.length) " " + $ParameterName + (' ' * $SpaceMultipler) + '= " " ' } #foreach '}' } #if else { # Send output to clipboard '@{' | Set-Clipboard foreach ($ParameterName in $ChosenParamNames) { $SpaceMultipler = $MaxLengthParamName - ($ParameterName.length) " " + $ParameterName + (' ' * $SpaceMultipler) + '= " " ' | Set-Clipboard -Append } #foreach '}' | Set-Clipboard -Append Write-Warning 'The splat table as been stored in the clipboard' } #else } #function |