-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathWingetPre-Install_Detection
72 lines (63 loc) · 2.42 KB
/
WingetPre-Install_Detection
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
##*===============================================
##* Check Xaml
##*===============================================
$packageName = "Microsoft.UI.Xaml.2.7"
# Find the package with the specific version
$package = Get-AppxPackage -Name $packageName -ErrorAction SilentlyContinue
if ($package) {
Write-Host "Package $packageName is installed."
} else {
Write-Host "Package $packageName is not installed."
##*===============================================
##* Updated Xaml Install
##*===============================================
# Define the URL and local paths
$nugetUrl = "https://www.nuget.org/api/v2/package/Microsoft.UI.Xaml/2.7.3"
$zipFilePath = "Microsoft.UI.Xaml.2.7.3.zip"
$extractedFolderPath = "C:\Temp\Microsoft.UI.Xaml.2.7.3" # Changed to a temp directory
# Ensure the extraction directory exists
if (-not (Test-Path $extractedFolderPath)) {
New-Item -ItemType Directory -Path $extractedFolderPath
}
# Download the NuGet package
Invoke-WebRequest -Uri $nugetUrl -OutFile $zipFilePath
# Extract the package with overwrite (-Force)
Expand-Archive -Path $zipFilePath -DestinationPath $extractedFolderPath -Force
# Locate the .appx file
$appxFile = (Get-ChildItem -Path "$extractedFolderPath\tools\AppX\x64\Release" -Filter "*.appx").FullName
# DISM command to add the package for all users (requires admin privileges)
dism.exe /Online /Add-ProvisionedAppxPackage /PackagePath:$appxFile /SkipLicense
# Clean up: Remove the extracted files and the downloaded zip file
Remove-Item -Path $extractedFolderPath -Recurse -Force
Remove-Item -Path $zipFilePath -Force
# Output message
Write-Host "Installation complete and temporary files cleaned up."
}
##*===============================================
##* Check Winget
##*===============================================
$wingetexe = Resolve-Path "C:\Program Files\WindowsApps\Microsoft.DesktopAppInstaller_*_x64__8wekyb3d8bbwe\winget.exe"
if ($wingetexe.count -gt 1){
$wingetexe = $wingetexe[-1].Path
}
$wingettest = & $wingetexe
if ($wingettest -like "*Windows Package Manager*"){
Write-Host "Winget Found, checking version"
$wingetVersion = & $wingetexe --version
# Removes the leading 'v' and anything following a dash
$Version = $wingetVersion -replace '^v|-.+$', ''
if($Version -ge 1.6)
{
Write-Host 'Winget is up to date'
Exit 0
}
else
{
Write-Host 'Winget is not up to date'
Exit 1
}
}
else {
Write-Host 'Winget not Found'
Exit 1
}