8

The PowerShell Basics If Statement–#SQLNewBlogger

 3 years ago
source link: https://voiceofthedba.com/2021/04/14/the-powershell-basics-if-statement-sqlnewblogger/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Another post for me that is simple and hopefully serves as an example for people trying to get blogging as #SQLNewBloggers.

This is a fairly simple construct, but I keep looking up the syntax if I haven’t written anything for a couple of weeks, which does happen. I’m hoping this quick post will help me remember the structure.

Parenthesis and Braces

The general structure is simple. It’s like this:

if ($a -eq 1) {
# do something  
}

This structure has the test expression inside the parenthesis and then any statements to execute, one or more, inside braces. Fairly simple, as long as you remember the –eq, –gt, –lt, etc.

If you have an ELSE, then you add that next with the braces again.

if ($a -eq 1) {
# do something  
}
else {
# do something else
}

That is easy to remember, as long as you use one language. I’ve been working more with Python, which is where I think I get confused.

SQLNewBlogger

This was about the 5th or 6th time I looked up the syntax, so I stopped and wrote this. It took only about 10 minutes to do this, no need to do more than mock up code, but show how this works.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK