Sunday, 30 July 2017

GET-Memory Useage function

Created a function to check the memory usage  on multiple servers



 Function Get-MemoryUsage ($ComputerName=$ENV:ComputerName) {
[cmdletbinding()]
$os = Get-Ciminstance Win32_OperatingSystem -ComputerName $ComputerName
$totalvisibleMemmorysize=$os.TotalvisibleMemmorysize
$pctFree = [math]::Round(($os.FreePhysicalMemory/$os.TotalVisibleMemorySize)*100,2)
$ser=$os.CSName

if ($pctFree -ge 45) {
$Status = "OK"
}
elseif ($pctFree -ge 15 ) {
$Status = "Warning"
}
else {
$Status = "Critical"
}

$os | Select @{Name = "Servername";Expression = {$ser}},
 @{Name = "TotalGB";Expression = {[int]($_.TotalVisibleMemorySize/1mb)}},
@{Name = "FreeGB";Expression = {[math]::Round($_.FreePhysicalMemory/1mb,2)}},
@{Name = "PctFree%"; Expression = {$pctFree}},@{Name = "Status";Expression = {$Status}} | Format-Table -AutoSize
}



Sunday, 2 July 2017

 Getting System Up time in Customized display

# Getting System Up time in Customized display
#Using this Script you can get the uptime of  multiple servers
#save the servers list in notepad with  out spaces.it will use to save the time if you want query the uptime of bulk servers.Please contact me for for any sugesstions and feedback





function get-uptime {
param(
$computername =$env:computername
)

$os = Get-WmiObject win32_operatingsystem -ComputerName $computername -ea silentlycontinue
if($os){
$lastbootuptime =$os.ConvertTodateTime($os.LastBootUpTime)

$LocalDateTime =$os.ConvertTodateTime($os.LocalDateTime)

$up =$LocalDateTime - $lastbootuptime

$uptime ="$($up.Days) days, $($up.Hours)h, $($up.Minutes)mins"

$results =new-object psobject

$results |Add-Member noteproperty LastBootUptime $LastBootuptime
$results |Add-Member noteproperty ComputerName $computername
$results |Add-Member noteproperty uptime $uptime


#Display the results

$results | Select-Object computername,LastBootuptime,Uptime

}


else

{

$results =New-Object psobject

$results =new-object psobject
$results |Add-Member noteproperty LastBootUptime "Na"
$results |Add-Member noteproperty ComputerName $computername
$results |Add-Member noteproperty uptime "Na"

#display the results

$results | Select-Object computername,LastBootUptime,Uptime




}



}

$infouptime =@()


foreach($allserver in $allservers){

$infouptime += get-uptime $allserver
}

$infouptime




###############################################

#Getting Computers source


$servers =Get-Content C:\servers.txt

foreach ($server in $servers)

{

get-uptime -computername $server

}



Powershell function to get theremote server IP details,Subnetmask,Gateway,DHCP Enabled status,DNS Servers,Wins and Macaddress

#Powershell function to get theremote server IP details,Subnetmask,Gateway,DHCP Enabled status,DNS Servers,Wins and Macaddress # use...