What does a ?{ }
block mean in a PowerShell?
For example
[enum]::GetValues([io.fileoptions]) | ?{$_.value__ -band 0x90000000}
?
is an alias for Where-Object
. The curly brackets are used if you have to do something more complex with the actual object. You could also write:
[enum]::GetValues([io.fileoptions]) | Where-Object { $_.value__ -band 0x90000000}
Use Get-Alias
cmdlet in doubts:
Description
The
Get-Alias
cmdlet gets the aliases (alternate names for commands and executable files) in the current session. This includes built-in aliases, aliases that you have set or imported, and aliases that you have added to your Windows PowerShell profile.By default,
Get-Alias
takes an alias and returns the command name. When you use theDefinition
parameter,Get-Alias
takes a command name and returns its aliases.Beginning in Windows PowerShell 3.0,
Get-Alias
displays non-hyphenated alias names in an "<alias> -> <definition>
" format to make it even easier to find the information that you need.
PS D:\PShell> Get-Alias ?
CommandType Name ModuleName
----------- ---- ----------
Alias % -> ForEach-Object
Alias ? -> Where-Object
Alias h -> Get-History
Alias r -> Invoke-History
? is an alias for Where-Object cmdlet, though it also has another alias - where.
{} curly brackets are used in case of script block, in this case it's a filter script block, it's mostly used for complex filtering, i.e. for more than one critera, like this:
Get-Service | Where-Object -FilterScript {$_.Name -like '*audio*' -and $_.Status -eq 'Running'}
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