How do I find all variables with a certain scoped option?
all!
I apologise in advance if this has been 开发者_Go百科asked or discussed before; I was not able to find anything from Google.
Here is how I was able to find all variables in a PowerShell script that have a certain scoped option (example here: ReadOnly
):
gv | %{if ( ($_.options -band ([System.Management.Automation.ScopedItemOptions]::ReadOnly).value__)) {echo $_.name}}
There is also the None
ScopedItemOption which equals 0. Finding these variables is easy:
gv | %{if ( $_.options -eq 0) {echo $_.name}}
Does anyone have a better suggestion for doing this?
Thanks!
Carlos Nunez.
Cosmetic version. You can also use the Scope parameter to get variables from other scopes, like Global,Local or Script:
Get-Variable | Where-Object {$_.Options -match 'readonly'} | Select-Object -ExpandProperty Name
精彩评论