powershell get-wmiobject通配符-批处理文件
我在为批处理文件而挣扎..这样做的目的是获得安装在远程pc上的应用程序的版本,但我不想编写完整的应用程序名称(这可能与客户端有所不同),我想为此使用通配符。
不幸的是,GET-WmiObject运算符不使用参数( -like)作为SQL.
下面的powershell命令按照我的要求工作,但是当我将它添加到批处理文件时,它不能工作.
Power Shell命令:
[tag:Get-WmiObject -ComputerName ##PCNAMEHERE## -Query "Select * From Win32_Product Where name Like 'McAfee%'" | select Name, Version]批处理程序上的行
\[tag:get specific app with Wildcards !!!!! Need corrections !!!
Powershell.exe Get-WmiObject -ComputerName %CN% -Query Select \* From Win32_Product Where name Like ''McAfee%'' | select Name, Version \>\>%LOG%\]我在执行批处理时出错了..。已经试着玩“和”但是没有成功..。
Get-WmiObject :无法找到接受参数'*‘的位置参数。一行:1字符:1
从...
中选择*
发布于 2022-11-02 18:06:04
如果要从cmd运行此命令,则应该使用参数-command,并且只查询所需的属性,例如:
Powershell.exe -command "Get-WmiObject -ComputerName %CN% -Query ""Select Name,Version From Win32_Product Where name Like 'McAfee%'"""但是原则上,当您使用cmd运行批处理文件/工作时,您也可以使用wmic:
wmic product where "name like 'mcafee%'" get name,versionhttps://learn.microsoft.com/en-us/windows/win32/wmisdk/wmic
如果您想留在PowerShell中,您应该使用cmdlet代替,例如:
Powershell.exe -command "get-ciminstance -ComputerName %CN% -Query ""Select Name,Version From Win32_Product Where name Like 'McAfee%'"""但是请注意,cmdlets在WinRM上中继用于远程处理。
发布于 2022-11-02 11:53:26
这样可以避免大量引用问题:
Powershell.exe "Get-WmiObject -ComputerName %CN% Win32_Product | Where name -Like *mcafee* | select Name, Version >> %LOG%"更好的是,由于win32_product速度太慢,>>可能混合编码,但使用远程powershell:
powershell "invoke-command %cn% { get-package *mcafee* } | select name, version | add-content %log%"https://stackoverflow.com/questions/74285693
复制相似问题