Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.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
如何检查powershell中多个变量的条件_Powershell_Shell - Fatal编程技术网

如何检查powershell中多个变量的条件

如何检查powershell中多个变量的条件,powershell,shell,Powershell,Shell,我有四个变量,我需要检查它们是否等于或大于512。如果变量的值小于512,则应为该变量指定512的值 $a = 512 $b = 256 $c = 512 $d = 1024 if(!($a, $b, $c,$d | Where {$_ -ge 512})) { #do some stuff } else { #here I need to write code like it should make variable ($b) equal to 512. } 我的代码中没有

我有四个变量,我需要检查它们是否等于或大于512。如果变量的值小于512,则应为该变量指定512的值

$a = 512
$b = 256
$c = 512
$d = 1024

if(!($a, $b, $c,$d | Where {$_ -ge 512})) {
    #do some stuff
}
else {
    #here I need to write code like it should make variable ($b) equal to 512.
}

我的代码中没有预定义这些变量。它将由管道运营商提供。因此,我的代码应该是这样的:将变量的值设置为512,小于512。

如果您知道变量名称,可以使用
获取变量
函数

Get-Variable -Name ('a','b','c','d') | % {if ($_.Value -lt 512) {$_.Value = 512}}

如果知道变量名,可以使用
Get variable
函数

Get-Variable -Name ('a','b','c','d') | % {if ($_.Value -lt 512) {$_.Value = 512}}

它起作用了。你能告诉我shell脚本中的相同逻辑吗?@Stella-如果你指的是powershell控制台而不是ISE,它是相同的。它起作用了。你能告诉我shell脚本中的相同逻辑吗?@Stella-如果你指的是powershell控制台而不是ISE,它是相同的。