Blog Post

PowerSQL – Find OS and Memory Usage Details – Multi Server Script – No Input files

,

Multi Server script to find OS and Memory details.  It doesn’t require a text file as its input but you have to pass computer names as its parameters which are separated by comma.

function Get-OSMemory {

param(

[string[]]$ComputerName = “.”

)

foreach ($Computer in $ComputerName) {

if(Test-Connection -ComputerName $Computer -Count 1 -ea 0) {

Write-Verbose “$Computer online”

$OS = (Get-WmiObject -computername $computer -class Win32_OperatingSystem ).Caption

if ((Get-WmiObject -Class Win32_OperatingSystem -ComputerName $Computer -ea 0).OSArchitecture -eq ’64-bit’)

{

$architecture = “64-Bit”

} else {

$architecture = “32-Bit”

}

$SystemInfo = Get-WmiObject -Class Win32_OperatingSystem -computername $Computer | Select-Object Name, TotalVisibleMemorySize, FreePhysicalMemory

$TotalRAM = $SystemInfo.TotalVisibleMemorySize/1MB

$FreeRAM = $SystemInfo.FreePhysicalMemory/1MB

$UsedRAM = $TotalRAM – $FreeRAM

$RAMPercentFree = ($FreeRAM / $TotalRAM) * 100

$TotalRAM = [Math]::Round($TotalRAM, 2)

$FreeRAM = [Math]::Round($FreeRAM, 2)

$UsedRAM = [Math]::Round($UsedRAM, 2)

$RAMPercentFree = [Math]::Round($RAMPercentFree, 2)

$OutputObj = New-Object -Type PSObject

$OutputObj | Add-Member -MemberType NoteProperty -Name ComputerName -Value $Computer.ToUpper()

$OutputObj | Add-Member -MemberType NoteProperty -Name Architecture -Value $architecture

$OutputObj | Add-Member -MemberType NoteProperty -Name OperatingSystem -Value $OS

$OutputObj | Add-Member -MemberType NoteProperty -Name TotalRAM -Value $TotalRAM

$OutputObj | Add-Member -MemberType NoteProperty -Name FreeRAM -Value $FreeRAM

$OutputObj | Add-Member -MemberType NoteProperty -Name UsedRAM -Value $UsedRAM

$OutputObj | Add-Member -MemberType NoteProperty -Name FreeRAMPer -Value $RAMPercentFree

$OutputObj

}

}

}

Execution Details:-

  1. PS:\>Get-OSMemory
  2. PS:\>Get-OSMemory  AQDBSP18
  3. PS:\>Get-OSMemory AQDBSP18,AQDBSP17,AQDBSP1

You can download the code here Code-OSMemory

Output: -

Image

Rate

You rated this post out of 5. Change rating

Share

Share

Rate

You rated this post out of 5. Change rating