powershell决定os架构

时间:2014-07-07 11:45:45

标签: powershell

我有这个代码的问题,它写x86操作系统,eventhoug write-host = $ OSArchitecture,states = 64-bit

    $OSArchitecture = (Get-WmiObject -Class Win32_OperatingSystem | Select-Object    OSArchitecture -ErrorAction Stop).OSArchitecture
write-host = $OSArchitecture

if ($OSArchitecture -eq '*64*') 
    {
        Write-Host "x64 operating system" 
        $Version = Get-ChildItem hklm:\software\wow6432node\microsoft\windows\currentversion\uninstall | ForEach-Object {Get-ItemProperty $_.pspath} | Where-Object {
        $_.DisplayName -Eq 'Microsoft Lync 2013'} | Select-Object DisplayVersion
    } 
    else 
    {
        Write-Host "x86 operating system"
        $Version = Get-ChildItem hklm:\software\microsoft\windows\currentversion\uninstall | ForEach-Object {Get-ItemProperty $_.pspath} | Where-Object {
        $_.DisplayName -Eq 'Microsoft Lync 2013'} | Select-Object DisplayVersion 
    }

提前致谢。

我收到此错误:无法将“System.Object []”类型的“System.Object []”值转换为“System.Int32”类型。

3 个答案:

答案 0 :(得分:1)

在x64系统[Environment]::Is64BitOperatingSystem上提供$true

答案 1 :(得分:0)

您可以将此用于此作业

if ([System.IntPtr]::Size -eq 4) { "32-bit" } else { "64-bit" }

或更改代码

if ($OSArchitecture -match '64') 

答案 2 :(得分:0)

正确的代码。

layout-w600dp-h600dp