在PowerShell (pwsh.exe)中执行Windows PowerShell专属Get-WmiObject命令的问题咨询
在PowerShell (pwsh.exe)中执行Windows PowerShell专属Get-WmiObject命令的问题咨询
最近我碰到了个头疼的问题,想跟大伙请教下:
我先启动了PowerShell 7(也就是C:\program files\PowerShell\7\pwsh.exe),然后尝试运行一条Windows PowerShell特有的命令:
Get-WmiObject -query "SELECT Version From Win32_OperatingSystem"
结果PowerShell 7完全不认识这条命令,直接报错:
Get-WmiObject: The term 'Get-WmiObject' is not recognized as a name of a cmdlet, function, script file, or executable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
一开始我想着,那只能切换到Windows PowerShell(powershell.exe)里去执行了,但后来寻思能不能直接从pwsh里调用执行,省得切换窗口。于是先试了这种写法:
powershell Get-WmiObject -query "SELECT Version From Win32_OperatingSystem"
结果还是失败了。
接着我尝试给整个命令套上单引号:
powershell 'Get-WmiObject -query "SELECT Version From Win32_OperatingSystem"'
这时候新问题又来了——如果我的命令里包含特殊字符(比如10.0%),或者是带where条件的命令,比如:Get-WmiObject -query "SELECT Version From Win32_OperatingSystem where Version like '10.0%'"
这种情况下又该怎么正确执行呢?
备注:内容来源于stack exchange,提问作者Ajay
相关产品推荐
相关产品推荐

