1

I have four variables, and I need to check if they are equal or greater than 512. If a variable's value is less than 512, then that variable should be assigned the value of 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.
}

These variables are not predefined in my code. It will be given by someone who runs the pipeline. So my code should be like: set the variable's value to 512, which are less than 512.

1 Answer 1

4

If you know the variable names, you can use the Get-Variable function

Get-Variable -Name ('a','b','c','d') | % {if ($_.Value -lt 512) {$_.Value = 512}}
Sign up to request clarification or add additional context in comments.

2 Comments

It worked .Could you tell me same logic in shell scripting as well?
@Stella - if you mean the powershell console instead of the ISE, it's the same.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.