When it comes
to determine on which architecture your script is running right now these 3 solutions
are quite handy
1.environment variable.
write-host "environement variable: $($env:PROCESSOR_ARCHITECTURE)"
little function:
if($env:PROCESSOR_ARCHITECTURE -ne 'x86'){
Write-Host "64bit system detected"
}else{
Write-Host "32bit system detected"
}
fast and easy way but can lead to mistakes. just
open a powershell console in x86 and open up another one in 64bit. now enter: $env:PROCESSOR_ARCHITECTURE in both windows and surprise surprise 2 different results.
2. dot net: my favorite. usually dot net is installed on almost every computer
so it’s quite safe to use and the fact that it returns true or false only is a nice bonus instead of
interpreting strings
write-host "dot net:
$([Environment]::Is64BitOperatingSystem)"
if([Environment]::Is64BitOperatingSystem -eq $true){
Write-Host "64bit system detected"
}else{
Write-Host "32bit system detected"
}
3. the good old
way - WMI. the only thing which keeps me from
using WMI is the fact that it tends to break.
write-host "WMI: $((Get-WmiObject
Win32_OperatingSystem).OSArchitecture)"
if((Get-WmiObject Win32_OperatingSystem).OSArchitecture -eq '64-bit'){
Write-Host "64bit system detected"
}else{
Write-Host "32bit system detected"
}
which one is your favorite? Maybe you have another solution for me. In both cases leave a comment.
No comments:
Post a Comment