Functions/Convert-CmdletToSplat.ps1
function Convert-CmdletToSplat { [CmdletBinding()] param ( [Parameter(Mandatory)] [ArgumentCompleter( { param ( $commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters ) Get-Command "$wordToComplete*" | ForEach-Object { $_ } })] [string] $CommandToProcess, [Parameter()] [switch] $CopyToClipBoard ) # Ignore the following Parameters $CmdletBindings = @("Verbose", "Debug", "ErrorAction", "WarningAction", "InformationAction", "ErrorVariable", "WarningVariable", "InformationVariable", "OutVariable", "OutBuffer", "PipelineVariable") $CmdLet = $CommandToProcess.Trim().Split(" ")[0] $Verbouwen = @{} $i = 1 $Verbouwen.$i = $CommandToProcess $i++; $Verbouwen.$i = ($Verbouwen.($i - 1)).replace($CmdLet, "") $i++; $Verbouwen.$i = ($Verbouwen.($i - 1)).replace("``", "") # $i++; $Verbouwen.$i = ($Verbouwen.($i - 1)).replace("`n", "") # $i++; $Verbouwen.$i = ($Verbouwen.($i - 1)).replace(" ", "") # $Verbouwen | Format-List $ParamArray = $Verbouwen.$i -Split " -" if ($ParamArray.Count -gt 1) { $Params = @() $ParamArray | ForEach-Object { $p = $_.Trim().split(" ") if ($p) { $obj = [PSCustomObject]@{ Parameter = $p[0] Value = $p[1..50] } $Params += $obj } } $Output = "`n" if ($Params) { $Output += "`$Params = @{`n" $Params | ForEach-Object { if ($_.Value) { $Value = $_.Value } else { $Value = "`$true" } if ($Value -like "*`$*") { $quotes = "" } elseif ($Value -like "*`"*") { $quotes = "" } else { $quotes = "`"" } $Output += "`t$($_.Parameter) = $($quotes)$($Value)$($quotes)`n" } $Output += "}`n`n" } $Output += "$($CmdLet) @Params`n`n" Write-Host $Output -ForegroundColor Yellow if ($CopyToClipBoard) { $Output | clip } } # Write-Host "##################################################" -ForegroundColor Green # $Cmdlet = "Invoke-Timer" $Command = Get-Command $Cmdlet -ea 0 if ($Command) { # $Command $Output = "`n" $Output += "`$Params = @{`n" foreach ($c in $Command) { ($c.Parameters).getenumerator() | ForEach-Object { if ($CmdletBindings -notcontains $_.Key) { $Output += " $($_.Key) = " if ($_.Value.SwitchParameter) { $Output += "`$true" } elseif ($_.Value.Attributes.ValidValues) { $Output += "`"$(($_.Value.Attributes.ValidValues) -join ",")`"" } else { $Output += "`"`"" } $Output += "`n" } } } $Output += "}`n`n" $Output += "$($CmdLet) @Params`n`n" Write-Host $Output -ForegroundColor Yellow } } |