如何检查powershell中多个变量的条件
我有四个变量,我需要检查它们是否等于或大于512。如果变量的值小于512,则应为该变量指定512的值如何检查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. } 我的代码中没有
$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,它是相同的。