0
gc "C:\folder1\folder2\MyService.exe.config"
gwmi win32_service|?{$_.name -match "MyService"} | % {$_.pathname}
"C:\folder1\folder2\MyService.exe.config"
返回正確路徑
gwmi win32_service|?{$_.name -match "Mailing"} | % {$_.pathname} | % {$_.gettype()}
返回類型,絕對是一個字符串
gwmi win32_service|?{$_.name -match "Mailing"} | % {$_.pathname} | % {gc -path $_}
gc : Cannot find drive. A drive with the name '"C' does not exist.
At line:1 char:71
+ gwmi win32_service|?{$_.name -match "MyService"} | % {$_.pathname} | % {gc -path $ ...
+ ~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: ("C:String) [Get-Content], DriveNotFoundException
+ FullyQualifiedErrorId : DriveNotFound,Microsoft.PowerShell.Commands.GetContentCommand
我在這裏錯過了什麼?
你有什麼想在這裏做什麼?返回的路徑名最有可能是一個exe文件,爲什麼你想在powershell中檢索它的內容?無論如何,試試這個:gwmi win32_service |?{$ _。name -match「IDLSemanticLogging」} |選擇-ExpandProperty路徑名| %{gc $ _} –