从VBScript执行PowerShell命令
我有一个PowerShell命令,可以从IIS(8.5)中删除虚拟文件夹从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
删除项目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
。请参阅更新的答案。