Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/powerbi/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows Powershell:循环现有变量以使某些变量不可见_Windows_Variables_Powershell_Foreach - Fatal编程技术网

Windows Powershell:循环现有变量以使某些变量不可见

Windows Powershell:循环现有变量以使某些变量不可见,windows,variables,powershell,foreach,Windows,Variables,Powershell,Foreach,我的困境是我想检查我所有的powershell变量,对于某些变量,使它们不可见。我试图避免为每个单独的变量编写代码,因为其中有相当多的变量 这是我到目前为止想到的,它不起作用,希望能得到一些帮助 $var=Get-Variable | Where-Object {($_.name -like "*label*")} | Sleect -expand Name foreach ($y in $var) { $tes="`$$y" $tes.Visiable=$fal

我的困境是我想检查我所有的powershell变量,对于某些变量,使它们不可见。我试图避免为每个单独的变量编写代码,因为其中有相当多的变量

这是我到目前为止想到的,它不起作用,希望能得到一些帮助

    $var=Get-Variable | Where-Object {($_.name -like "*label*")} | Sleect -expand Name
    foreach ($y in $var) {
    $tes="`$$y"
    $tes.Visiable=$false
    }
本质上,我希望将“$tes”替换为实际变量名“$labelHome”,这样命令将像输入“$labelHome.Visible=$false”一样运行

谢谢

也许是这个

Get-Variable *label*  | Set-Variable -Visibility Private
试试这个:

Get-Variable *label* |  %{ ($_.Value).Visible = $false }

谢谢,但是运气不好。仍然可见据我所知,这就像PS变量一样“看不见”。我不希望代码能工作,因为你在
Sleect
Visiable
中至少有两个打字错误。很酷,帖子中的措辞有点混乱,但我想这就是你想要的。