There are a couple of syntactic idiosyncrasies that PowerShell has that I can't find much documentation on. Today my question is the ? {...}
example
PS> Get-SPServiceInstance | ? {$_.GetType.toString() -eq $varname}
I understand what the pipe means. I'm pretty sure $_ is used to reference the current item in some kind of loop.
Can someone explain what this means? Also it would be great if someone could point me to a place where I can find out about PowerShell reserved symbols.
[^_^]16:46:21[1]>get-help ?
Name Category Synopsis
---- -------- --------
% Alias ForEach-Object
? Alias Where-Object
h Alias Get-History
r Alias Invoke-History
"?" is an alias for "where-object"
'?' is an alias to the Where-Object cmdlet. Where-Object takes a scriptblock (e.g '{...}') and evaluates its code. If the code evaluates to $true, the current object is written to the pipeline and is available to the next command in chain, otherwise ($false) the object is discarded.
For more help type:
Get-Help Where-Object -Full
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With