Created
June 14, 2011 21:17
-
-
Save linuxbender/1025908 to your computer and use it in GitHub Desktop.
read OS name – Service Pack – last boot – up time
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # read info from the current host | |
| # replace "." with your remote host - if you like | |
| $OS = get-wmiobject win32_operatingsystem -ComputerName . | |
| # default values | |
| $OSSP = "{n.a}" | |
| $OSName = "{n.a}" | |
| $OSLastBoot = "{n.a}" | |
| $OSUpTime = "{n.a}" | |
| #check host values are not equal null | |
| if($OS.CSDVersion -ne $Null) { | |
| $OSSP = $OS.CSDVersion.toString() | |
| } | |
| if($OS.Caption -ne $Null) { | |
| $OSName = $OS.Caption.toString() | |
| } | |
| if($OS.LastBootUpTime -ne $Null ) { | |
| $OSLastBoot = $OS.converttodatetime($OS.LastBootUpTime) | |
| $OSUpTime = New-TimeSpan (get-date $OSLastBoot) | |
| } | |
| # String.Format example in powershell | |
| $out = [String]::Format("OS name : {0} - Service Pack : {1} - Last Boot at : {2} `n", $OSName, $OSSP,$OSLastBoot) | |
| $out += [String]::Format("Server Up Time is in Days : {0} - Hours : {1} - Min : {2}", $OSUpTime.Days , $OSUpTime.Hours , $OSUpTime.Minutes) | |
| # console output | |
| Write-Host $out |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment