Jus*_*Guy 47 active-directory powershell-2.0
我有一个非常短的PowerShell脚本连接到服务器并导入AD模块.我想通过双击来运行脚本,但我担心窗口会在最后一行后立即关闭.
我该如何解决这个问题?
dea*_*dog 81
您基本上有3个选项可以阻止PowerShell控制台窗口关闭,我在博客文章中有更详细的描述.
PowerShell -NoExit "C:\SomeFolder\SomeScript.ps1"Read-Host -Prompt "Press Enter to exit"有关要修改的注册表项的详细信息,请参阅我的博客.
Jus*_*Guy 17
呃......我应该知道的:
powershell -noexit <path\script>
Run Code Online (Sandbox Code Playgroud)
这就是它的全部:)
以下解决方案可防止脚本在运行 Powershell ISE 时关闭,并允许脚本在其他情况下关闭。
# If running in the console, wait for input before closing.
if ($Host.Name -eq "ConsoleHost")
{
Write-Host "Press any key to continue..."
$Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyUp") > $null
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
67951 次 |
| 最近记录: |