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 - Fatal编程技术网

尝试运行PowerShell脚本时出现“浏览文件夹”错误

尝试运行PowerShell脚本时出现“浏览文件夹”错误,powershell,Powershell,我对PowerShell非常陌生,需要运行从公司下载的脚本以进行故障排除。这是在没有GUI的web服务器上完成的,因此我只能使用PowerShell命令 在管理员中执行以下命令后:Windows PowerShell PS D:\> ls Directory: D:\ Mode LastWriteTime Length Name ---- ------------- --

我对PowerShell非常陌生,需要运行从公司下载的脚本以进行故障排除。这是在没有GUI的web服务器上完成的,因此我只能使用PowerShell命令

在管理员中执行以下命令后:Windows PowerShell

PS D:\> ls

            Directory: D:\

Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----         7/1/2019   4:08 PM                Backups
d-----         7/9/2019  10:22 AM                certificates
d-----        6/20/2019   4:21 PM                inetpub
d-----        6/19/2019   2:57 PM                Installs
d-----        6/19/2019   2:56 PM                Program Files
d-----        6/19/2019   2:56 PM                Program Files (x86)
d-----        1/31/2020  11:50 AM                serverinfo
-a----        7/16/2019  11:43 AM              2 tmp

PS D:\> .\serverinfo\ServerInfo.ps1

Security warning
Run only scripts that you trust. While scripts from the internet can be useful, this script can potentially harm your computer. If you trust this script, use the Unblock-File cmdlet to allow the script to run without this warning message. Do you want to run D:\serverinfo\ServerInfo.ps1?
[D] Do not run  [R] Run once  [S] Suspend  [?] Help (default is "D"): R

Script has started
Select-Folder : Operation cancelled by user.
At D:\serverinfo\ServerInfo.ps1:46 char:9
+ $path = Select-Folder
+         ~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Select-Folder
然后它会弹出

如图所示,没有要显示的文件夹,对此我感到困惑。程序文件、服务器信息、inetpub等不是应该存在的所有文件夹吗

当我尝试单击“创建新文件夹”时,什么也没发生-我无法创建一个

单击“确定”或“取消”按钮都会在PowerShell中显示相同的内容

PS D:\> ls

            Directory: D:\

Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----         7/1/2019   4:08 PM                Backups
d-----         7/9/2019  10:22 AM                certificates
d-----        6/20/2019   4:21 PM                inetpub
d-----        6/19/2019   2:57 PM                Installs
d-----        6/19/2019   2:56 PM                Program Files
d-----        6/19/2019   2:56 PM                Program Files (x86)
d-----        1/31/2020  11:50 AM                serverinfo
-a----        7/16/2019  11:43 AM              2 tmp

PS D:\> .\serverinfo\ServerInfo.ps1

Security warning
Run only scripts that you trust. While scripts from the internet can be useful, this script can potentially harm your computer. If you trust this script, use the Unblock-File cmdlet to allow the script to run without this warning message. Do you want to run D:\serverinfo\ServerInfo.ps1?
[D] Do not run  [R] Run once  [S] Suspend  [?] Help (default is "D"): R

Script has started
Select-Folder : Operation cancelled by user.
At D:\serverinfo\ServerInfo.ps1:46 char:9
+ $path = Select-Folder
+         ~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Select-Folder
这是什么意思?我能做些什么来修复这个问题并最终正确运行我的脚本? 先谢谢你

编辑: 以下是ServerInfo.ps1文件的代码。这是一个很长的脚本,但是关于文件夹的代码就在它的开头。

能否发布您的Powershell版本和环境信息

我试着在本地机器上运行ServerInfo.ps1脚本,它运行得非常完美

我猜可能是版本、环境或权限问题

作为参考,我在域外运行Windows 10 1809,Powershell版本为5.1.17763.771

编辑:如果您完全信任脚本,请确保取消阻止脚本,因为您没有访问GUI的权限,您可以执行以下操作:

获取子项D:\Path\To\Script.ps1 |取消阻止文件


我还建议您尝试在自己的脚本中运行有问题的代码,看看问题是否仍然存在。

您可以发布ServerInfo.ps1文件的内容吗?我假设脚本希望访问您环境中不可用的一些资源。也许你不应该与脚本抗争,而应该以其他方式获取信息。如果脚本足够短,可以发布到这里,那么它可能是一个起点。@MarkKram我继续编辑了这篇文章,并添加了一个脚本链接。时间太长了,我无法将其粘贴到帖子中,所以我使用了pastebin。这应该只是与问题相关的代码的开始。@harper现在补充道。嗨,很抱歉我的回复太晚了,我是一名实习生,有一段时间没有做过这方面的工作了。我终于能够选择一个文件夹,它最终可以在PSISE中运行脚本。它执行了从删除磁盘上现有的serverinfo.zip文件到获取升级日志内容(如果有)的所有命令。但是,当它尝试执行下一个命令Passwordstate Gateway Directory Properties时,它会显示一个错误,即Get ChildItem:找不到路径“C:Hosts\Gateway”,因为它不存在。我不知道它为什么这么说?我该如何解决这个问题?我假设C:Hosts\Gateway缺少第一个\是您在评论中的一个输入错误?否则,请确保路径存在并且脚本可以访问该路径,确保没有可能阻止命令正常工作的权限问题、转义和无效字符。尝试在脚本外部的路径上运行get子集,以确保。如果您找到答案,请考虑它。