Skip to content

Instantly share code, notes, and snippets.

@p0w3rsh3ll
Created March 31, 2015 16:24
Show Gist options
  • Save p0w3rsh3ll/6ebd39e20ad66f0207f8 to your computer and use it in GitHub Desktop.
Save p0w3rsh3ll/6ebd39e20ad66f0207f8 to your computer and use it in GitHub Desktop.
$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