I'm working through the lab of advanced functions in PowerShell Toolmaking, and one of the answers to the lab questions uses the subexpression operator in the filter of Get-CimInstance.
Get-CimInstance win32_process -filter "ProcessId = '$($Service.ProcessId)'"
The command returns an error if I don't use the subexpression operator.
Why is that?
You mean, if you do Get-CimInstance win32_process -filter "ProcessId = '$Service.ProcessId'" ?
Because Only $service is seen as a variable. Do this:
Write-Host "ProcessId = $Service.processid"
And you'll see why that doesn't form a legal query. Covered this in "Learn Windows PowerShell in a Month of Lunches," FWIW.
This explanation clears things up.
You must be logged in to reply to this topic.