简体   繁体   English

什么?{}在PowerShell中意味着什么?

[英]What does ?{} mean in PowerShell?

What does a ?{ } block mean in a PowerShell? PowerShell中的?{ }块是什么意思?

For example 例如

[enum]::GetValues([io.fileoptions]) | ?{$_.value__ -band 0x90000000}

? is an alias for Where-Object . 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: 怀疑使用Get-Alias cmdlet

Description 描述

The Get-Alias cmdlet gets the aliases (alternate names for commands and executable files) in the current session. Get-Alias cmdlet在当前会话中获取别名(命令和可执行文件的备用名称)。 This includes built-in aliases, aliases that you have set or imported, and aliases that you have added to your Windows PowerShell profile. 这包括内置别名,已设置或导入的别名以及已添加到Windows PowerShell配置文件的别名。

By default, Get-Alias takes an alias and returns the command name. 默认情况下, Get-Alias采用别名并返回命令名称。 When you use the Definition parameter, Get-Alias takes a command name and returns its aliases. 使用Definition参数时, Get-Alias接受命令名称并返回其别名。

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. 从Windows PowerShell 3.0开始, Get-Alias以“ <alias> -> <definition> ”格式显示非连字别名,以便更容易找到所需的信息。

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. 是Where-Object cmdlet的别名,但它还有另一个别名 - 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, ie for more than one critera, like this: {}大括号用于脚本块,在这种情况下它是一个过滤器脚本块,它主要用于复杂过滤,即多个critera,如下所示:

Get-Service | Where-Object -FilterScript {$_.Name -like '*audio*' -and $_.Status -eq 'Running'}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM