Powershell에서 32/64비트 결정
시스템이 32/64비트이면 WMI에서 꺼낼 몇 줄의 코드를 만들고 64비트이면 이 작업을 수행합니다. 32비트이면 이 작업을 수행합니다.
누가 도와줄 수 있습니까?
Environment에는 두 가지 부울 정적 방법이 있습니다. 하나는 PowerShell 프로세스를 살펴보고, 하나는 기본 OS를 검사하고 비교할 수 있습니다.
if ([Environment]::Is64BitProcess -ne [Environment]::Is64BitOperatingSystem)
{
"PowerShell process does not match the OS"
}
최소한 Windows 7(윈도우 7)을 실행하고 있다고 가정하면 다음과 같은 작업이 가능합니다.
64비트 기계에서 실행되는 32비트 버전의 파워셸에서 나에게 적합한 샘플을 포함하면 다음과 같습니다.
Get-WmiObject win32_operatingsystem | select osarchitecture
64비트에 대해 "64비트"를 반환합니다.
if ((Get-WmiObject win32_operatingsystem | select osarchitecture).osarchitecture -eq "64-bit")
{
#64 bit logic here
Write "64-bit OS"
}
else
{
#32 bit logic here
Write "32-bit OS"
}
이는 이전 답변과 유사하지만 64비트/64_비트/64비트/64비트 형식에 관계없이 올바른 결과를 얻을 수 있습니다.
if ((Get-WmiObject win32_operatingsystem | select osarchitecture).osarchitecture -like "64*")
{
#64bit code here
Write "64-bit OS"
}
else
{
#32bit code here
Write "32-bit OS"
}
멋진 한 줄을 위해 두 줄이 함께 부서졌습니다.
Write-Host "64bit process?:"$([Environment]::Is64BitProcess) ;Write-Host "64bit OS?:"$([Environment]::Is64BitOperatingSystem);
[IntPtr]::Size -eq 4 # 32 bit
IntPtr의 크기는 32비트 시스템에서 4바이트, 64비트 시스템에서 8바이트가 됩니다(https://msdn.microsoft.com/en-us/library/system.intptr.size.aspx) .
if($env:PROCESSOR_ARCHITECTURE -eq "x86"){"32-Bit CPU"}Else{"64-Bit CPU"}
-edit, 미안하지만 사용법을 설명하기 위해 코드를 더 포함하는 것을 잊었습니다.
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.
Guvante의 답변을 사용하여 전역 부울 만들기
$global:Is64Bits=if((gwmi win32_operatingsystem | select osarchitecture).osarchitecture -eq "64-bit"){$true}else{$false}
부울 값(예: 에 의해 반환된 값)을 필터링할 필요가 없습니다.-Eq
연산자) 를 통해 "If
” 또는 부울 값 또는 식을 다음과 비교합니다.$True
아니면$False
.
Jose의 One-liner는 다음과 같이 단순화됩니다.
$global:Is64Bits=(gwmi win32_operatingsystem | select osarchitecture).osarchitecture -eq "64-bit"
언급URL : https://stackoverflow.com/questions/31977657/determining-32-64-bit-in-powershell
'source' 카테고리의 다른 글
CREATE 명령이 사용자에게 거부됨 (0) | 2023.10.31 |
---|---|
mysql은 int를 통화로 선택하거나 통화 형식으로 변환합니까? (0) | 2023.10.31 |
GLib 기능을 사용하는 이유는 무엇입니까? (0) | 2023.10.31 |
Swift 프로토콜 오류: 클래스 유형이 아닌 경우 'weak'을(를) 적용할 수 없습니다. (0) | 2023.10.26 |
C#에서 HTTP Post 데이터를 가져오는 방법? (0) | 2023.10.26 |