1
在powershell v3中,您可以使用$executionContext.SessionState.InvokeCommand.PostCommandLookupAction
和CommandScriptBlock
修改參數。你如何在v2中完成同樣的事情?如何修改發送到PowerShell v2中內置命令的參數?
Powershell的3例如:
$executionContext.SessionState.InvokeCommand.PostCommandLookupAction = {
param($CommandName, $CommandLookupEventArgs)
if($CommandLookupEventArgs.CommandOrigin -eq "Runspace" -and $CommandName -eq "cd"){
$CommandLookupEventArgs.CommandScriptBlock = {
if($args){
$x = ModifyPathOrDoSomethingHere($x)
$x = Resolve-Path($args)
Set-Location $x
}
}
$CommandLookupEventArgs.StopSearch = $true
}
}