#requires -Version 5.1 [CmdletBinding()] param( [string]$InstallPath, [switch]$SkipWsl, [ValidateRange(1, 30)][int]$CommandTimeoutSeconds = 8 ) # ASCII source works without a BOM on Windows PowerShell 5.1 as well as PS7. # Dot-sourcing exposes functions for offline tests without collecting host data. function New-SetupCheck { param([string]$Status, [string]$Reason, $Evidence = @{}) [pscustomobject][ordered]@{ status = $Status; reason = $Reason; evidence = $Evidence } } function Get-FailureKind { param($ErrorValue) $message = [string]$ErrorValue if ($message -match 'denied|unauthorized|permission|blocked by security policy|program blacklist|blocked for security|0x80070005|0x80041003|access is|\u62d2\u7edd|\u6743\u9650') { return 'permission-denied' } return 'unknown' } function Get-SetupCommand { param([string]$Name) $discoveryErrors = @() $command = Get-Command $Name -CommandType Application -ErrorAction SilentlyContinue -ErrorVariable discoveryErrors | Select-Object -First 1 foreach ($failure in $discoveryErrors) { if ($failure.Exception -isnot [System.Management.Automation.CommandNotFoundException]) { throw $failure } } if ($command) { return $command.Source } # Newly installed Docker/NVIDIA tools may not be in this terminal's PATH. $candidates = @() if ($Name -eq 'docker.exe') { $candidates = @( "$env:LOCALAPPDATA\Programs\DockerDesktop\resources\bin\docker.exe", "$env:ProgramFiles\Docker\Docker\resources\bin\docker.exe" ) } elseif ($Name -eq 'nvidia-smi.exe') { $candidates = @("$env:SystemRoot\System32\nvidia-smi.exe", "$env:ProgramFiles\NVIDIA Corporation\NVSMI\nvidia-smi.exe") } foreach ($candidate in $candidates) { if (Test-Path -LiteralPath $candidate -PathType Leaf -ErrorAction Stop) { return $candidate } } return $null } function Invoke-SetupNative { param([string]$File, [string[]]$Arguments, [int]$TimeoutSeconds = 8, [switch]$PinnedDocker) # Arguments are static tokens or a context name passed as one quoted token; never a shell command. $info = New-Object System.Diagnostics.ProcessStartInfo $info.FileName = $File $quoted = foreach ($argument in $Arguments) { '"' + ([regex]::Replace(([regex]::Replace($argument, '(\\*)"', '$1$1\"')), '(\\+)$', '$1$1')) + '"' } $info.Arguments = $quoted -join ' ' $info.UseShellExecute = $false $info.CreateNoWindow = $true $info.RedirectStandardOutput = $true $info.RedirectStandardError = $true if ($PinnedDocker) { # Prevent an inherited context or TLS override from redirecting the pinned local query. foreach ($name in @('DOCKER_CONTEXT', 'DOCKER_HOST', 'DOCKER_TLS_VERIFY', 'DOCKER_CERT_PATH', 'DOCKER_API_VERSION')) { $info.EnvironmentVariables.Remove($name) } } $process = New-Object System.Diagnostics.Process $process.StartInfo = $info try { [void]$process.Start() $stdout = $process.StandardOutput.ReadToEndAsync() $stderr = $process.StandardError.ReadToEndAsync() if (-not $process.WaitForExit($TimeoutSeconds * 1000)) { # Kill only our query process; never a daemon, container or existing user process. $process.Kill() return @{ status = 'unknown'; reason = 'timeout'; output = ''; exitCode = $null } } if (-not $stdout.Wait(1000) -or -not $stderr.Wait(1000)) { return @{ status = 'unknown'; reason = 'output-timeout'; output = ''; exitCode = $process.ExitCode } } # WSL emits UTF-16 on some Windows releases despite redirected console encoding. $output = $stdout.Result.Replace([string][char]0, '').Trim().TrimStart([char]0xFEFF) if ($process.ExitCode -eq 0) { return @{ status = 'pass'; reason = 'query-succeeded'; output = $output; exitCode = 0 } } $failureText = $stderr.Result + $output $kind = Get-FailureKind $failureText $reason = 'query-failed' if ($kind -eq 'permission-denied') { $reason = 'access-denied' } elseif ($failureText -match 'cannot connect|connection refused|is the docker daemon running|open //\./pipe/.*(?:file|path).*not find') { $reason = 'connection-unavailable' } elseif ($failureText -match '(?:communicate with|initialize).*NVIDIA.*driver|driver.*not loaded') { $reason = 'driver-unavailable' } return @{ status = $kind; reason = $reason; output = ''; exitCode = $process.ExitCode } } catch { return @{ status = (Get-FailureKind $_); reason = 'query-failed'; output = ''; exitCode = $null } } finally { $process.Dispose() } } function Get-SetupCim { param([string]$ClassName, [string]$Filter) $options = @{ ClassName = $ClassName; OperationTimeoutSec = 5; ErrorAction = 'Stop' } if ($Filter) { $options.Filter = $Filter } Get-CimInstance @options } function Get-WindowsSetupCheck { try { $os = Get-SetupCim Win32_OperatingSystem $architecture = $env:PROCESSOR_ARCHITEW6432 if (-not $architecture) { $architecture = $env:PROCESSOR_ARCHITECTURE } $remote = $null -ne (Get-Variable PSSenderInfo -ValueOnly -ErrorAction SilentlyContinue) $evidence = @{ version = $os.Version; build = $os.BuildNumber; architecture = $architecture; productType = $os.ProductType; remoteSession = $remote } if ($architecture -ne 'AMD64' -or $os.ProductType -ne 1 -or [int]$os.BuildNumber -lt 10240) { return New-SetupCheck 'incompatible' 'outside-windows-x64-workstation-scope' $evidence } New-SetupCheck 'pass' 'windows-x64-observed-support-must-be-rechecked' $evidence } catch { New-SetupCheck (Get-FailureKind $_) 'windows-query-failed' } } function Get-ResourceSetupChecks { param([string]$TargetPath) try { $system = Get-SetupCim Win32_ComputerSystem $memory = New-SetupCheck 'unknown' 'workload-requirement-unknown' @{ totalBytes = [long]$system.TotalPhysicalMemory } } catch { $memory = New-SetupCheck (Get-FailureKind $_) 'memory-query-failed' } try { $pathToCheck = $env:LOCALAPPDATA if ($TargetPath) { $pathToCheck = [IO.Path]::GetFullPath($TargetPath) } $drive = [IO.Path]::GetPathRoot($pathToCheck).TrimEnd('\') if ($drive -notmatch '^[a-zA-Z]:$') { throw 'unsupported-drive' } $diskInfo = Get-SetupCim Win32_LogicalDisk ("DeviceID='" + $drive + "'") if (-not $diskInfo) { throw 'disk-unavailable' } $disk = New-SetupCheck 'unknown' 'workload-requirement-unknown' @{ drive = $drive; freeBytes = [long]$diskInfo.FreeSpace; sizeBytes = [long]$diskInfo.Size; scope = 'install-drive-only' } } catch { $disk = New-SetupCheck (Get-FailureKind $_) 'disk-query-failed' } @{ memory = $memory; disk = $disk } } function Get-VirtualizationSetupCheck { try { $system = Get-SetupCim Win32_ComputerSystem $cpus = @(Get-SetupCim Win32_Processor) $firmware = @($cpus | ForEach-Object { $_.VirtualizationFirmwareEnabled }) $slat = @($cpus | ForEach-Object { $_.SecondLevelAddressTranslationExtensions }) $evidence = @{ hypervisorPresent = $system.HypervisorPresent; firmwareEnabled = $firmware; slat = $slat } if ($system.HypervisorPresent -eq $true) { return New-SetupCheck 'pass' 'hypervisor-present' $evidence } if ($firmware -contains $false -or $slat -contains $false) { return New-SetupCheck 'incompatible' 'virtualization-disabled-or-unsupported' $evidence } if ($cpus.Count -gt 0 -and $firmware -notcontains $null -and $slat -notcontains $null) { return New-SetupCheck 'pass' 'virtualization-observed' $evidence } New-SetupCheck 'unknown' 'virtualization-not-established' $evidence } catch { New-SetupCheck (Get-FailureKind $_) 'virtualization-query-failed' } } function Get-RestartSetupCheck { $signals = @() try { $keys = @{ cbs = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\RebootPending' windowsUpdate = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired' } foreach ($key in $keys.Keys) { if (Test-Path -LiteralPath $keys[$key] -ErrorAction Stop) { $signals += $key } } if ($signals.Count -gt 0) { return New-SetupCheck 'restart-required' 'pending-reboot-signal' @{ signals = $signals } } New-SetupCheck 'unknown' 'no-known-reboot-signal-not-exhaustive' } catch { New-SetupCheck (Get-FailureKind $_) 'restart-query-failed' } } function Get-WslSetupCheck { param([int]$TimeoutSeconds, [switch]$Skip) if ($Skip) { return New-SetupCheck 'permission-denied' 'wsl-check-skipped-tool-restriction' @{ nativeQuerySkipped = $true } } try { $command = Get-SetupCommand 'wsl.exe' } catch { return New-SetupCheck (Get-FailureKind $_) 'wsl-command-discovery-failed' } $features = @() $featureFailure = $null try { $features = @(Get-SetupCim Win32_OptionalFeature "Name='Microsoft-Windows-Subsystem-Linux' OR Name='VirtualMachinePlatform'" | Select-Object Name, InstallState) } catch { $featureFailure = Get-FailureKind $_ } if (-not $command) { if ($featureFailure) { return New-SetupCheck $featureFailure 'wsl-feature-query-failed' } return New-SetupCheck 'missing' 'wsl-command-not-found' @{ features = $features } } $state = Invoke-SetupNative $command @('--status') $TimeoutSeconds # A denied status query is a boundary, not a reason to try a second WSL command. $versionQuery = @{ status = 'not-run'; output = ''; exitCode = $null } if ($state.status -ne 'permission-denied') { $versionQuery = Invoke-SetupNative $command @('--version') $TimeoutSeconds } $version = $null if ($versionQuery.status -eq 'pass' -and $versionQuery.output -match '(\d+\.\d+\.\d+(?:\.\d+)?)') { $version = $Matches[1] } $evidence = @{ features = $features; featureQueryFailure = $featureFailure; statusQuery = $state.status; statusExitCode = $state.exitCode; versionQuery = $versionQuery.status; version = $version } if ($state.status -ne 'pass') { return New-SetupCheck $state.status ('wsl-' + $state.reason) $evidence } if ($versionQuery.status -eq 'permission-denied') { return New-SetupCheck 'permission-denied' 'wsl-version-query-denied' $evidence } if ($featureFailure -eq 'permission-denied') { return New-SetupCheck 'permission-denied' 'wsl-feature-query-failed' $evidence } if ($features.InstallState -contains 2 -or $features.InstallState -contains 3) { return New-SetupCheck 'missing' 'wsl-feature-disabled' $evidence } # A successful --status alone does not establish WSL2 capability/version. if (-not $version) { return New-SetupCheck 'unknown' 'wsl-version-not-established' $evidence } New-SetupCheck 'pass' 'wsl-observed-check-current-backend-requirements' $evidence } function Get-GpuSetupCheck { param([int]$TimeoutSeconds) $hardware = @() $hardwareFailure = $null try { # Vendor IDs still identify hardware when the display driver only supplies a generic name. # Never serialize the complete PNP device ID (it can contain identifying instance data). $hardware = @(Get-SetupCim Win32_VideoController | Select-Object Name, DriverVersion, ConfigManagerErrorCode, @{ Name = 'vendor'; Expression = { if ($_.PNPDeviceID -match '^PCI\\VEN_10DE') { 'NVIDIA' } elseif ($_.PNPDeviceID -match '^PCI\\VEN_1002') { 'AMD' } elseif ($_.PNPDeviceID -match '^PCI\\VEN_8086') { 'Intel' } else { 'unknown' } } }) } catch { $hardwareFailure = Get-FailureKind $_ } $nvidia = @($hardware | Where-Object { $_.Name -match 'NVIDIA' -or $_.vendor -eq 'NVIDIA' }) try { $command = Get-SetupCommand 'nvidia-smi.exe' } catch { return New-SetupCheck (Get-FailureKind $_) 'gpu-command-discovery-failed' } $evidence = @{ hardware = $hardware; hardwareQueryFailure = $hardwareFailure; toolFound = [bool]$command; devices = @(); minimumDriverMajor = 575; minimumWindowsDriverVersion = '576.57'; cudaBaseline = '12.9.1' } if (-not $command) { if ($hardwareFailure) { return New-SetupCheck $hardwareFailure 'gpu-hardware-query-failed' $evidence } $knownOtherHardware = @($hardware | Where-Object { $_.vendor -in @('AMD', 'Intel') }) if ($knownOtherHardware.Count -gt 0 -and $nvidia.Count -eq 0) { return New-SetupCheck 'missing' 'nvidia-hardware-not-detected' $evidence } if ($nvidia.Count -gt 0) { return New-SetupCheck 'unknown' 'nvidia-tool-unavailable-driver-not-established' $evidence } return New-SetupCheck 'unknown' 'gpu-hardware-not-established' $evidence } $result = Invoke-SetupNative $command @('--query-gpu=name,driver_version,memory.total', '--format=csv,noheader,nounits') $TimeoutSeconds if ($result.status -ne 'pass') { return New-SetupCheck $result.status ('gpu-' + $result.reason) $evidence } $devices = @() foreach ($line in ($result.output -split '\r?\n')) { $parts = @($line -split ',' | ForEach-Object { $_.Trim() }) if ($parts.Count -ne 3 -or $parts[1] -notmatch '^\d+(\.\d+)+$' -or $parts[2] -notmatch '^\d+(\.\d+)?$') { return New-SetupCheck 'unknown' 'gpu-output-not-established' $evidence } $driver = $null if (-not [version]::TryParse($parts[1], [ref]$driver)) { return New-SetupCheck 'unknown' 'gpu-output-not-established' $evidence } $devices += @{ name = $parts[0]; driverVersion = $parts[1]; driverMajor = $driver.Major; memoryMiB = [double]::Parse($parts[2], [Globalization.CultureInfo]::InvariantCulture) } } $evidence.devices = $devices if ($devices.Count -eq 0) { return New-SetupCheck 'unknown' 'gpu-output-not-established' $evidence } if (@($devices | Where-Object { $_.driverMajor -lt 575 }).Count -gt 0) { return New-SetupCheck 'incompatible' 'nvidia-driver-major-too-old' $evidence } if (@($devices | Where-Object { [version]$_.driverVersion -lt [version]'576.57' }).Count -gt 0) { return New-SetupCheck 'incompatible' 'nvidia-driver-below-cuda-baseline' $evidence } New-SetupCheck 'pass' 'host-nvidia-driver-baseline-met-container-gpu-untested' $evidence } function Get-DockerSetupCheck { param([int]$TimeoutSeconds) try { $command = Get-SetupCommand 'docker.exe' } catch { return New-SetupCheck (Get-FailureKind $_) 'docker-command-discovery-failed' } if (-not $command) { return New-SetupCheck 'missing' 'docker-cli-not-found' } $client = Invoke-SetupNative $command @('--version') $TimeoutSeconds $evidence = @{ cli = $client.status; endpointKind = 'unresolved'; serverVersion = $null; osType = $null; backend = 'unverified'; containerGpu = 'untested' } if ($client.status -ne 'pass') { return New-SetupCheck $client.status ('docker-cli-' + $client.reason) $evidence } $endpoint = $null $context = $env:DOCKER_CONTEXT if (-not $context -and $env:DOCKER_HOST) { $endpoint = $env:DOCKER_HOST } else { if (-not $context) { $selected = Invoke-SetupNative $command @('context', 'show') $TimeoutSeconds if ($selected.status -ne 'pass') { return New-SetupCheck $selected.status 'docker-context-unresolved' $evidence } if (-not $selected.output) { return New-SetupCheck 'unknown' 'docker-context-unresolved' $evidence } $context = $selected.output } if ($context -notmatch '^[a-zA-Z0-9][a-zA-Z0-9_.-]{0,127}$') { return New-SetupCheck 'unknown' 'docker-context-name-unverified' $evidence } $inspection = Invoke-SetupNative $command @('context', 'inspect', $context, '--format', '{{json .Endpoints.docker.Host}}') $TimeoutSeconds if ($inspection.status -ne 'pass') { return New-SetupCheck $inspection.status 'docker-context-inspect-failed' $evidence } try { $endpoint = $inspection.output | ConvertFrom-Json -ErrorAction Stop } catch { return New-SetupCheck 'unknown' 'docker-context-output-invalid' $evidence } } # No remote or arbitrary local server query. Pin a recognized Windows Docker pipe. if ($endpoint -notin @('npipe:////./pipe/docker_engine', 'npipe:////./pipe/dockerDesktopLinuxEngine', 'npipe:////./pipe/dockerDesktopWindowsEngine')) { $evidence.endpointKind = 'nonlocal-or-unverified' return New-SetupCheck 'incompatible' 'nonlocal-or-unverified-endpoint' $evidence } $evidence.endpointKind = 'known-local-pipe' $server = Invoke-SetupNative $command @('--host', $endpoint, 'info', '--format', '{{json .}}') $TimeoutSeconds -PinnedDocker if ($server.status -ne 'pass') { return New-SetupCheck $server.status ('local-engine-' + $server.reason) $evidence } try { $data = $server.output | ConvertFrom-Json -ErrorAction Stop } catch { return New-SetupCheck 'unknown' 'docker-server-output-invalid' $evidence } $evidence.osType = $data.OSType $evidence.serverVersion = $data.ServerVersion if ($data.OSType -eq 'windows') { return New-SetupCheck 'incompatible' 'windows-containers-mode' $evidence } if ($data.OperatingSystem -notmatch '^Docker Desktop' -or $data.OSType -ne 'linux') { return New-SetupCheck 'incompatible' 'other-or-unverified-local-server' $evidence } if (-not $data.ServerVersion) { return New-SetupCheck 'unknown' 'docker-server-version-missing' $evidence } New-SetupCheck 'pass' 'local-desktop-linux-engine-observed' $evidence } function Protect-SetupPath { param([string]$Value) foreach ($name in @('LOCALAPPDATA', 'ProgramFiles', 'ProgramFiles(x86)', 'USERPROFILE')) { $prefix = [Environment]::GetEnvironmentVariable($name) if ($prefix -and $Value.StartsWith($prefix + '\', [StringComparison]::OrdinalIgnoreCase)) { return '%' + $name + '%' + $Value.Substring($prefix.Length) } } return $Value } function Get-NovaberSetupCheck { param([string]$ExplicitPath) $candidates = @() $queryFailure = $null if ($ExplicitPath) { $candidates += $ExplicitPath } else { $candidates += @("$env:LOCALAPPDATA\Programs\novaber\Novaber.exe", "$env:ProgramFiles\Novaber\Novaber.exe", "${env:ProgramFiles(x86)}\Novaber\Novaber.exe") foreach ($root in @('HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall', 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall', 'HKLM:\Software\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall')) { try { if (-not (Test-Path -LiteralPath $root -ErrorAction Stop)) { continue } foreach ($key in (Get-ChildItem -LiteralPath $root -ErrorAction Stop)) { $entry = Get-ItemProperty -LiteralPath $key.PSPath -ErrorAction Stop if ($entry.DisplayName -eq 'Novaber') { if ($entry.InstallLocation) { $candidates += Join-Path $entry.InstallLocation 'Novaber.exe' } if ($entry.DisplayIcon) { $candidates += ($entry.DisplayIcon -replace ',\d+$', '').Trim('"') } } } } catch { $queryFailure = Get-FailureKind $_ } } } $found = @() foreach ($candidate in ($candidates | Select-Object -Unique)) { try { $candidate = [IO.Path]::GetFullPath($candidate) if ($candidate -notmatch '^[a-zA-Z]:\\' -or [IO.Path]::GetFileName($candidate) -ine 'Novaber.exe') { continue } if (-not (Test-Path -LiteralPath $candidate -PathType Leaf -ErrorAction Stop)) { continue } $file = Get-Item -LiteralPath $candidate -ErrorAction Stop if ($file.Name -ine 'Novaber.exe' -or $file.VersionInfo.ProductName -ne 'Novaber' -or -not $file.VersionInfo.ProductVersion) { continue } $found += @{ path = Protect-SetupPath $file.FullName; version = $file.VersionInfo.ProductVersion; source = 'exe-version-resource'; launchTested = $false } } catch { $queryFailure = Get-FailureKind $_ } } $evidence = @{ installations = $found; queryFailure = $queryFailure; customLocationsNotSearched = -not [bool]$ExplicitPath } if ($queryFailure -eq 'permission-denied') { return New-SetupCheck 'permission-denied' 'novaber-discovery-incomplete' $evidence } if ($found.Count -gt 0) { return New-SetupCheck 'pass' 'novaber-files-observed-trust-and-launch-unverified' $evidence } if ($ExplicitPath -and -not $queryFailure) { return New-SetupCheck 'missing' 'novaber-not-at-specified-path' $evidence } New-SetupCheck 'unknown' 'novaber-not-found-in-known-locations' $evidence } function Get-NovaberSetupReport { param([string]$TargetPath, [int]$TimeoutSeconds = 8, [switch]$SkipWsl) $checks = [ordered]@{} $names = @('windows', 'memory', 'disk', 'virtualization', 'restart', 'wsl', 'gpu', 'docker', 'novaber') if ($env:OS -ne 'Windows_NT') { foreach ($name in $names) { $checks[$name] = New-SetupCheck 'unknown' 'run-on-target-windows-host' } $checks.windows = New-SetupCheck 'incompatible' 'not-windows-host' } else { $checks.windows = Get-WindowsSetupCheck # Do not query container/remote services when outside the Windows x64 scope. if (-not [Environment]::Is64BitProcess) { foreach ($name in $names | Where-Object { $_ -ne 'windows' }) { $checks[$name] = New-SetupCheck 'unknown' 'run-64bit-powershell-on-target' } } elseif ($checks.windows.status -eq 'incompatible') { foreach ($name in $names | Where-Object { $_ -ne 'windows' }) { $checks[$name] = New-SetupCheck 'unknown' 'outside-supported-host-scope' } } else { $checks.memory = $null; $checks.disk = $null $resources = Get-ResourceSetupChecks $TargetPath $checks.memory = $resources.memory; $checks.disk = $resources.disk $checks.virtualization = Get-VirtualizationSetupCheck $checks.restart = Get-RestartSetupCheck $checks.wsl = Get-WslSetupCheck $TimeoutSeconds -Skip:$SkipWsl $checks.gpu = Get-GpuSetupCheck $TimeoutSeconds $checks.docker = Get-DockerSetupCheck $TimeoutSeconds $checks.novaber = Get-NovaberSetupCheck $TargetPath } } [pscustomobject][ordered]@{ schemaVersion = 1; toolVersion = '1.0.3'; checkedAt = [DateTime]::UtcNow.ToString('o') readOnly = $true; targetConfirmationRequired = $true; checks = $checks } } if ($MyInvocation.InvocationName -ne '.') { $ErrorActionPreference = 'Stop' [Console]::OutputEncoding = New-Object System.Text.UTF8Encoding($false) Get-NovaberSetupReport -TargetPath $InstallPath -TimeoutSeconds $CommandTimeoutSeconds -SkipWsl:$SkipWsl | ConvertTo-Json -Depth 12 -Compress }