如何查找具有特定范围选项的所有变量?
全部!
如果之前有人问过或讨论过这个问题,我提前表示歉意;我无法从谷歌找到任何东西。
以下是我如何在 PowerShell 脚本中找到具有特定作用域选项的所有变量(此处示例:ReadOnly
):
gv | %{if ( ($_.options -band ([System.Management.Automation.ScopedItemOptions]::ReadOnly).value__)) {echo $_.name}}
还有等于 0 的 None
ScopedItemOption找到这些变量很容易:
gv | %{if ( $_.options -eq 0) {echo $_.name}}
有人对此有更好的建议吗?
谢谢!
卡洛斯·努涅斯.
all!
I apologise in advance if this has been 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
化妆品版。您还可以使用 Scope 参数从其他范围获取变量,例如 Global、Local 或 Script:
Cosmetic version. You can also use the Scope parameter to get variables from other scopes, like Global,Local or Script: