Skip to content

Commit

Permalink
- Improve verbiage for incompatible systems
Browse files Browse the repository at this point in the history
- Add import of Appx module on Server + pwsh
  • Loading branch information
asheroto committed Nov 6, 2023
1 parent 14cda9a commit 4a0f46a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
1 change: 0 additions & 1 deletion README.md
Expand Up @@ -167,7 +167,6 @@ winget-install

- Before releasing a new version, the script is tested on a clean install of Windows 10 22H2, Server 2022 21H2, and Windows 11 22H2
- If you run into an issue, please ensure your system is compatible & fully updated
- Note that PowerShell 7 `pwsh.exe` doesn't work well with the `Appx` commands on *some* systems, so if you see a warning about `Appx`, so try using the plain built-in Powershell `powershell.exe` instead
- Try running `winget-install` again, sometimes the script will fail due to a temporary issue with the prerequisite server URLs
- Try using the `-DebugMode` and `-DisableCleanup` parameters to see if it provides any additional information
- If you're getting a `resource in use` error message, run the script again with the `-ForceClose` parameter
Expand Down
27 changes: 21 additions & 6 deletions winget-install.ps1
@@ -1,6 +1,6 @@
<#PSScriptInfo
.VERSION 3.2.3
.VERSION 3.2.4
.GUID 3b581edb-5d90-4fa1-ba15-4f2377275463
Expand Down Expand Up @@ -37,6 +37,7 @@
[Version 3.2.1] - Fixed minor glitch when using -Version or -Help parameters.
[Version 3.2.2] - Improved script exit functionality.
[Version 3.2.3] - Improved -ForceClose window handling with x86 PowerShell process.
[Version 3.2.4] - Improved verbiage for incompatible systems. Added importing Appx module on Windows Server with PowerShell 7+ systems to avoid error message.
#>

Expand Down Expand Up @@ -66,7 +67,7 @@ This function should be run with administrative privileges.
.PARAMETER Help
Displays the full help information for the script.
.NOTES
Version : 3.2.3
Version : 3.2.4
Created by : asheroto
.LINK
Project Site: https://github.com/asheroto/winget-install
Expand All @@ -84,7 +85,7 @@ param (
)

# Version
$CurrentVersion = '3.2.3'
$CurrentVersion = '3.2.4'
$RepoOwner = 'asheroto'
$RepoName = 'winget-install'
$PowerShellGalleryName = 'winget-install'
Expand Down Expand Up @@ -629,6 +630,20 @@ function Install-Prerequisite {
Code = 0
}
try {
# ============================================================================ #
# Import Appx module on Windows Server and PowerShell version 7+
# ============================================================================ #
# This is to avoid the following error:
# The 'Add-AppxPackage' command was found in the module 'Appx', but the module could not be loaded due to the following error:
# [Operation is not supported on this platform. (0x80131539)]
if ($osVersion.Type -eq "Server" -and $PSVersionTable.PSVersion.Major -ge 7) {
if ($DebugMode) { Write-Output "Server OS with PowerShell 7+ was detected, importing Appx module..." }
Import-Module Appx -UseWindowsPowerShell *>$null;
} else {
if ($DebugMode) { Write-Output "Server OS with PowerShell 7+ was not detected, skipping Appx module import..." }
}
if ($DebugMmode) { Write-Output "" }

# ============================================================================ #
# Windows 10 / Server 2022 detection
# ============================================================================ #
Expand Down Expand Up @@ -920,19 +935,19 @@ $currentProcess = Get-CurrentProcess

# If it's a workstation, make sure it is Windows 10+
if ($osVersion.Type -eq "Workstation" -and $osVersion.NumericVersion -lt 10) {
Write-Error "winget is only compatible with Windows 10 or greater."
Write-Error "winget requires Windows 10 or later on workstations. Your version of Windows is not supported."
ExitWithDelay 1
}

# If it's a workstation with Windows 10, make sure it's version 1809 or greater
if ($osVersion.Type -eq "Workstation" -and $osVersion.NumericVersion -eq 10 -and $osVersion.ReleaseId -lt 1809) {
Write-Error "winget is only compatible with Windows 10 version 1809 or greater."
Write-Error "winget requires Windows 10 version 1809 or later on workstations. Please update Windows to a compatible version."
ExitWithDelay 1
}

# If it's a server, it needs to be 2022+
if ($osVersion.Type -eq "Server" -and $osVersion.NumericVersion -lt 2022) {
Write-Error "winget is only compatible with Windows Server 2022+."
Write-Error "winget requires Windows Server 2022 or newer on server platforms. Your version of Windows Server is not supported."
ExitWithDelay 1
}

Expand Down

0 comments on commit 4a0f46a

Please sign in to comment.