Techibee.com

Get Operating System architecture(32-bit or 64-bit) using powershell

Updated on 2/13/2012 with a more robust function to get OS architecture and details.

After introduction of windows 7 and 2008, use of 64-bit operating systems have increased. Today I came across a requirement to generate list of servers which are running with 32-bit operating system and 64-bit operating system. I look at OperatingSystem attribute value of active directory objects, but that doesn’t have sufficient information. I did bit more research and came-up with below powershell script which works for windows XP, 2003, 7, 2008.

Code:

function Get-OSArchitecture {            
[cmdletbinding()]            
param(            
    [parameter(ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true)]            
    [string[]]$ComputerName = $env:computername                        
)            

begin {}            

process {            

 foreach ($Computer in $ComputerName) {            
  if(Test-Connection -ComputerName $Computer -Count 1 -ea 0) {            
   Write-Verbose "$Computer is 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"            
   }            

   $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            
  }            
 }            
}            

end {}            

}

Usage:

Get-OSArchitecture -ComputerName PC1, PC2, PC3 | ft -auto

Hope this helps..

Exit mobile version