Advertisement
erikwelander25

Powershell config

Nov 13th, 2019
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Import-Module posh-git
  2. function Set-ParamAlias {
  3.     param
  4.     (
  5.         [string]$Name,
  6.         [string]$Command,
  7.         [hashtable]$parametersBinding
  8.     )
  9.  
  10.     function AddLine($ProxyCommand, $line) {
  11.         $ProxyCommand -replace '(.*)(\$outBuffer = \$null)(.*)', "`$1`$2`n        $line`$3"
  12.     }
  13.    
  14.     $metadata = New-Object System.Management.Automation.CommandMetaData (Get-Command $Command)
  15.     foreach ($b in $parametersBinding.GetEnumerator())
  16.     {
  17.         $null = $metadata.Parameters.Remove($b.Name)
  18.     }
  19.     $ProxyCommand = [System.Management.Automation.ProxyCommand]::Create($metadata)
  20.     foreach ($b in $parametersBinding.GetEnumerator())
  21.     {
  22.         $ProxyCommand = AddLine $ProxyCommand "`$PSBoundParameters['$($b.Name)'] = $($b.Value)"
  23.     }
  24.  
  25.     iex "function global:$Name { $ProxyCommand }"
  26. }
  27. Set-ParamAlias -Name rmr -Command rm -parametersBinding @{Recurse = '$true'; Force = '$true'}
  28. Set-ParamAlias -Name cpr -Command cp -parametersBinding @{Recurse = '$true'; Force = '$true'}
  29. Set-ParamAlias -Name mkfile -Command New-Item -ItemType file -parametersBinding @{Name = '$params'}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement