Exported on 11-Nov-2021 12:13:43
Parameters
1 - If
Below shows the basic IF Else statement syntax:
if (<test condition 1>)
{<statement list 1>}
When an IF statement is run, the
If
If
The IF Statement above in this Attune Blueprint contains a single command and does not contain any Else statements or any ElseIF statements.
This is the simplest form of the IF Statement.
It checks if the condition [the value of the Variable A ($A) is greater than 3] is satisfied and echos out the text [Output: (The value 5 is greater than 3.)] written in front of the CMDLET "Write-Host".
Login as user {Attune Node Credentials} on node {Attune Node}
#Region IF
#==============================================================================
# Creates a variable "A" and assigns a numeric value of 5 to it.
$A = 5
# This is an if statement block that checks if the value of the variable A is greater than 3.
if ($A -gt 3) {
# If the condition is satisfied it will print the text in front of the CMDLET (Write-Host) to the screen.
# This is a print to screen CMDLET [Write-Host].
Write-Host "The value $A is greater than 3."
}
#==============================================================================
#EndRegion IF
2 - Else
Below shows the basic Else statement syntax:
if (<test condition 1>)
{<statement list 1>}
[else
{<statement list 2>}]
When an IF statement is run, the
If <test condition 1> is true, <statement list 1> runs, and it exits the If statement.
If <test condition 1> is false, the <statement list 2> runs, and it exits the If statement.
In the example above, if the condition [the value of the Variable A ($A) is greater than 3] evaluates to true then, the statement in the IF block runs.
However, if the Variable A ($A) is less than or equal to 3 or is not an existing variable (the condition is not satsified) then, the If statement does not display a message.
By adding an Else statement, a message is displayed [Output: (The value 3 is less than or equal to 3 or is not created or is not initialized.)]
When the Variable A ($A) is less than or equal to 3 or the condition in the IF block is not satisfied.
Login as user {Attune Node Credentials} on node {Attune Node}
#Region Else
#==============================================================================
# Creates a variable "A" and assigns a numeric value of 3 to it.
$A = 3
# This is an IF-Else statement that checks if the value of the variable A is greater than 3.
if ($A -gt 3) {
# If the condition is satisfied it will print the text in front of the CMDLET (Write-Host) to the screen.
# This is a print to screen CMDLET [Write-Host].
Write-Host "The value $A is greater than 3."
}
# This is an else statement that runs if no condition is satisfied.
else {
# If the condition is not satisfied it will print the text in front of the CMDLET (Write-Host) to the screen.
# This is a print to screen CMDLET [Write-Host].
Write-Host ("The value $A is less than or equal to 3 or" + " is not created or is not initialized.")
}
#==============================================================================
#EndRegion Else
3 - ElseIf
Below shows the basic ElseIF statement syntax:
if (<test condition 1>)
{<statement list 1>}
[elseif (<test condition 2>)
{<statement list 2>}]
[else
{<statement list 3>}]
When an IF statement is run, the
If
If
If
If both
Multiple ElseIF statements can be used to create a series of conditional tests. Each test is run only if all the previous tests are false.
To further explain the script in this Attune Blueprint, you can use the ElseIF statement to display a message [Output: (The value 3 is equal to 3.)] when the condition [value of Variable A ($A) is equal to 3] is satisfied.
Login as user {Attune Node Credentials} on node {Attune Node}
#Region ElseIf
#==============================================================================
# Creates a variable "A" and assigns a numeric value of 3 to it.
$A = 3
# This is an if statement block that checks if the value of the variable A is greater than 3.
if ($A -gt 3) {
# If the condition is satisfied it will print the text in front of the CMDLET (Write-Host) to the screen.
# This is a print to screen CMDLET [Write-Host].
Write-Host "The value $A is greater than 3."
}
# This is an ElseIF statement block that checks if the value of the variable A is equal to 3.
elseif ($A -eq 3) {
# If the condition is satisfied it will print the text in front of the CMDLET (Write-Host) to the screen.
# This is a print to screen CMDLET [Write-Host].
Write-Host "The value $A is equal to 3."
}
# This is an else statement block that runs if neither of the above conditions is satisfied.
else {
# If neither of the above conditions is satisfied it will print the text in front of the CMDLET (Write-Host) to the screen.
# This is a print to screen CMDLET [Write-Host].
Write-Host ("The value $A is less than 3 or" + " was not created or initialized.")
}
#==============================================================================
#EndRegion ElseIF
POWERSHELL IF STATEMENT ON ATTUNE
This is a Blueprint on Attune of how to run an IF statement in PowerShell
The IF Statement is used to run a block of code if a specified condition evaluates to true.
One or more conditions can also be specified to run if the latter evaluates to false.
Finally, an additional code block can be specified to run if another condition evaluates to true.