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

About these ads

About Prashanth Jayaram

I’m a Database technologist having 8+ years of rich, hands-on experience on Database technologies. I am Microsoft Certified Professional and backed with a Degree in Master of Computer Application. My expertise lies in T-SQL programming, Replication and PowerShell. hobbies are playing sports and drawing.
This entry was posted in PowerShell and tagged , , , . Bookmark the permalink.

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

  1. david says:

    Would you be interested in exchanging links?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s