Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
当脚本路径完全限定时,在删除服务器上执行Powershell失败_Powershell_Windows Server 2012 R2_Fully Qualified Naming - Fatal编程技术网

当脚本路径完全限定时,在删除服务器上执行Powershell失败

当脚本路径完全限定时,在删除服务器上执行Powershell失败,powershell,windows-server-2012-r2,fully-qualified-naming,Powershell,Windows Server 2012 R2,Fully Qualified Naming,我有两台服务器在同一个域上运行Windows Server 2012 R2,\tt-sql.perf.corp和\tt-file.perf.corp。文件服务器\tt file.perf.corp\fileshare\helloworld.ps1上的共享文件夹中有一个Powershell脚本。我在sql server上有一个应用程序正在执行以下命令: powershell-NonInteractive-InputFormat None-ExecutionPolicy Bypass-Command

我有两台服务器在同一个域上运行Windows Server 2012 R2,\tt-sql.perf.corp和\tt-file.perf.corp。文件服务器\tt file.perf.corp\fileshare\helloworld.ps1上的共享文件夹中有一个Powershell脚本。我在sql server上有一个应用程序正在执行以下命令:

powershell-NonInteractive-InputFormat None-ExecutionPolicy Bypass-Command“&'\tt file.perf.corp\fileshare\helloworld.ps1'

它失败,出现以下错误:

&:AuthorizationManager检查失败。第1行字符数:3 +&'\tt file.perf.corp\fileshare\helloworld.ps1' + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +CategoryInfo:SecurityError:(:)[],PSSecurityException +FullyQualifiedErrorId:未经授权的访问

如果我更改路径以使用IP地址,它也会失败

但是,当脚本的路径未完全限定时,它会起作用:
powershell-NonInteractive-InputFormat None-ExecutionPolicy Bypass-Command“&'\tt file\fileshare\helloworld.ps1'


Windows Management Instrumentation服务正在两台服务器上运行。我也在这两台服务器上运行了Get ExecutionPolicy,并且都设置为无限制。UAC在两台服务器上都被禁用。发生了什么事?

您似乎已经找到了解决方法(使用短名称而不是FQDN),因此,我将尝试回答为什么您首先会遇到这个问题

可以找到一些更大的问题;实际上,这是因为当您为服务器指定FQDN时,您运行的是与PowerShell/Windows安全功能之一相冲突的。即使您指定PowerShell应绕过正常执行策略,但从FQDN运行会使Windows相信此文件来自web,因此PowerShell希望向您显示如下警告:

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  
\\tt-file.perf.corp\fileshare\helloworld.ps1?
[D] Do not run  [R] Run once  [S] Suspend  [?] Help (default is "D"):
但它不能,因为您正在非交互模式下运行shell


所以你有两个选择来解决这个问题,真的:

  • 正如这篇博文所提到的,您可以通过在IE中将UNC路径设置为受信任的站点来解决问题,或者只使用您看到的短名称(使用\tt file\vs\tt file.perf.corp)
  • 您可以为本地Intranet区域使用组策略(或在IE中配置,如果这是一台一次性计算机)。如果这是一次性机器,请转到Internet Explorer、工具、Internet选项,然后转到安全选项卡。单击本地Intranet,Advanced,然后在此处添加FQDN,如下所示
  • 如果这是要全局配置的设置,请在组策略管理控制台中的以下位置指定路径,就像我在上面所做的那样:

    用户配置,展开策略>Windows设置>Internet 浏览器维护>安全性 3.双击安全区域和内容分级,然后选择导入当前安全区域和隐私设置

    有关集团政策方法的更多信息


    我希望这有帮助!不幸的是,我想不出一个好的PowerShell方法来解决这个问题:)

    谢谢你提供的信息,这就解释了。你知道为什么我不会在另一个内部域上看到这个问题吗?据我所知,没有将域添加到本地intranet的组策略,并且没有在IE中进行设置。我不确定在其他地方可以找到允许它工作的内容。Internet Explorer中也有一个设置,与我之前提到的受信任站点相同,无论如何,您可以单击一个复选框,它将自动确定intranet站点并绕过安全性。也许那个框被选中了?