gpt4 book ai didi

powershell - 使用powershell编写新的powershell窗口脚本?

转载 作者:行者123 更新时间:2023-12-03 00:54:31 25 4
gpt4 key购买 nike

我想自动启动一个Powershell并从另一个Powershell运行一些命令(由于功能的优势,我想从另一个Powershell启动它)。
我想这样做是因为我正在使用powershell测试用C#编码的* .dll,并且由于无法在powershell中卸载dll而必须不断启动和退出powershell,因此无法用其重新加载库类。

有没有一种方法可以自动执行Powershell,就像使用Office进行对象自动化一样?

最佳答案

仅使用脚本或脚本块怎么办?

powershell {
Add-Type foo.dll
[Foo]::DoSomething();
}

应该管用。

如果您需要交互性并且需要随意尝试多个命令,则可以使用
powershell -noexit { Add-Type foo.dll }

在这种情况下,至少更改提示颜色可能很有用,这样您就知道您是在测试子 shell 中还是在父子 shell 中:
function Test-DLL {
powershell -noexit {
function prompt {
Write-Host -n -fore yellow "Test $PWD>"
' '
}

Add-Type foo.dll
}
}

我也倾向于通过以下方式定义一个小函数:
"function $([char]4) { exit }" | Invoke-Expression

这使我可以使用Ctrl + D,Enter(类似于Unix shell的一半)关闭PowerShell。

关于powershell - 使用powershell编写新的powershell窗口脚本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9620342/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com