Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Logical Constructs Question

$
0
0

I am not a programmer at all, but I do want to be able to write my own scripts to make my admin life a bit easier. So, I am now into chapter 3 of Mr. Jones's TollMaker book. I have always had issues trying to understand the "If, ElseIf, and Else" statements. I think I have a handle on it now, but I am reading that professional fromatted code is what is expected. I have seen several examples, but I would like to submit the following format to the experts and ask if this format would be considered acceptable. It helps me to understand better if I keep things on one line that run together like the "Condition" and the "ScriptBlock" of the first "If" statement. If I had one or more "ElseIf" statements, I would format those the same way, is there anything wrong with what I am doing? Would this be considered acceptable in the PowerShell community?

# Clear the screen
Clear-Host

# Vaiable to hold user input
$StrComputer = Read-Host 'Enter the computer name'

# Variable to hold/store the results of the "Test-Connection" call to determine the machines "Ping" status
$strTC = Test-Connection -ComputerName $StrComputer -count 1 -quiet

# IF statement to determine if the machine is online, or offline so as to inform the script user.
if($strTC-eq 'True') {write-host 'This machine is online'}
else{Write-Host 'That machine is offline'}

 


Viewing all articles
Browse latest Browse all 6937

Trending Articles