Link to home
Start Free TrialLog in
Avatar of David Sechler
David SechlerFlag for United States of America

asked on

IF statement to PowerShell Script

I have a Powershell script that gets uptime from servers that I pieced together from bits and pieces from written code on the net. What I have works great, however I've been asked to modify it for some output based on how long the servers have been up.

Here is what I've been asked to add to the script:

An "if" statement to check if the $UptimeSeconds variable is less than 600 to Write-output the value "rebooted" and and if $UptimeSeconds is greater than 2592000 (30 days) to Write-output "rebootneeded"

I appreciate any help I can get. I'm just leaning Powershell and am digging in where I can.

David
Uptime.txt
ASKER CERTIFIED SOLUTION
Avatar of SubSun
SubSun
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of David Sechler

ASKER

I ran the script and got the same output as I did in the original script. I've added the results.txt as an attachmentresults.txt.
It's because none of the servers have uptime below 600 seconds and above 30 days..

If you want to test change the threshold to one day.. Change line 13 to..
	If ($uptime.TotalDays -gt 1){

Open in new window

I just bounced one of my workstations in the list and your right! Good to go! Thanks so much for the help Subsun!
Thanks again for the help. This was my first question here and I'm quite pleased!