Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
$MetaData = New-Object System.Management.Automation.CommandMetaData (Get-Command Get-Culture -CommandType Cmdlet)
$functionContent = ([System.Management.Automation.ProxyCommand]::Create($MetaData))
$newcode = @'
if ($PSBoundParameters['All']) {
$scriptCmd = { & { [System.Globalization.CultureInfo]::GetCultures([System.Globalization.CultureTypes]::AllCultures) }}
} else {
$wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Get-Culture', [System.Management.Automation.CommandTypes]::Cmdlet)
$scriptCmd = {& $wrappedCmd @PSBoundParameters }
}
'@
$line1 = "\`$wrappedCmd\s\=\s\`$ExecutionContext\.InvokeCommand\.GetCommand\('Get\-Culture\'\,\s\[System\.Management\.Automation\.CommandTypes\]::Cmdlet\)`r`n"
$line2 = "\s*\`$scriptCmd\s=\s\{&\s\`$wrappedCmd\s@PSBoundParameters\s}"
$updatedFunction = $functionContent -replace (($line1,$line2)-join,''),$newcode
$updatedFunction = $updatedFunction -replace 'param\(\)','param([switch]${All})'
Set-Item -Path function:\GLOBAL:Get-Culture -Value $updatedFunction -Force
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment