Skip to content

Commit f34f9c8

Browse files
nohwndCopilot
andcommitted
Fix #2678: Suppress Get-CimInstance access denied error
Copilot-generated fix. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent d5f7c87 commit f34f9c8

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

src/functions/TestResults.ps1

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -468,10 +468,10 @@ function Get-RunTimeEnvironment {
468468
$computerName = $env:ComputerName
469469
$userName = $env:Username
470470
if ($null -ne $SafeCommands['Get-CimInstance']) {
471-
$osSystemInformation = (& $SafeCommands['Get-CimInstance'] Win32_OperatingSystem)
471+
$osSystemInformation = (& $SafeCommands['Get-CimInstance'] Win32_OperatingSystem -ErrorAction Ignore)
472472
}
473473
elseif ($null -ne $SafeCommands['Get-WmiObject']) {
474-
$osSystemInformation = (& $SafeCommands['Get-WmiObject'] Win32_OperatingSystem)
474+
$osSystemInformation = (& $SafeCommands['Get-WmiObject'] Win32_OperatingSystem -ErrorAction Ignore)
475475
}
476476
elseif ($IsMacOS -or $IsLinux) {
477477
$osSystemInformation = @{
@@ -492,7 +492,9 @@ function Get-RunTimeEnvironment {
492492
# well, we tried
493493
}
494494
}
495-
else {
495+
496+
# Fall back to unknown values if WMI/CIM returned null (e.g. access denied when not running as Administrator)
497+
if ($null -eq $osSystemInformation) {
496498
$osSystemInformation = @{
497499
Name = 'Unknown'
498500
Version = '0.0.0.0'

0 commit comments

Comments
 (0)