Showing posts with label powershell script. Show all posts
Showing posts with label powershell script. Show all posts

Monday, December 30, 2013

Uptime in Powershell using WMI


The below script is written in power shell and is used to compute up-time for remote Windows system using WMI WIn32_OperatingSystem . You need to have Power shell installed to run this and also would require Administrative rights on Remote hosts  which you are targeting this script. Copy the below script in green to notepad and save it as get-uptime.ps1.

Go to powershell, and set-location to the directory where you have saved the script.

Execute the script .\get-uptime.ps1 hostname to get the uptime of remote system

#Script to Find the uptime of remote host
#pass the paramter hostname after the script during usage
#Author: Shashanka Haritsa 2011
#Function to Convert Date String
Function datestringtodate($stringdata){
[System.Management.ManagementDateTimeconverter]::ToDateTime($stringdata)
}
}
if ($args -eq “Help”) {
Write-host “Usage get-uptime.ps1 hostname” -Foregroundcolor Cyan
Write-host “Ex: get-uptime.ps1 server01, where server01 is the hostname” -Foregroundcolor Cyan
exit
}
Else{
$lastuptimedate = (get-wmiobject win32_operatingsystem -Computername $args).LastBootUpTime
$convert = datestringtodate($lastuptimedate)
$currentdate =(get-wmiobject win32_operatingsystem -Computername $args).localDateTime
$convert1 =datestringtodate($currentdate)
$up =$convert1-$convert
$uptimet = ” System is up for ” + $up.Days + ” Days ” + $up.Hours + ” Hours ” + $up.Minutes + ” Minutes ” + $up.Milliseconds + ” Milliseconds”
$uptimet
}
#End of the script
 
I hope it helps you all!

Physical Memory Capacity using Powershell and WMI

A small Script to fetch Physical Memory installed/mounted on the host as below. It gives you the Slots,DIMM number and capacity of the RAM in GB for the Remote Hosts using WMI. Copy the below contents [ In Green] to the notepad and save it as .ps1 file with name of your choice.
How to Run:
  • Run PowerShell from start—>Run—>Type PowerShell and hit Enter
  • Go the location where the script file is saved. CD “location path”
  • type .\filename.ps1 “Hostname”
Ex: .\filename.ps1 shashank where, .\filename.ps1 is script and shashank is the host for which you want to compute the Physical Memory Availability.
#Author:Shashanka Haritsa @ February 2011
#Script will fetch DIMMS and their Physical Memory Capacity
$count = 0
$memories = get-wmiobject win32_physicalmemory -computername $args
“=====================================================”
foreach ($Dimm in $memories){
$Dimm.BankLabel + ” ” + $Dimm.DeviceLocator +” Capacity = ” + $Dimm.Capacity/(1024*1024*1024) + “GB”
$Count = $Count + 1
}
“=====================================================”
“Found Totally ” + $Count + ” Installed Memory Modules”
“=====================================================”
I hope this helps to gather the information required from Remote hosts in Faster way.