Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/6.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
Windows powershell通过.bat文件的文件路径中存在空格问题_Windows_Batch File_Powershell - Fatal编程技术网

Windows powershell通过.bat文件的文件路径中存在空格问题

Windows powershell通过.bat文件的文件路径中存在空格问题,windows,batch-file,powershell,Windows,Batch File,Powershell,问题:我需要从服务器以用户身份运行PS脚本,并在此脚本中提供参数。只需简单地单击一个文件(.bat),即可由另一个IT团队在服务器上轻松部署ssas解决方案 为此,我使用.bat文件中的runAs命令。这里有一些复杂之处:我不能使用引号来回避powershell中文件路径中的空格问题,因为我使用.bat来表示runAs(第一个双引号将解释为runAs的结尾) 我还考虑过使用凭证代替runAs,但它也有同样的问题 set x=%CD% runas /netonly /user:server_n

问题:我需要从服务器以用户身份运行PS脚本,并在此脚本中提供参数。只需简单地单击一个文件(.bat),即可由另一个IT团队在服务器上轻松部署ssas解决方案

为此,我使用.bat文件中的runAs命令。这里有一些复杂之处:我不能使用引号来回避powershell中文件路径中的空格问题,因为我使用.bat来表示runAs(第一个双引号将解释为runAs的结尾)

我还考虑过使用凭证代替runAs,但它也有同样的问题

set  x=%CD%

runas /netonly /user:server_name\test "powershell.exe -NoExit %x%\deploy.ps1 server_name\MSSQL2012 %x%\_RetainALL.xmla

转义runas命令中的引号,并在cmd实例中运行它。

@user3627830,问题是runas没有正确解释引号,而不是powershell。错误是什么?错误在哪里?很好,但powershell理解这一点:\%cd%\deploy.ps1\'像%cd%\deploy.ps1\,如果我做\'%cd%\deploy.ps1\,那么powershell像:\D:\Folder\deploy.ps1。@user3627830,代码更新。试试这种方法。我编写了一个工具来转储用于执行的命令行,这样调用时它看不到反斜杠。同样的错误,poweshell解释这个comand像:D:\Folder,但实际路径是:D:\Folder 12\deploy.ps1
runas /netonly /user:server_name\test "cmd /c powershell.exe -NoExit \"%cd%\deploy.ps1\" server_name\MSSQL2012 \"%cd%\_RetainALL.xmla\" "