

The PowerShell Basics If Statement–#SQLNewBlogger
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.
Recommend
-
64
Learning SQL can feel intimidating, even to some experienced DB2 DBAs. For years, you could administer Db2 without using SQL. There are a lot of developers, too who want to learn SQL. The set-thinking of SQL can be confus...
-
12
SQL Error 10713 a MERGE Statement Must Be Terminated by a Semi Colon Sorry for not writing any blog posts for a week, I’ve been writing on a novel and I’ve gotten into a good flow and have been spending that pr...
-
9
Creating an HTML URL from a PowerShell String–#SQLNewBlogger Another po...
-
8
Don't Fear Hitting Enter with -WhatIf PowerShell Basics: Don't Fear Hitting Enter with -WhatIf ...
-
8
Query Windows Server Event Logs PowerShell basics: Query Windows Server Event Logs ...
-
12
PowerShell Basics: Query Azure Role Based Access Control Assignments ...
-
9
STRING_SPLIT Basics–#SQLNewBlogger Another post for me that is simple and hopefully serves as an example for people try...
-
12
Another post for me that is simple and hopefully serves as an example for people trying to get blogging as #SQLNewBloggers. I...
-
8
Reading Data from the Command Line in PowerShell–#SQLNewBlogger Another post for me that i...
-
12
Getting a Day Difference in PowerShell–#SQLNewBlogger Another post for me that is simple and hopeful...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK