Powershell 获取内容无法读取通过WMI检索到的路径 gc“C:\folder1\folder2\MyService.exe.config”
一切都好Powershell 获取内容无法读取通过WMI检索到的路径 gc“C:\folder1\folder2\MyService.exe.config”,powershell,Powershell,一切都好 gwmi win32_服务|?{$\u.name-匹配“MyService”}{$\u.pathname} “C:\folder1\folder2\MyService.exe.config” 返回正确的路径 gwmi win32_服务|?{$\.name-匹配“邮件”}{$\.pathname}}{$\.gettype()} 返回类型肯定是字符串 gwmi win32_服务|?{$\.name-match“Mailing”}{$\.pathname}}{gc-path$} gc:
gwmi win32_服务|?{$\u.name-匹配“MyService”}{$\u.pathname}
“C:\folder1\folder2\MyService.exe.config”
返回正确的路径
gwmi win32_服务|?{$\.name-匹配“邮件”}{$\.pathname}}{$\.gettype()}
返回类型肯定是字符串
gwmi win32_服务|?{$\.name-match“Mailing”}{$\.pathname}}{gc-path$}
gc:找不到驱动器。名为“C”的驱动器不存在。
第1行字符:71
+gwmi win32_服务|?{$\.name-match“MyService”}|%{$\.pathname}|%{gc-path$。。。
+ ~~~~~~~~~~
+CategoryInfo:ObjectNotFound:(“C:String)[获取内容],DriveNotFoundException
+FullyQualifiedErrorId:DriveNotFound,Microsoft.PowerShell.Commands.GetContentCommand
我在这里遗漏了什么?仔细查看错误消息: A drive with the name '"C' does not exist. ^ 删除字符串开头和结尾的双引号,问题将消失:
获取WmiObject Win32\u服务|
其中对象{$\.Name-匹配“邮件”}|
ForEach对象{$\路径名-替换“^”(.*“$”,“$1”}|
ForEach对象{Get Content-Path$}
仔细查看错误消息:
A drive with the name '"C' does not exist.
^
删除字符串开头和结尾的双引号,问题将消失:
获取WmiObject Win32\u服务|
其中对象{$\.Name-匹配“邮件”}|
ForEach对象{$\路径名-替换“^”(.*“$”,“$1”}|
ForEach对象{Get Content-Path$}
您想在这里做什么?返回的路径名很可能是一个exe文件,为什么要在powershell中检索它的内容?无论如何,请尝试以下操作:gwmi win32|服务{$|.name-match“idlsemanticlocking”}选择-ExpandProperty路径名{gc$}您想在此处执行什么操作?返回的路径名很可能是一个exe文件,为什么要在powershell中检索它的内容?无论如何,请尝试以下操作:gwmi win32|服务|?{$|.name-match“idlsemanticlocking”}选择-ExpandProperty路径名|%{gc$|