在powershell v3中,您可以使用$executionContext.SessionState.InvokeCommand.PostCommandLookupAction
和CommandScriptBlock
来修改参数。你如何在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
}
}