cscript调用powershell-不使用'&燃气轮机';或out-file cmdlet

cscript调用powershell-不使用'&燃气轮机';或out-file cmdlet,powershell,vbscript,wsh,Powershell,Vbscript,Wsh,情景: 想要在vbscript中封装一些powershell,因为我们需要同时从一堆服务器中提取CPU信息,并将结果放入单个文件中。在使用vbscript“fork”一个Powershell命令并立即返回之前,我也做过类似的工作,实际上可以同时浏览多个服务器,而无需等待每个服务器按顺序返回 平台恰好是XP(别无选择) 在PowerShell提示符中: Get-counter -computername thehost1 -SampleInterval 2 -MaxSamples 5 -Cou

情景:

想要在vbscript中封装一些powershell,因为我们需要同时从一堆服务器中提取CPU信息,并将结果放入单个文件中。在使用vbscript“fork”一个Powershell命令并立即返回之前,我也做过类似的工作,实际上可以同时浏览多个服务器,而无需等待每个服务器按顺序返回

平台恰好是XP(别无选择)

在PowerShell提示符中:

Get-counter 
-computername thehost1 -SampleInterval 2 -MaxSamples 5 
-Counter "\Processor(_Total)\% Processor Time" > out1.text
是找。。。。把文件写出来

从VBS:

CreateObject("WScript.Shell").Run "powershell -nologo -command Get-counter 
-computername thehost1 -SampleInterval 2 -MaxSamples 5 
-Counter ""\Processor(_Total)\% Processor Time"" | Out-File ""out1.txt"" ",0
从VBS执行powershell时,它会运行,但不会创建输出文件或打印错误(也尝试使用“>”而不是Out file servlet)

正在尝试调试(显示可能与cscript一起使用的参数的截断列表):

没有生成调试器或任何其他输出

关于这里可能出了什么问题,有什么线索吗

非常感谢


Kevin

我认为
“\Processor(\u Total)\%Processor Time”
的引号是问题的根源

您没有看到任何错误,因为VBScript正在成功运行PowerShell,并且不知道PowerShell脚本行正在失败

我通过将
更改为
使其工作,如下所示:

CreateObject("WScript.Shell").Run "powershell -nologo -command Get-counter -computername thehost1 -SampleInterval 2 -MaxSamples 5 -Counter '\Processor(_Total)\% Processor Time' >C:\YourPath\out1.txt", 0

我怀疑该文件是在其他文件夹中创建的。可能是powershell的默认工作目录,我认为是C:\Sindows\System32。请检查那里。还可以尝试使用文件的显式路径。如果尝试使用特定的文件路径,将在计算机上进行检查。谢谢
CreateObject("WScript.Shell").Run "powershell -nologo -command Get-counter -computername thehost1 -SampleInterval 2 -MaxSamples 5 -Counter '\Processor(_Total)\% Processor Time' >C:\YourPath\out1.txt", 0