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..
Comments on this entry are closed.
Hi,
On Windows Server 2003, the (get-wmiobject win32_operatingsystem).Caption command won’t give you any relevant information about the OS architecture. Unfortunately.
I tried it on a Server 2003 Std 32-bit and I got this: “Microsoft(R) Windows(R) Server 2003, Standard Edition”. I tried on Server 2003×64 as well and I got this: “Microsoft(R) Windows(R) Server 2003 Standard x64 Edition”. So I would not say that it is a right solution. Until now I didn’t find the right way how could I determine the architecture of my Server 2003.
On Server 2008Sp1 and R2 I use the (get-wmiobject win32_operatingsystem).OSArcitecture. It works properly. I recommend it.
@supi007, Whatever you said is correct. However, the code “(get-wmiobject win32_operatingsystem).Caption” returning is in fact having the version of Operating System. In case of 64-bit OS, you have in the returned value. In case of 32-bit, the returned value will not contain either 64 or 32-bit indication which means by default it is 32-bit. Only thing you need to do is, parse the code output and mark it as 64-bit if “x64” is found in string, otherwise it is 32-bit.
Hope this explanation helps.
A simpler method is to look at the address width as follows:
$Processor = Get-WmiObject Win32_Processor -ComputerName SERVER -namespace rootcimv2 | where {$_.DeviceID -eq “CPU0”} | select AddressWidth
$Processor.AddressWidth will return 32 or 64, which will tell you what architecture it is. Limiting it to “CPU0” makes sure you get just one 32 or 64 no matter how many processors there are. Works for Windows 2000 and up.
@Dave D –
The original example reports the OS architecture… Unless I misunderstand, you’re reporting the Processor architecture. They may not be the same, since you can run 32-bit Windows on 64-bit processors.
There are cases where you might want to know either piece of information, but they’re not necessarily the same thing.
Actually, I was wrong… looks like Dave D’s method will return the OS architecture correctly.
Back to lurking…
All of them are working properly. However, i would like to know if we can get the version of OS if it is R2. When i run this for Windows 2003 R2, it doesnt show up in the output.
Can some check this ?
try Get-WmiObject -Class Win32_OperatingSystem | Select OtherTypeDescription
that property will only be populated if running Server 2003 R2.
Function gives random result,for 2003 gave 2008 and for some 32 bit gave 64 bit
great work. thanx a lot for the function.
what about something like this inside your For-Each loop?
$Architecuture = ($env:PROCESSOR_ARCHITECTURE)
Maybe this will work on a wider variety of occasions:
(Get-WmiObject -Class Win32_ComputerSystem).SystemType -match ‘(x64)’
Get absolutely nothing when I run this script except a return to the CLI. What am I missing?
Its a PS function. So after you copy paste, it will be obviously return to CLI. That completes the function import operation. To use it just call the function from the window.
Get-OSArchitecture -ComputerName PC1, PC2, PC3 | ft -auto
Don’t you have something that can query AD by OU and then pipe it to the script. I am new to PowerShell and I get that the reason I came up blank on running it was because I am suppose to supply the list of systems. However, that is the whole point, who knows what is out there? I need to know how to extract the systems in our organization and have this script execute against it. How can that be done?
Get-OSArchitecture -ComputerName (get-content c:\temp\servers.txt)
Keep all your severs in servers.txt before you execute the above
How would i return a value from that function?
I have tried [ref]$value = $architecture, but having no luck
any ideas?
I want to use that return value (or object.value) as input to another function.
sorry it was this simple: (new to powershell)
PS H:\> $OSArch = Get-OSArchitecture -ComputerName Computer
PS H:\> $OSArch.architecture
64-Bit
I am still learning the ways of Powershell, and am looking for some help modifying the $outputfile. I am able to get the script to read a list of computers (ComputerName is the header) from a csv, but I would like for the output to be a separate file for each computer. I will be running this against 1,000’s of workstations and find it to be easier to look for one small file compared to comping through one potentially very large file.
Hopefully someone is still watching this thread and can reply. Either way, thank you for this excellent write-up!
I’m sorry, I posted my previous comment on the wrong thread. It was meant to go over here: http://techibee.com/powershell/powershell-script-to-query-softwares-installed-on-remote-computer/1389
Working perfect, thanks for sharing.
I am new to powershell and i want to check if some targeted computers can have windows 10 installed. To see this i want to check if they can support x64 bit architecture even if they currently they are x86.
How can i do it?
Hi,
Microsoft already provided a script to check for Upgrade readiness. Have you tried it?
I don’t have a script available to check Processor architecture. I will do it in future posts.
https://docs.microsoft.com/en-us/windows/deployment/upgrade/upgrade-readiness-deployment-script
I’m trying to get the results for a filtered list of machines using Get-OSArchitecture function.
Tried Get-OSArchitecture -ComputerName (get-adcomputer -filter {Name -like “*OPS*”} )
and
$a = get-adcomputer -filter {Name -like “*OPS*”} | select Name
Get-OSArchitecture -ComputerName $a
neither worked.
Any ideas?
Hi,
Both the methods you have tried has a problem. Instead of passing Computername as argument you are passing computer object itself which doesn’t work.
Try below methods and let me know how it goes.
First verify your AD query and ensure it is returning computer names only.
$a = get-adcomputer -filter {Name -like “*OPS*”} | select -expandproperty Name
Write-Host $a
It should be a array without any header.
Then pass it to Get-OSArchitecture -ComputerName $a
It should work.
That worked! Thanks very much for your help. Dan.
trying to get the results into a csv file with seperate columns for Computername,Architecture but its putting the results in the same column.
This is what I’m doing:
$d = Get-ADComputer -filter * | select -ExpandProperty Name
Get-OSArchitecture -ComputerName $d | select name,architecture | ft -auto >> out3.csv
Sorry, new enough to powershell.
Great coding by the way
sorry, here’s what im using
$d = Get-ADComputer -filter * | select -ExpandProperty Name
Get-OSArchitecture -ComputerName $d | select computername,architecture >> out6.csv
Hi,
Try this.
Get-OSArchitecture -ComputerName $d | select computername,architecture | out-cdv c:\temp\mycsv.csv -NoTypeInformation