Coming from another Language if else Statements with Powershell is pretty straight forward.
Lets just see an example for syntax.
$eggs = 14
if ($eggs -eq 12) {
“You have exactly a dozen eggs.”
}
elseif ($eggs -lt 12) {
“You have less than a dozen eggs.”
}
else {
“You have more than a dozen eggs.”
}
Something different than other languages is the comparison operators.
$a -eq 0 # Equality comparison operator
$a -ne 5 # Not-equal comparison operator
$a -gt 2 # Greater than comparison operator
$a -lt 3 # Less than comparison operator
You can set up scripts based on decisions from if statements. What do i Mean?
let just say from the example above if the number of eggs is equal to 14, show me all the services in the system. You see! Haha! Fun game to play with.
If you are a blue teamer or a red teamer you can create your own scripts and use if statements as a way to control what decisions you want the script to go.
if ($eggs -eq 14) {
Get-Service -Name *
}
Lots of stuff that you can do when it comes to setting a script to run anyway you can. In my opinion, I think your ability to research on what can’t or can be done in a computer is what set a lot of researchers apart. I am not an expert by any means, I am just someone who is motivated and just like to learn things.
I just like the challenge of making the computer do things for me. Look at that script below and you can type it and make it run in your computer if you want. Basically it compares two variables and of-course if going to execute
because it is true, challenge is not equal to fun in that case, so if the challenge is not fun execute whatever is in the parenthesis.
$challenge = "fun"
$fun = $true
if($challenge -ne $fun){
Write-Output "I told you I make this work"
}
I learn something in College and around the internet called the True Table, Caleb Curry on his Youtube channel explain that stuff in a way that is very easy to understand. Go check him how he explain logic.
See you guys later!
Peace!
Here are some resources on if Statements in Powershell.
https://www.pdq.com/blog/how-to-use-if-statements-in-powershell/
https://gist.github.com/pcgeek86/336e08d1a09e3dd1a8f0a30a9fe61c8a