Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/13.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
从VBScript执行PowerShell命令_Powershell_Vbscript_Iis 8.5 - Fatal编程技术网

从VBScript执行PowerShell命令

从VBScript执行PowerShell命令,powershell,vbscript,iis-8.5,Powershell,Vbscript,Iis 8.5,我有一个PowerShell命令,可以从IIS(8.5)中删除虚拟文件夹 删除项目IIS:\Sites\WebsiteName\VirtualFolderName-Force-Recurse 当从PowerShell控制台独立执行时,它工作正常,但我想从VBScript内部运行它。我有类似以下内容的VBScript: Set objShell=CreateObject(“WScript.Shell”) 运行(“powershell.exe-noexit-Command='Remove-Item

我有一个PowerShell命令,可以从IIS(8.5)中删除虚拟文件夹

删除项目IIS:\Sites\WebsiteName\VirtualFolderName-Force-Recurse
当从PowerShell控制台独立执行时,它工作正常,但我想从VBScript内部运行它。我有类似以下内容的VBScript:

Set objShell=CreateObject(“WScript.Shell”)
运行(“powershell.exe-noexit-Command='Remove-Item IIS:\Sites\WebsiteName\VirtualFolderName-Force-Recurse'”)
当我在上面执行时,它不会工作,它只是在PowerShell控制台上发出命令


这里有什么建议吗?

单引号只能在PowerShell中使用。PowerShell语句周围需要双引号,并且必须将它们加倍才能在VBScript字符串中转义。另外,删除参数
-Command
与其参数之间的
=
。如果模块
WebAdministration
没有自动加载,您需要自己加载,否则您将没有驱动器
IIS:

更改此项:

objShell.Run(“powershell.exe-noexit-Command='Remove-Item IIS:\Sites\WebsiteName\VirtualFolderName-Force-Recurse'”)
为此:

objShell.Run(“powershell.exe-noexit-Command”“导入模块WebAdministration;删除项目IIS:\Sites\WebsiteName\VirtualFolderName-Force-Recurse”“)

出现错误:删除项目:找不到驱动器。名为“IIS”的驱动器不存在。@Pankaj加载模块
WebAdministration
。请参阅更新的答案。