[求助]某.ps1在ISE中运行正常但在Powershell控制台中停止工作
powershell吧
全部回复
仅看楼主
level 3
test.ps1
[System.Reflection.Assembly]::LoadFrom( ${env:windir} + "\system32\inetsrv\" + "Microsoft.Web.Management.dll" )
$infos = [Microsoft.Web.Management.Server.ManagementAuthorization]::GetAuthorizedUsers("NewWebSite1", $false, 0,[int]::MaxValue)
$keypress = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
test.ps1文件在ISE中运行成功,且在Powershell中通过 & ".\test.ps1"和 .\test.ps1可以运行成功。但是在powershell中尝试通过: powershell -file ".\test.ps1" 来执行命令时Powershell控制台停止工作(Stopped Working),在网上查资料后有尝试添加 -sta参数的,但是不起作用,请大神帮帮看看问题出在哪儿。
Powershell 版本: Version : 5.0.9897.0
2014年12月03日 07点12分 1
level 9
实际上你的理解,启动一个PowerShell或者是ISE再运行test.ps1,PowerShell已经加载了一些模块。比如ISE就加载了.NET Runtime。Microsoft.Web.Management.dll依赖的dll你也要显示的在脚本中加载。
2015年01月06日 11点01分 2
1