pull/431/head
romanitho 2023-10-17 22:35:36 +02:00
parent b48e8f894e
commit 2a9cbcb820
5 changed files with 40 additions and 52 deletions

View File

@ -246,7 +246,7 @@ function Install-WinGet {
try { try {
Write-ToLog "-> Installing Microsoft.VCLibs.140.00.UWPDesktop..." Write-ToLog "-> Installing Microsoft.VCLibs.140.00.UWPDesktop..."
Add-AppxProvisionedPackage -Online -PackagePath $VCLibsFile -SkipLicense | Out-Null Add-AppxProvisionedPackage -Online -PackagePath $VCLibsFile -SkipLicense | Out-Null
Write-ToLog "-> Microsoft.VCLibs.140.00.UWPDesktop installed successfully" "Green" Write-ToLog "-> Microsoft.VCLibs.140.00.UWPDesktop installed successfully." "Green"
} }
catch { catch {
Write-ToLog "-> Failed to intall Microsoft.VCLibs.140.00.UWPDesktop..." "Red" Write-ToLog "-> Failed to intall Microsoft.VCLibs.140.00.UWPDesktop..." "Red"
@ -258,17 +258,17 @@ function Install-WinGet {
} }
elseif ($WinGetAvailableVersion -match "-pre") { elseif ($WinGetAvailableVersion -match "-pre") {
Write-ToLog "-> WinGet is probably up to date (v$WinGetInstalledVersion) - v$WinGetAvailableVersion is available but only as a Pre-release" "Yellow" Write-ToLog "-> WinGet is probably up to date (v$WinGetInstalledVersion) - v$WinGetAvailableVersion is available but only as a Pre-release." "Yellow"
Update-StoreApps Update-StoreApps
} }
else { else {
Write-ToLog "-> WinGet is up to date: v$WinGetInstalledVersion" "Green" Write-ToLog "-> WinGet is up to date: v$WinGetInstalledVersion`n" "Green"
} }
} }
function Install-WingetAutoUpdate { function Install-WingetAutoUpdate {
Write-ToLog "`nInstalling WAU..." "Yellow" Write-ToLog "Installing WAU..." "Yellow"
try { try {
#Copy files to location (and clean old install) #Copy files to location (and clean old install)
@ -452,16 +452,16 @@ function Install-WingetAutoUpdate {
} }
#Security check #Security check
Write-ToLog "`nChecking Mods Directory:" "Yellow" Write-ToLog "Checking Mods Directory:" "Yellow"
$Protected = Invoke-ModsProtect "$WingetUpdatePath\mods" $Protected = Invoke-ModsProtect "$WingetUpdatePath\mods"
if ($Protected -eq $True) { if ($Protected -eq $True) {
Write-ToLog "The mods directory is now secured!`n" "Green" Write-ToLog "-> The mods directory is now secured!`n" "Green"
} }
elseif ($Protected -eq $False) { elseif ($Protected -eq $False) {
Write-ToLog "The mods directory was already secured!`n" "Green" Write-ToLog "-> The mods directory was already secured!`n" "Green"
} }
else { else {
Write-ToLog "Error: The mods directory couldn't be verified as secured!`n" "Red" Write-ToLog "-> Error: The mods directory couldn't be verified as secured!`n" "Red"
} }
#Create Shortcuts #Create Shortcuts
@ -493,7 +493,7 @@ function Install-WingetAutoUpdate {
function Uninstall-WingetAutoUpdate { function Uninstall-WingetAutoUpdate {
Write-ToLog "`nUninstalling WAU..." "Yellow" Write-ToLog "Uninstalling WAU..." "Yellow"
try { try {
#Get registry install location #Get registry install location
@ -530,15 +530,15 @@ function Uninstall-WingetAutoUpdate {
Remove-Item -Path "${env:Public}\Desktop\WAU - Check for updated Apps.lnk" -Force | Out-Null Remove-Item -Path "${env:Public}\Desktop\WAU - Check for updated Apps.lnk" -Force | Out-Null
} }
Write-ToLog "Uninstallation succeeded!" "Green" Write-ToLog "Uninstallation succeeded!`n" "Green"
Start-sleep 1 Start-sleep 1
} }
else { else {
Write-ToLog "$InstallLocation not found! Uninstallation failed!" "Red" Write-ToLog "$InstallLocation not found! Uninstallation failed!`n" "Red"
} }
} }
catch { catch {
Write-ToLog "Uninstallation failed! Run as admin ?" "Red" Write-ToLog "Uninstallation failed! Run as admin ?`n" "Red"
Start-sleep 1 Start-sleep 1
} }
} }
@ -565,7 +565,7 @@ function Start-WingetAutoUpdate {
} }
if ($RunWinget -eq 1) { if ($RunWinget -eq 1) {
try { try {
Write-ToLog "`nRunning Winget-AutoUpdate..." "Yellow" Write-ToLog "Running Winget-AutoUpdate..." "Yellow"
Get-ScheduledTask -TaskName "Winget-AutoUpdate" -ErrorAction SilentlyContinue | Start-ScheduledTask -ErrorAction SilentlyContinue Get-ScheduledTask -TaskName "Winget-AutoUpdate" -ErrorAction SilentlyContinue | Start-ScheduledTask -ErrorAction SilentlyContinue
while ((Get-ScheduledTask -TaskName "Winget-AutoUpdate").State -ne 'Ready') { while ((Get-ScheduledTask -TaskName "Winget-AutoUpdate").State -ne 'Ready') {
Start-Sleep 1 Start-Sleep 1
@ -621,7 +621,7 @@ Write-Host "`t https://github.com/Romanitho/Winget-AutoUpdate`n" -Foreground
Write-Host "`t________________________________________________________`n`n" Write-Host "`t________________________________________________________`n`n"
if (!$Uninstall) { if (!$Uninstall) {
Write-ToLog "Installing WAU to $WingetUpdatePath\`n" Write-ToLog "Installing WAU to $WingetUpdatePath\"
Install-Prerequisites Install-Prerequisites
Install-WinGet Install-WinGet
Install-WingetAutoUpdate Install-WingetAutoUpdate

View File

@ -37,11 +37,11 @@ function Invoke-PostUpdateActions {
#Check if the current available WinGet isn't a Pre-release and if it's newer than the installed #Check if the current available WinGet isn't a Pre-release and if it's newer than the installed
if (!($WinGetAvailableVersion -match "-pre") -and ($WinGetAvailableVersion -gt $WinGetInstalledVersion)) { if (!($WinGetAvailableVersion -match "-pre") -and ($WinGetAvailableVersion -gt $WinGetInstalledVersion)) {
Write-ToLog "-> WinGet is not installed/up to date (v$WinGetInstalledVersion) - v$WinGetAvailableVersion is available:" "red" Write-ToLog "-> WinGet is not installed/up to date (v$WinGetInstalledVersion) - v$WinGetAvailableVersion is available:" "red"
Update-WinGet $WinGetAvailableVersion $($WAUConfig.InstallLocation) $true Update-WinGet $WinGetAvailableVersion $($WAUConfig.InstallLocation)
} }
elseif ($WinGetAvailableVersion -match "-pre") { elseif ($WinGetAvailableVersion -match "-pre") {
Write-ToLog "-> WinGet is probably up to date (v$WinGetInstalledVersion) - v$WinGetAvailableVersion is available but only as a Pre-release" "yellow" Write-ToLog "-> WinGet is probably up to date (v$WinGetInstalledVersion) - v$WinGetAvailableVersion is available but only as a Pre-release" "yellow"
Update-StoreApps $true Update-StoreApps
} }
else { else {
Write-ToLog "-> WinGet is up to date: v$WinGetInstalledVersion" "green" Write-ToLog "-> WinGet is up to date: v$WinGetInstalledVersion" "green"

View File

@ -1,16 +1,15 @@
#Function to force an upgrade of Store Apps #Function to force an upgrade of Store Apps
Function Update-StoreApps ($Log = $false) { Function Update-StoreApps {
$force_string = "-> Forcing an upgrade of Store Apps (this can take a minute)..." $force_string = "-> Forcing an upgrade of Store Apps (this can take a minute)..."
$fail_string = "-> ...something went wrong!" $fail_string = "-> ...something went wrong!"
#If not WSB or Server, upgrade Microsoft Store Apps! #If not WSB or Server, upgrade Microsoft Store Apps!
if (!(Test-Path "${env:SystemDrive}\Users\WDAGUtilityAccount") -and (Get-CimInstance Win32_OperatingSystem).Caption -notmatch "Windows Server") { if (!(Test-Path "${env:SystemDrive}\Users\WDAGUtilityAccount") -and (Get-CimInstance Win32_OperatingSystem).Caption -notmatch "Windows Server") {
switch ($Log) {
$true {Write-ToLog $force_string "yellow"} Write-ToLog $force_string "yellow"
Default {Write-Host $force_string -ForegroundColor Yellow}
}
try { try {
$namespaceName = "root\cimv2\mdm\dmmap" $namespaceName = "root\cimv2\mdm\dmmap"
$className = "MDM_EnterpriseModernAppManagement_AppManagement01" $className = "MDM_EnterpriseModernAppManagement_AppManagement01"
@ -19,10 +18,7 @@ Function Update-StoreApps ($Log = $false) {
return $true return $true
} }
catch { catch {
switch ($Log) { Write-ToLog $fail_string "red"
$true {Write-ToLog $fail_string "red"}
Default {Write-Host $fail_string -ForegroundColor Red}
}
return $false return $false
} }
} }

View File

@ -1,51 +1,36 @@
#Function to download and update WinGet #Function to download and update WinGet
Function Update-WinGet ($WinGetAvailableVersion, $DownloadPath, $Log = $false) { Function Update-WinGet ($WinGetAvailableVersion, $DownloadPath) {
$download_string = "-> Downloading WinGet MSIXBundle for App Installer..." $download_string = "-> Downloading WinGet MSIXBundle for App Installer..."
$install_string = "-> Installing WinGet MSIXBundle for App Installer..." $install_string = "-> Installing WinGet MSIXBundle for App Installer..."
$success_string = "-> WinGet MSIXBundle (v$WinGetAvailableVersion) for App Installer installed successfully" $success_string = "-> WinGet MSIXBundle (v$WinGetAvailableVersion) for App Installer installed successfully"
$reset_string = "-> WinGet sources reset." $reset_string = "-> WinGet sources reset."
$fail_string = "-> Failed to install WinGet MSIXBundle for App Installer..." $fail_string = "-> Failed to install WinGet MSIXBundle for App Installer..."
#Download WinGet MSIXBundle #Download WinGet MSIXBundle
switch ($Log) { Write-ToLog $download_string
$true {Write-ToLog $download_string}
Default {Write-Host $download_string}
}
$WinGetURL = "https://github.com/microsoft/winget-cli/releases/download/v$WinGetAvailableVersion/Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle" $WinGetURL = "https://github.com/microsoft/winget-cli/releases/download/v$WinGetAvailableVersion/Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle"
$WebClient = New-Object System.Net.WebClient $WebClient = New-Object System.Net.WebClient
$WebClient.DownloadFile($WinGetURL, "$DownloadPath\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle") $WebClient.DownloadFile($WinGetURL, "$DownloadPath\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle")
#Install WinGet MSIXBundle in SYSTEM context #Install WinGet MSIXBundle in SYSTEM context
try { try {
switch ($Log) { Write-ToLog $install_string
$true {Write-ToLog $install_string}
Default {Write-Host $install_string}
}
Add-AppxProvisionedPackage -Online -PackagePath "$DownloadPath\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle" -SkipLicense | Out-Null Add-AppxProvisionedPackage -Online -PackagePath "$DownloadPath\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle" -SkipLicense | Out-Null
switch ($Log) { Write-ToLog $success_string "green"
$true {Write-ToLog $success_string "green"}
Default {Write-host $success_string -ForegroundColor Green}
}
#Reset WinGet Sources #Reset WinGet Sources
$ResolveWingetPath = Resolve-Path "$env:programfiles\WindowsApps\Microsoft.DesktopAppInstaller_*_*__8wekyb3d8bbwe\winget.exe" | Sort-Object { [version]($_.Path -replace '^[^\d]+_((\d+\.)*\d+)_.*', '$1') } $ResolveWingetPath = Resolve-Path "$env:programfiles\WindowsApps\Microsoft.DesktopAppInstaller_*_*__8wekyb3d8bbwe\winget.exe" | Sort-Object { [version]($_.Path -replace '^[^\d]+_((\d+\.)*\d+)_.*', '$1') }
if ($ResolveWingetPath) { if ($ResolveWingetPath) {
switch ($Log) { Write-ToLog $reset_string "green"
$true {Write-ToLog $reset_string "green"}
Default {Write-Host $reset_string -ForegroundColor Green}
}
#If multiple version, pick last one #If multiple version, pick last one
$WingetPath = $ResolveWingetPath[-1].Path $WingetPath = $ResolveWingetPath[-1].Path
& $WingetPath source reset --force & $WingetPath source reset --force
} }
} }
catch { catch {
switch ($Log) { Write-ToLog $fail_string "red"
$true {Write-ToLog $fail_string "red"}
Default {Write-Host $fail_string -ForegroundColor Red}
}
Update-StoreApps Update-StoreApps
} }

View File

@ -1,6 +1,13 @@
#Write to Log Function #Write to Log Function
function Write-ToLog ($LogMsg, $LogColor = "White", $IsHeader) { function Write-ToLog {
[CmdletBinding()]
param(
[Parameter()] [String] $LogMsg,
[Parameter()] [String] $LogColor = "White",
[Parameter()] [Switch] $IsHeader = $false
)
#Create file if doesn't exist #Create file if doesn't exist
if (!(Test-Path $LogFile)) { if (!(Test-Path $LogFile)) {