您能否从powershell中的PostCommandLookupAction访问/修改参数?
挂接命令的所有实例,如您能否从powershell中的PostCommandLookupAction访问/修改参数?,powershell,powershell-3.0,executioncontext,Powershell,Powershell 3.0,Executioncontext,挂接命令的所有实例,如cd,并希望验证和可能修改输入 $executionContext.SessionState.InvokeCommand.PostCommandLookupAction = { param($CommandName, $CommandLookupEventArgs) #Only hook cd if($CommandLookupEventArgs.CommandOrigin -eq "Runspace" -and $CommandName -eq "
cd
,并希望验证和可能修改输入
$executionContext.SessionState.InvokeCommand.PostCommandLookupAction = {
param($CommandName, $CommandLookupEventArgs)
#Only hook cd
if($CommandLookupEventArgs.CommandOrigin -eq "Runspace" -and $CommandName -eq "cd"){
//Do modification here
}
}
是否有一个变量提供修改传递给cd的参数的访问权限?如果指定
CommandScriptBlock
,则参数将在该脚本块内可用,例如:
$ExecutionContext.InvokeCommand.PostCommandLookupAction = {
param($s,$ea)
if ($ea.commandname -eq 'cd') {
write-host "Intercpeting CD command"
$ea.CommandScriptBlock = {Set-Location @args}
$ea.StopSearch = $true
}
}