Blog Post

The PowerShell Basics If Statement–#SQLNewBlogger

,

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.

Original post (opens in new tab)
View comments in original post (opens in new tab)

Rate

5 (2)

You rated this post out of 5. Change rating

Share

Share

Rate

5 (2)

You rated this post out of 5. Change rating