Skip to content

Commit 41abaad

Browse files
author
devizer
committed
Update Module: Get-CPU-Architecture-Suffix-for-Windows without WMI [skip ci]
1 parent eb2c92a commit 41abaad

2 files changed

Lines changed: 45 additions & 2 deletions

File tree

Install-SqlServer-Version-Management.ps1

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Param(
44
)
55

66
$ModuleName = 'SqlServer-Version-Management';
7-
$ModuleVersion = '2.1.184';
7+
$ModuleVersion = '2.1.185';
88
$ModuleFiles = @(
99
@{
1010
FileName = 'SqlServer-Version-Management\SqlServer-Version-Management.psd1';
@@ -15,7 +15,7 @@ $ModuleFiles = @(
1515
" ModuleToProcess = @('SqlServer-Version-Management.psm1')",
1616
"",
1717
" # Version below is automatically incremented on build",
18-
" ModuleVersion = `"2.1.184`"",
18+
" ModuleVersion = `"2.1.185`"",
1919
"",
2020
" GUID = 'dd03b53d-575a-4056-ae08-e6dfea3384ea'",
2121
"",
@@ -764,6 +764,8 @@ $ModuleFiles = @(
764764
"",
765765
"# x86 (0), MIPS (1), Alpha (2), PowerPC (3), ARM (5), ia64 (6) Itanium-based systems, x64 (9), ARM64 (12)",
766766
"function Get-CPU-Architecture-Suffix-for-Windows-Implementation() {",
767+
" `$ret = Get-OS-Architecture-by-Registry",
768+
" if (`$ret) { return `$ret; }",
767769
" # on multiple sockets x64",
768770
" `$proc = Select-WMI-Objects `"Win32_Processor`";",
769771
" `$a = (`$proc | Select -First 1).Architecture",
@@ -790,6 +792,25 @@ $ModuleFiles = @(
790792
" return `$Global:CPUArchitectureSuffixforWindows",
791793
"}",
792794
"",
795+
"function Get-OS-Architecture-by-Registry {",
796+
" `$regPath = `"HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment`"",
797+
" `$valueName = `"PROCESSOR_ARCHITECTURE`"",
798+
" `$rawArch = `$null",
799+
"",
800+
" try {",
801+
" if (Test-Path `$regPath) { `$rawArch = (Get-ItemProperty -Path `$regPath -Name `$valueName -ErrorAction SilentlyContinue).`$valueName }",
802+
" } catch { `$rawArch = `$null }",
803+
"",
804+
" switch (`$rawArch) {",
805+
" `"AMD64`" { return `"x64`" }",
806+
" `"x86`" { return `"x86`" }",
807+
" `"ARM64`" { return `"arm64`" }",
808+
" `"ARM`" { return `"arm`" }",
809+
" `"IA64`" { return `"ia64`" }",
810+
" `"EM64T`" { return `"x64`" }",
811+
" }",
812+
"}",
813+
"",
793814
"# Include File: [\Includes\Get-Cpu-Name.ps1]",
794815
"function Get-Cpu-Name-Implementation {",
795816
" `$platform = Get-Os-Platform",
@@ -4281,6 +4302,7 @@ $ModuleFiles = @(
42814302
"Export-ModuleMember -Function Get-Aria2c-Exe-FullPath-for-Windows",
42824303
"Export-ModuleMember -Function Get-Builtin-Windows-Group-Name",
42834304
"Export-ModuleMember -Function Get-CPU-Architecture-Suffix-for-Windows",
4305+
"Export-ModuleMember -Function Get-OS-Architecture-by-Registry",
42844306
"Export-ModuleMember -Function Get-Cpu-Name",
42854307
"Export-ModuleMember -Function Get-Folder-Size",
42864308
"Export-ModuleMember -Function Get-Full7z-Exe-FullPath-for-Windows",

SqlServer-Version-Management.ps1

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,8 @@ function Get-Aria2c-Exe-FullPath-for-Windows([string] $arch) {
631631

632632
# x86 (0), MIPS (1), Alpha (2), PowerPC (3), ARM (5), ia64 (6) Itanium-based systems, x64 (9), ARM64 (12)
633633
function Get-CPU-Architecture-Suffix-for-Windows-Implementation() {
634+
$ret = Get-OS-Architecture-by-Registry
635+
if ($ret) { return $ret; }
634636
# on multiple sockets x64
635637
$proc = Select-WMI-Objects "Win32_Processor";
636638
$a = ($proc | Select -First 1).Architecture
@@ -657,6 +659,25 @@ function Get-CPU-Architecture-Suffix-for-Windows() {
657659
return $Global:CPUArchitectureSuffixforWindows
658660
}
659661

662+
function Get-OS-Architecture-by-Registry {
663+
$regPath = "HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment"
664+
$valueName = "PROCESSOR_ARCHITECTURE"
665+
$rawArch = $null
666+
667+
try {
668+
if (Test-Path $regPath) { $rawArch = (Get-ItemProperty -Path $regPath -Name $valueName -ErrorAction SilentlyContinue).$valueName }
669+
} catch { $rawArch = $null }
670+
671+
switch ($rawArch) {
672+
"AMD64" { return "x64" }
673+
"x86" { return "x86" }
674+
"ARM64" { return "arm64" }
675+
"ARM" { return "arm" }
676+
"IA64" { return "ia64" }
677+
"EM64T" { return "x64" }
678+
}
679+
}
680+
660681
# Include File: [\Includes\Get-Cpu-Name.ps1]
661682
function Get-Cpu-Name-Implementation {
662683
$platform = Get-Os-Platform

0 commit comments

Comments
 (0)