更新时间:2022-12-02 20:01:02
仅使用脚本或脚本块怎么办?
What about just using a script or script blocks?
powershell {
Add-Type foo.dll
[Foo]::DoSomething();
}
应该工作.
如果您需要交互性并且需要随意尝试多个命令,则可以使用
If you need interactivity and need to try multiple commands at will, you could use
powershell -noexit { Add-Type foo.dll }
在这种情况下,至少更改提示颜色可能很有用,这样您就知道您是在测试子外壳程序中还是在父子外壳程序中:
In that case it can be useful to at least change the prompt color so you know whether you're in the test sub-shell or in the parent one:
function Test-DLL {
powershell -noexit {
function prompt {
Write-Host -n -fore yellow "Test $PWD>"
' '
}
Add-Type foo.dll
}
}
我也倾向于通过以下方式定义一个小函数:
I tend to define a small function in the following way too:
"function $([char]4) { exit }" | Invoke-Expression
这使我可以使用 Ctrl + D , Enter (类似于Unix shell的一半)关闭PowerShell.
which allows me to close PowerShell with Ctrl+D, Enter (half an analog to Unix shells).