Determining 32/64 bit in Powershell

前端 未结 6 1962
梦谈多话
梦谈多话 2021-01-02 04:14

I am trying to create a couple lines of code that will pull from WMI if a machine is either 32/64 bit and then if it is 64 do this .... if it is 32bit do this...

Can

6条回答
  •  清歌不尽
    2021-01-02 04:57

    if($env:PROCESSOR_ARCHITECTURE -eq "x86"){"32-Bit CPU"}Else{"64-Bit CPU"}
    

    -edit, sorry forgot to include more code to explain the usage.

    if($env:PROCESSOR_ARCHITECTURE -eq "x86")
     {
    #If the powershell console is x86, create alias to run x64 powershell console.
     set-alias ps64 "$env:windir\sysnative\WindowsPowerShell\v1.0\powershell.exe"
    
    $script2=[ScriptBlock]::Create("#your commands here, bonus is the script block expands variables defined above")
    
    ps64 -command $script2
     }
     Else{
     #Otherwise, run the x64 commands.
    

提交回复
热议问题