开发者

How do I find all variables with a certain scoped option?

开发者 https://www.devze.com 2023-03-29 22:27 出处:网络
all! I apologise in advance if this has been 开发者_Go百科asked or discussed before; I was not able to find anything from Google.

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
0

精彩评论

暂无评论...
验证码 换一张
取 消