我们在基础架构中有许多PowerShell脚本,用于从用户login到支持技术人员模拟用户上下文等各种任务。
这些脚本集中在我们的文件服务器上(通过DFS)以便于pipe理。 其中一些在login时运行,一些在已发布的Citrix应用程序中运行。
我们已经为整个域以及将Powershell执行策略设置为“不受限制”的所有用户实施了策略,以便脚本可以从文件服务器运行。
这对于login脚本来说(至less目前为止)是完全正常的,但对于稍后运行的脚本(通常是通过已发布的应用程序,但在使用terminal服务和完整桌面时同样适用),结果是不一致的:某些用户可以运行脚本很好,一些总是在powershell控制台中提示让脚本运行。
我无法find任何可能导致此行为的事情,而且实际上并不一致:如果手动启动PowerShell并运行get-executionpolicy ,则会被告知当前的策略是unrestricted 。 然而,如果来自同一个会话,我尝试通过调用powershell <script file name> <parameters>的程序运行脚本,脚本可以运行之前得到提示。
什么可能导致这样的行为?
我猜你所看到的提示是这样的:
Security Warning Run only scripts that you trust. While scripts from the Internet can be useful, this script can potentially harm your computer. Do you want to run \server\scripts\my.ps1? [D] Do not run [R] Run once [S] Suspend [?] Help (default is "D"): d
如果运行“get-help about_execution_policies”,则会看到“Unrestricted”的行为定义为:
Unrestricted - Unsigned scripts can run. (This risks running malicious scripts.) - Warns the user before running scripts and configuration files that are downloaded from the Internet.
即使设置为Unrestricted,PowerShell也会提示您运行它认为从互联网上下载的脚本 – 这可以包括从UNCpath调用的脚本。 您可以通过调整计算机上的Internet Explorer安全区域来调整行为(是的),和/或通过使用caspol.exe在系统上configuration.NET代码访问安全策略。
这里有一些有用的链接,如果这实际上是你看到的提示:
http://www.leeholmes.com/blog/2008/07/24/powershell-execution-policies-in-standard-images/