From 99345b766228f0ff985b164c102c4fe52f70cf0e Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Tue, 27 Dec 2022 22:44:37 +0100 Subject: [PATCH 01/86] Started with admx/adml and Policies Management --- Winget-AutoUpdate/Winget-Upgrade.ps1 | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/Winget-AutoUpdate/Winget-Upgrade.ps1 b/Winget-AutoUpdate/Winget-Upgrade.ps1 index be9b4c1b..65596d57 100644 --- a/Winget-AutoUpdate/Winget-Upgrade.ps1 +++ b/Winget-AutoUpdate/Winget-Upgrade.ps1 @@ -25,6 +25,27 @@ else { #Get WAU Configurations $Script:WAUConfig = Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate" +if ($IsSystem) { + #Get WAU Policies and set the Configurations Registry Accordingly + $WAUPolicies = Get-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Romanitho\Winget-AutoUpdate" -ErrorAction SilentlyContinue + $regPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate" + if ($null -ne $WAUPolicies.WAU_BypassListForUsers) { + New-ItemProperty $regPath -Name WAU_BypassListForUsers -Value $WAUPolicies.WAU_BypassListForUsers -PropertyType DWord -Force -ErrorAction SilentlyContinue | Out-Null + } + if ($null -ne $WAUPolicies.WAU_DisableAutoUpdate) { + New-ItemProperty $regPath -Name WAU_DisableAutoUpdate -Value $WAUPolicies.WAU_DisableAutoUpdate -PropertyType DWord -Force -ErrorAction SilentlyContinue | Out-Null + } + if ($null -ne $WAUPolicies.WAU_DoNotRunOnMetered) { + New-ItemProperty $regPath -Name WAU_DoNotRunOnMetered -Value $WAUPolicies.WAU_DoNotRunOnMetered -PropertyType DWord -Force -ErrorAction SilentlyContinue | Out-Null + } + if ($null -ne $WAUPolicies.WAU_UpdatePrerelease) { + New-ItemProperty $regPath -Name WAU_UpdatePrerelease -Value $WAUPolicies.WAU_UpdatePrerelease -PropertyType DWord -Force -ErrorAction SilentlyContinue | Out-Null + } + if ($null -ne $WAUPolicies.WAU_UseWhiteList) { + New-ItemProperty $regPath -Name WAU_UseWhiteList -Value $WAUPolicies.WAU_UseWhiteList -PropertyType DWord -Force -ErrorAction SilentlyContinue | Out-Null + } +} + #Run post update actions if necessary if (!($WAUConfig.WAU_PostUpdateActions -eq 0)) { Invoke-PostUpdateActions From 649f2322a4f787110f569e21b6440b0b51ad19af Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Tue, 27 Dec 2022 23:43:14 +0100 Subject: [PATCH 02/86] Write only if $WAUPolicies differs from $WAUConfig --- Winget-AutoUpdate/Winget-Upgrade.ps1 | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Winget-AutoUpdate/Winget-Upgrade.ps1 b/Winget-AutoUpdate/Winget-Upgrade.ps1 index 65596d57..1fdc5a8e 100644 --- a/Winget-AutoUpdate/Winget-Upgrade.ps1 +++ b/Winget-AutoUpdate/Winget-Upgrade.ps1 @@ -29,19 +29,19 @@ if ($IsSystem) { #Get WAU Policies and set the Configurations Registry Accordingly $WAUPolicies = Get-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Romanitho\Winget-AutoUpdate" -ErrorAction SilentlyContinue $regPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate" - if ($null -ne $WAUPolicies.WAU_BypassListForUsers) { + if ($null -ne $WAUPolicies.WAU_BypassListForUsers -and ($WAUPolicies.WAU_BypassListForUsers -ne $WAUConfig.WAU_BypassListForUsers)) { New-ItemProperty $regPath -Name WAU_BypassListForUsers -Value $WAUPolicies.WAU_BypassListForUsers -PropertyType DWord -Force -ErrorAction SilentlyContinue | Out-Null } - if ($null -ne $WAUPolicies.WAU_DisableAutoUpdate) { + if ($null -ne $WAUPolicies.WAU_DisableAutoUpdate -and ($WAUPolicies.WAU_DisableAutoUpdate -ne $WAUConfig.WAU_DisableAutoUpdate)) { New-ItemProperty $regPath -Name WAU_DisableAutoUpdate -Value $WAUPolicies.WAU_DisableAutoUpdate -PropertyType DWord -Force -ErrorAction SilentlyContinue | Out-Null } - if ($null -ne $WAUPolicies.WAU_DoNotRunOnMetered) { + if ($null -ne $WAUPolicies.WAU_DoNotRunOnMetered -and ($WAUPolicies.WAU_DoNotRunOnMetered -ne $WAUConfig.WAU_DoNotRunOnMetered)) { New-ItemProperty $regPath -Name WAU_DoNotRunOnMetered -Value $WAUPolicies.WAU_DoNotRunOnMetered -PropertyType DWord -Force -ErrorAction SilentlyContinue | Out-Null } - if ($null -ne $WAUPolicies.WAU_UpdatePrerelease) { + if ($null -ne $WAUPolicies.WAU_UpdatePrerelease -and ($WAUPolicies.WAU_UpdatePrerelease -ne $WAUConfig.WAU_UpdatePrerelease)) { New-ItemProperty $regPath -Name WAU_UpdatePrerelease -Value $WAUPolicies.WAU_UpdatePrerelease -PropertyType DWord -Force -ErrorAction SilentlyContinue | Out-Null } - if ($null -ne $WAUPolicies.WAU_UseWhiteList) { + if ($null -ne $WAUPolicies.WAU_UseWhiteList -and ($WAUPolicies.WAU_UseWhiteList -ne $WAUConfig.WAU_UseWhiteList)) { New-ItemProperty $regPath -Name WAU_UseWhiteList -Value $WAUPolicies.WAU_UseWhiteList -PropertyType DWord -Force -ErrorAction SilentlyContinue | Out-Null } } From 50dcf3469eda3265764b3a85e0601408e643ba8b Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Wed, 28 Dec 2022 00:14:20 +0100 Subject: [PATCH 03/86] README, ADMX/ADML --- Policies/README.md | 9 ++++++ Policies/WAU.admx | 70 +++++++++++++++++++++++++++++++++++++++++ Policies/en-US/WAU.adml | 21 +++++++++++++ 3 files changed, 100 insertions(+) create mode 100644 Policies/README.md create mode 100644 Policies/WAU.admx create mode 100644 Policies/en-US/WAU.adml diff --git a/Policies/README.md b/Policies/README.md new file mode 100644 index 00000000..3d46e88c --- /dev/null +++ b/Policies/README.md @@ -0,0 +1,9 @@ +### Add the administrative template to an individual computer +1. Copy the "**WAU.admx**" file to your Policy Definition template folder. (Example: `C:\Windows\PolicyDefinitions`) +2. Copy the "**WAU.adml**" file to the matching language folder in your Policy Definition folder. (Example: `C:\Windows\PolicyDefinitions\en-US`) + +### Add the administrative template to Active Directory +1. On a domain controller or workstation with [RSAT](https://learn.microsoft.com/en-us/troubleshoot/windows-server/system-management-components/remote-server-administration-tools), go to the **PolicyDefinition** folder (also known as the _Central Store_) on any domain controller for your domain. +2. Copy the "**WAU.admx**" file to the PolicyDefinition folder. (Example: `%systemroot%\sysvol\domain\policies\PolicyDefinitions`) +3. Copy the "**WAU.adml**" file to the matching language folder in the PolicyDefinition folder. Create the folder if it doesn't already exist. (Example: `%systemroot%\sysvol\domain\policies\PolicyDefinitions\EN-US`) +4. If your domain has more than one domain controller, the new [ADMX files](https://learn.microsoft.com/en-us/troubleshoot/windows-client/group-policy/create-and-manage-central-store) will be replicated to them at the next domain replication interval. diff --git a/Policies/WAU.admx b/Policies/WAU.admx new file mode 100644 index 00000000..e445dcdc --- /dev/null +++ b/Policies/WAU.admx @@ -0,0 +1,70 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Policies/en-US/WAU.adml b/Policies/en-US/WAU.adml new file mode 100644 index 00000000..daf18efe --- /dev/null +++ b/Policies/en-US/WAU.adml @@ -0,0 +1,21 @@ + + + + + + + Winget-AutoUpdate + Winget-AutoUpdate version 1.15.3 or later + Bypass Black/White list for User + This policy setting specifies whether to Bypass Black/White list when run in user context or not. + Disable Winget-AutoUpdate update checking + This policy setting specifies whether to Disable Winget-AutoUpdate update checking or not. By default, WAU auto updates if new version is available on Github. + Do not run WAU on metered connection + This policy setting specifies whether to Run WAU on metered connection or not. Default No. + Update WAU to PreRelease versions + This policy setting specifies whether to update WAU (if enabled) to PreRelease versions or not. Default No. + Use WhiteList instead of BlackList + This policy setting specifies whether to use a WhiteList or not. Default Blacklist. + + + From daa2e9ec4dccec82428072acf546f1464e3cfe5f Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Wed, 28 Dec 2022 00:41:11 +0100 Subject: [PATCH 04/86] Check only if $WAUPolicies exists --- Winget-AutoUpdate/Winget-Upgrade.ps1 | 32 +++++++++++++++------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/Winget-AutoUpdate/Winget-Upgrade.ps1 b/Winget-AutoUpdate/Winget-Upgrade.ps1 index 1fdc5a8e..8737cabc 100644 --- a/Winget-AutoUpdate/Winget-Upgrade.ps1 +++ b/Winget-AutoUpdate/Winget-Upgrade.ps1 @@ -28,21 +28,23 @@ $Script:WAUConfig = Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\Cur if ($IsSystem) { #Get WAU Policies and set the Configurations Registry Accordingly $WAUPolicies = Get-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Romanitho\Winget-AutoUpdate" -ErrorAction SilentlyContinue - $regPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate" - if ($null -ne $WAUPolicies.WAU_BypassListForUsers -and ($WAUPolicies.WAU_BypassListForUsers -ne $WAUConfig.WAU_BypassListForUsers)) { - New-ItemProperty $regPath -Name WAU_BypassListForUsers -Value $WAUPolicies.WAU_BypassListForUsers -PropertyType DWord -Force -ErrorAction SilentlyContinue | Out-Null - } - if ($null -ne $WAUPolicies.WAU_DisableAutoUpdate -and ($WAUPolicies.WAU_DisableAutoUpdate -ne $WAUConfig.WAU_DisableAutoUpdate)) { - New-ItemProperty $regPath -Name WAU_DisableAutoUpdate -Value $WAUPolicies.WAU_DisableAutoUpdate -PropertyType DWord -Force -ErrorAction SilentlyContinue | Out-Null - } - if ($null -ne $WAUPolicies.WAU_DoNotRunOnMetered -and ($WAUPolicies.WAU_DoNotRunOnMetered -ne $WAUConfig.WAU_DoNotRunOnMetered)) { - New-ItemProperty $regPath -Name WAU_DoNotRunOnMetered -Value $WAUPolicies.WAU_DoNotRunOnMetered -PropertyType DWord -Force -ErrorAction SilentlyContinue | Out-Null - } - if ($null -ne $WAUPolicies.WAU_UpdatePrerelease -and ($WAUPolicies.WAU_UpdatePrerelease -ne $WAUConfig.WAU_UpdatePrerelease)) { - New-ItemProperty $regPath -Name WAU_UpdatePrerelease -Value $WAUPolicies.WAU_UpdatePrerelease -PropertyType DWord -Force -ErrorAction SilentlyContinue | Out-Null - } - if ($null -ne $WAUPolicies.WAU_UseWhiteList -and ($WAUPolicies.WAU_UseWhiteList -ne $WAUConfig.WAU_UseWhiteList)) { - New-ItemProperty $regPath -Name WAU_UseWhiteList -Value $WAUPolicies.WAU_UseWhiteList -PropertyType DWord -Force -ErrorAction SilentlyContinue | Out-Null + if ($WAUPolicies) { + $regPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate" + if ($null -ne $WAUPolicies.WAU_BypassListForUsers -and ($WAUPolicies.WAU_BypassListForUsers -ne $WAUConfig.WAU_BypassListForUsers)) { + New-ItemProperty $regPath -Name WAU_BypassListForUsers -Value $WAUPolicies.WAU_BypassListForUsers -PropertyType DWord -Force -ErrorAction SilentlyContinue | Out-Null + } + if ($null -ne $WAUPolicies.WAU_DisableAutoUpdate -and ($WAUPolicies.WAU_DisableAutoUpdate -ne $WAUConfig.WAU_DisableAutoUpdate)) { + New-ItemProperty $regPath -Name WAU_DisableAutoUpdate -Value $WAUPolicies.WAU_DisableAutoUpdate -PropertyType DWord -Force -ErrorAction SilentlyContinue | Out-Null + } + if ($null -ne $WAUPolicies.WAU_DoNotRunOnMetered -and ($WAUPolicies.WAU_DoNotRunOnMetered -ne $WAUConfig.WAU_DoNotRunOnMetered)) { + New-ItemProperty $regPath -Name WAU_DoNotRunOnMetered -Value $WAUPolicies.WAU_DoNotRunOnMetered -PropertyType DWord -Force -ErrorAction SilentlyContinue | Out-Null + } + if ($null -ne $WAUPolicies.WAU_UpdatePrerelease -and ($WAUPolicies.WAU_UpdatePrerelease -ne $WAUConfig.WAU_UpdatePrerelease)) { + New-ItemProperty $regPath -Name WAU_UpdatePrerelease -Value $WAUPolicies.WAU_UpdatePrerelease -PropertyType DWord -Force -ErrorAction SilentlyContinue | Out-Null + } + if ($null -ne $WAUPolicies.WAU_UseWhiteList -and ($WAUPolicies.WAU_UseWhiteList -ne $WAUConfig.WAU_UseWhiteList)) { + New-ItemProperty $regPath -Name WAU_UseWhiteList -Value $WAUPolicies.WAU_UseWhiteList -PropertyType DWord -Force -ErrorAction SilentlyContinue | Out-Null + } } } From 6964d0045f22a20cf1f4217ddea28411963e98a3 Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Wed, 28 Dec 2022 01:47:04 +0100 Subject: [PATCH 05/86] ListPath/ModsPath done --- Policies/WAU.admx | 14 ++++++++++++++ Policies/en-US/WAU.adml | 16 ++++++++++++++++ Winget-AutoUpdate/Winget-Upgrade.ps1 | 6 ++++++ 3 files changed, 36 insertions(+) diff --git a/Policies/WAU.admx b/Policies/WAU.admx index e445dcdc..8fd4333b 100644 --- a/Policies/WAU.admx +++ b/Policies/WAU.admx @@ -66,5 +66,19 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Policies/en-US/WAU.adml b/Policies/en-US/WAU.adml index daf18efe..7d880bcc 100644 --- a/Policies/en-US/WAU.adml +++ b/Policies/en-US/WAU.adml @@ -16,6 +16,22 @@ This policy setting specifies whether to update WAU (if enabled) to PreRelease versions or not. Default No. Use WhiteList instead of BlackList This policy setting specifies whether to use a WhiteList or not. Default Blacklist. + Get Black/White List from external Path (URL/UNC/Local) + If this policy is enabled, you can set a (URL/UNC/Local) Path to external lists other than the default. If this policy is disabled or not configured, the default ListPath is used. + Get Mods from external Path (URL/UNC/Local) + If this policy is enabled, you can set a (URL/UNC/Local) Path to external mods other than the default. If this policy is disabled or not configured, the default ModsPath is used. + + + + + + + + + + + + diff --git a/Winget-AutoUpdate/Winget-Upgrade.ps1 b/Winget-AutoUpdate/Winget-Upgrade.ps1 index 8737cabc..b34575f8 100644 --- a/Winget-AutoUpdate/Winget-Upgrade.ps1 +++ b/Winget-AutoUpdate/Winget-Upgrade.ps1 @@ -45,6 +45,12 @@ if ($IsSystem) { if ($null -ne $WAUPolicies.WAU_UseWhiteList -and ($WAUPolicies.WAU_UseWhiteList -ne $WAUConfig.WAU_UseWhiteList)) { New-ItemProperty $regPath -Name WAU_UseWhiteList -Value $WAUPolicies.WAU_UseWhiteList -PropertyType DWord -Force -ErrorAction SilentlyContinue | Out-Null } + if ($null -ne $WAUPolicies.WAU_ListPath -and ($WAUPolicies.WAU_ListPath -ne $WAUConfig.WAU_ListPath)) { + New-ItemProperty $regPath -Name WAU_ListPath -Value $WAUPolicies.WAU_ListPath -Force -ErrorAction SilentlyContinue | Out-Null + } + if ($null -ne $WAUPolicies.WAU_ModsPath -and ($WAUPolicies.WAU_ModsPath -ne $WAUConfig.WAU_ModsPath)) { + New-ItemProperty $regPath -Name WAU_ModsPath -Value $WAUPolicies.WAU_ModsPath -Force -ErrorAction SilentlyContinue | Out-Null + } } } From 4e660e3546daf01520e183d50d046a559926dc49 Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Wed, 28 Dec 2022 03:31:26 +0100 Subject: [PATCH 06/86] A few steps more... --- Policies/WAU.admx | 10 ++++ Policies/en-US/WAU.adml | 2 + Winget-AutoUpdate/Winget-Upgrade.ps1 | 71 ++++++++++++++++++++-------- 3 files changed, 62 insertions(+), 21 deletions(-) diff --git a/Policies/WAU.admx b/Policies/WAU.admx index 8fd4333b..25002e73 100644 --- a/Policies/WAU.admx +++ b/Policies/WAU.admx @@ -16,6 +16,16 @@ + + + + + + + + + + diff --git a/Policies/en-US/WAU.adml b/Policies/en-US/WAU.adml index 7d880bcc..c9c9daba 100644 --- a/Policies/en-US/WAU.adml +++ b/Policies/en-US/WAU.adml @@ -6,6 +6,8 @@ Winget-AutoUpdate Winget-AutoUpdate version 1.15.3 or later + Activate WAU GPO Management + This policy setting is an overriding toggle for GPO Management of Winget-AutoUpdate. Bypass Black/White list for User This policy setting specifies whether to Bypass Black/White list when run in user context or not. Disable Winget-AutoUpdate update checking diff --git a/Winget-AutoUpdate/Winget-Upgrade.ps1 b/Winget-AutoUpdate/Winget-Upgrade.ps1 index b34575f8..5e5ad0b9 100644 --- a/Winget-AutoUpdate/Winget-Upgrade.ps1 +++ b/Winget-AutoUpdate/Winget-Upgrade.ps1 @@ -29,27 +29,56 @@ if ($IsSystem) { #Get WAU Policies and set the Configurations Registry Accordingly $WAUPolicies = Get-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Romanitho\Winget-AutoUpdate" -ErrorAction SilentlyContinue if ($WAUPolicies) { - $regPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate" - if ($null -ne $WAUPolicies.WAU_BypassListForUsers -and ($WAUPolicies.WAU_BypassListForUsers -ne $WAUConfig.WAU_BypassListForUsers)) { - New-ItemProperty $regPath -Name WAU_BypassListForUsers -Value $WAUPolicies.WAU_BypassListForUsers -PropertyType DWord -Force -ErrorAction SilentlyContinue | Out-Null - } - if ($null -ne $WAUPolicies.WAU_DisableAutoUpdate -and ($WAUPolicies.WAU_DisableAutoUpdate -ne $WAUConfig.WAU_DisableAutoUpdate)) { - New-ItemProperty $regPath -Name WAU_DisableAutoUpdate -Value $WAUPolicies.WAU_DisableAutoUpdate -PropertyType DWord -Force -ErrorAction SilentlyContinue | Out-Null - } - if ($null -ne $WAUPolicies.WAU_DoNotRunOnMetered -and ($WAUPolicies.WAU_DoNotRunOnMetered -ne $WAUConfig.WAU_DoNotRunOnMetered)) { - New-ItemProperty $regPath -Name WAU_DoNotRunOnMetered -Value $WAUPolicies.WAU_DoNotRunOnMetered -PropertyType DWord -Force -ErrorAction SilentlyContinue | Out-Null - } - if ($null -ne $WAUPolicies.WAU_UpdatePrerelease -and ($WAUPolicies.WAU_UpdatePrerelease -ne $WAUConfig.WAU_UpdatePrerelease)) { - New-ItemProperty $regPath -Name WAU_UpdatePrerelease -Value $WAUPolicies.WAU_UpdatePrerelease -PropertyType DWord -Force -ErrorAction SilentlyContinue | Out-Null - } - if ($null -ne $WAUPolicies.WAU_UseWhiteList -and ($WAUPolicies.WAU_UseWhiteList -ne $WAUConfig.WAU_UseWhiteList)) { - New-ItemProperty $regPath -Name WAU_UseWhiteList -Value $WAUPolicies.WAU_UseWhiteList -PropertyType DWord -Force -ErrorAction SilentlyContinue | Out-Null - } - if ($null -ne $WAUPolicies.WAU_ListPath -and ($WAUPolicies.WAU_ListPath -ne $WAUConfig.WAU_ListPath)) { - New-ItemProperty $regPath -Name WAU_ListPath -Value $WAUPolicies.WAU_ListPath -Force -ErrorAction SilentlyContinue | Out-Null - } - if ($null -ne $WAUPolicies.WAU_ModsPath -and ($WAUPolicies.WAU_ModsPath -ne $WAUConfig.WAU_ModsPath)) { - New-ItemProperty $regPath -Name WAU_ModsPath -Value $WAUPolicies.WAU_ModsPath -Force -ErrorAction SilentlyContinue | Out-Null + if ($WAUPolicies.WAU_ActivateGPOManagement -eq 1) { + $regPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate" + if ($null -ne $WAUPolicies.WAU_BypassListForUsers -and ($WAUPolicies.WAU_BypassListForUsers -ne $WAUConfig.WAU_BypassListForUsers)) { + New-ItemProperty $regPath -Name WAU_BypassListForUsers -Value $WAUPolicies.WAU_BypassListForUsers -PropertyType DWord -Force | Out-Null + } + elseif ($null -eq $WAUPolicies.WAU_BypassListForUsers) { + Remove-ItemProperty $regPath"\" -Name WAU_BypassListForUsers -Force -ErrorAction SilentlyContinue | Out-Null + } + + if ($null -ne $WAUPolicies.WAU_DisableAutoUpdate -and ($WAUPolicies.WAU_DisableAutoUpdate -ne $WAUConfig.WAU_DisableAutoUpdate)) { + New-ItemProperty $regPath -Name WAU_DisableAutoUpdate -Value $WAUPolicies.WAU_DisableAutoUpdate -PropertyType DWord -Force | Out-Null + } + elseif ($null -eq $WAUPolicies.WAU_DisableAutoUpdate) { + Remove-ItemProperty $regPath"\" -Name WAU_DisableAutoUpdate -Force -ErrorAction SilentlyContinue | Out-Null + } + + if ($null -ne $WAUPolicies.WAU_DoNotRunOnMetered -and ($WAUPolicies.WAU_DoNotRunOnMetered -ne $WAUConfig.WAU_DoNotRunOnMetered)) { + New-ItemProperty $regPath -Name WAU_DoNotRunOnMetered -Value $WAUPolicies.WAU_DoNotRunOnMetered -PropertyType DWord -Force | Out-Null + } + elseif ($null -eq $WAUPolicies.WAU_DoNotRunOnMetered) { + New-ItemProperty $regPath -Name WAU_DoNotRunOnMetered -Value 1 -PropertyType DWord -Force | Out-Null + } + + if ($null -ne $WAUPolicies.WAU_UpdatePrerelease -and ($WAUPolicies.WAU_UpdatePrerelease -ne $WAUConfig.WAU_UpdatePrerelease)) { + New-ItemProperty $regPath -Name WAU_UpdatePrerelease -Value $WAUPolicies.WAU_UpdatePrerelease -PropertyType DWord -Force | Out-Null + } + elseif ($null -eq $WAUPolicies.WAU_UpdatePrerelease) { + New-ItemProperty $regPath -Name WAU_UpdatePrerelease -Value 0 -PropertyType DWord -Force | Out-Null + } + + if ($null -ne $WAUPolicies.WAU_UseWhiteList -and ($WAUPolicies.WAU_UseWhiteList -ne $WAUConfig.WAU_UseWhiteList)) { + New-ItemProperty $regPath -Name WAU_UseWhiteList -Value $WAUPolicies.WAU_UseWhiteList -PropertyType DWord -Force | Out-Null + } + elseif ($null -eq $WAUPolicies.WAU_UseWhiteList) { + Remove-ItemProperty $regPath"\" -Name WAU_UseWhiteList -Force -ErrorAction SilentlyContinue | Out-Null + } + + if ($null -ne $WAUPolicies.WAU_ListPath -and ($WAUPolicies.WAU_ListPath -ne $WAUConfig.WAU_ListPath)) { + New-ItemProperty $regPath -Name WAU_ListPath -Value $WAUPolicies.WAU_ListPath -Force | Out-Null + } + elseif ($null -eq $WAUPolicies.WAU_ListPath) { + Remove-ItemProperty $regPath"\" -Name WAU_ListPath -Force -ErrorAction SilentlyContinue | Out-Null + } + + if ($null -ne $WAUPolicies.WAU_ModsPath -and ($WAUPolicies.WAU_ModsPath -ne $WAUConfig.WAU_ModsPath)) { + New-ItemProperty $regPath -Name WAU_ModsPath -Value $WAUPolicies.WAU_ModsPath -Force | Out-Null + } + elseif ($null -eq $WAUPolicies.WAU_ModsPath) { + Remove-ItemProperty $regPath"\" -Name WAU_ModsPath -Force -ErrorAction SilentlyContinue | Out-Null + } } } } From 96b1900b31256c65643f78f23514994dafa0e07f Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Wed, 28 Dec 2022 13:52:03 +0100 Subject: [PATCH 07/86] NotificationLevel done --- Policies/WAU.admx | 23 +++++++++++++++++++++++ Policies/en-US/WAU.adml | 9 +++++++++ Winget-AutoUpdate/Winget-Upgrade.ps1 | 7 +++++++ 3 files changed, 39 insertions(+) diff --git a/Policies/WAU.admx b/Policies/WAU.admx index 25002e73..bcf4d137 100644 --- a/Policies/WAU.admx +++ b/Policies/WAU.admx @@ -90,5 +90,28 @@ + + + + + + + + Full + + + + + SuccessOnly + + + + + None + + + + + \ No newline at end of file diff --git a/Policies/en-US/WAU.adml b/Policies/en-US/WAU.adml index c9c9daba..998d48f5 100644 --- a/Policies/en-US/WAU.adml +++ b/Policies/en-US/WAU.adml @@ -22,6 +22,12 @@ If this policy is enabled, you can set a (URL/UNC/Local) Path to external lists other than the default. If this policy is disabled or not configured, the default ListPath is used. Get Mods from external Path (URL/UNC/Local) If this policy is enabled, you can set a (URL/UNC/Local) Path to external mods other than the default. If this policy is disabled or not configured, the default ModsPath is used. + Notification Level + If this policy is enabled, you can configure Notification Level: Full (Default, displays all notifications), SuccessOnly (Only displays notifications for success) or None (Does not display any notification). +If this policy is not configured or disabled, the default displays all notifications. + 1. Full (Default, displays all notifications) + 2. SuccessOnly (Only displays notifications for success) + 3. None (Does not display any notification) @@ -34,6 +40,9 @@ + + + diff --git a/Winget-AutoUpdate/Winget-Upgrade.ps1 b/Winget-AutoUpdate/Winget-Upgrade.ps1 index 5e5ad0b9..92dd12d1 100644 --- a/Winget-AutoUpdate/Winget-Upgrade.ps1 +++ b/Winget-AutoUpdate/Winget-Upgrade.ps1 @@ -79,6 +79,13 @@ if ($IsSystem) { elseif ($null -eq $WAUPolicies.WAU_ModsPath) { Remove-ItemProperty $regPath"\" -Name WAU_ModsPath -Force -ErrorAction SilentlyContinue | Out-Null } + + if ($null -ne $WAUPolicies.WAU_NotificationLevel -and ($WAUPolicies.WAU_NotificationLevel -ne $WAUConfig.WAU_NotificationLevel)) { + New-ItemProperty $regPath -Name WAU_NotificationLevel -Value $WAUPolicies.WAU_NotificationLevel -Force | Out-Null + } + elseif ($null -eq $WAUPolicies.WAU_NotificationLevel) { + New-ItemProperty $regPath -Name WAU_NotificationLevel -Value "Full" -Force | Out-Null + } } } } From 51dfd99b937975b946970f50ba570b78f47d92cb Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Wed, 28 Dec 2022 15:08:10 +0100 Subject: [PATCH 08/86] Message in log --- Winget-AutoUpdate/Winget-Upgrade.ps1 | 1 + 1 file changed, 1 insertion(+) diff --git a/Winget-AutoUpdate/Winget-Upgrade.ps1 b/Winget-AutoUpdate/Winget-Upgrade.ps1 index 92dd12d1..ee23865b 100644 --- a/Winget-AutoUpdate/Winget-Upgrade.ps1 +++ b/Winget-AutoUpdate/Winget-Upgrade.ps1 @@ -30,6 +30,7 @@ if ($IsSystem) { $WAUPolicies = Get-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Romanitho\Winget-AutoUpdate" -ErrorAction SilentlyContinue if ($WAUPolicies) { if ($WAUPolicies.WAU_ActivateGPOManagement -eq 1) { + Write-Log "Activated WAU GPO Management detected, comparing..." $regPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate" if ($null -ne $WAUPolicies.WAU_BypassListForUsers -and ($WAUPolicies.WAU_BypassListForUsers -ne $WAUConfig.WAU_BypassListForUsers)) { New-ItemProperty $regPath -Name WAU_BypassListForUsers -Value $WAUPolicies.WAU_BypassListForUsers -PropertyType DWord -Force | Out-Null From ba6ed977b8852027806ff45c2869763a4d0565dc Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Wed, 28 Dec 2022 16:07:18 +0100 Subject: [PATCH 09/86] Text and List/Mods Path error handling --- Policies/en-US/WAU.adml | 8 ++++++-- Winget-AutoUpdate/Winget-Upgrade.ps1 | 14 +++++++------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/Policies/en-US/WAU.adml b/Policies/en-US/WAU.adml index 998d48f5..99d26243 100644 --- a/Policies/en-US/WAU.adml +++ b/Policies/en-US/WAU.adml @@ -23,8 +23,12 @@ Get Mods from external Path (URL/UNC/Local) If this policy is enabled, you can set a (URL/UNC/Local) Path to external mods other than the default. If this policy is disabled or not configured, the default ModsPath is used. Notification Level - If this policy is enabled, you can configure Notification Level: Full (Default, displays all notifications), SuccessOnly (Only displays notifications for success) or None (Does not display any notification). -If this policy is not configured or disabled, the default displays all notifications. + If this policy is enabled, you can configure the Notification Level: +1. Full (Default, displays all notifications) +2. SuccessOnly (Only displays notifications for success) +3. None (Does not display any notification) + +If this policy is not configured or disabled, the Default displays all notifications (1. Full). 1. Full (Default, displays all notifications) 2. SuccessOnly (Only displays notifications for success) 3. None (Does not display any notification) diff --git a/Winget-AutoUpdate/Winget-Upgrade.ps1 b/Winget-AutoUpdate/Winget-Upgrade.ps1 index ee23865b..c01d3b80 100644 --- a/Winget-AutoUpdate/Winget-Upgrade.ps1 +++ b/Winget-AutoUpdate/Winget-Upgrade.ps1 @@ -144,10 +144,10 @@ if (Test-Network) { #Get External ListPath if System if ($WAUConfig.WAU_ListPath) { - Write-Log "WAU uses External Lists from: $($WAUConfig.WAU_ListPath)" - $NewList = Test-ListPath $WAUConfig.WAU_ListPath $WAUConfig.WAU_UseWhiteList $WAUConfig.InstallLocation + Write-Log "WAU uses External Lists from: $($WAUConfig.WAU_ListPath.TrimEnd(" ", "\", "/"))" + $NewList = Test-ListPath $WAUConfig.WAU_ListPath.TrimEnd(" ", "\", "/") $WAUConfig.WAU_UseWhiteList $WAUConfig.InstallLocation.TrimEnd(" ", "\") if ($NewList) { - Write-Log "Newer List downloaded/copied to local path: $($WAUConfig.InstallLocation)" "Yellow" + Write-Log "Newer List downloaded/copied to local path: $($WAUConfig.InstallLocation.TrimEnd(" ", "\"))" "Yellow" } else { if ((Test-Path "$WorkingDir\included_apps.txt") -or (Test-Path "$WorkingDir\excluded_apps.txt")) { @@ -163,10 +163,10 @@ if (Test-Network) { #Get External ModsPath if System if ($WAUConfig.WAU_ModsPath) { - Write-Log "WAU uses External Mods from: $($WAUConfig.WAU_ModsPath)" - $NewMods, $DeletedMods = Test-ModsPath $WAUConfig.WAU_ModsPath $WAUConfig.InstallLocation + Write-Log "WAU uses External Mods from: $($WAUConfig.WAU_ModsPath.TrimEnd(" ", "\", "/"))" + $NewMods, $DeletedMods = Test-ModsPath $WAUConfig.WAU_ModsPath.TrimEnd(" ", "\", "/") $WAUConfig.InstallLocation.TrimEnd(" ", "\") if ($NewMods -gt 0) { - Write-Log "$NewMods newer Mods downloaded/copied to local path: $($WAUConfig.InstallLocation)\mods" "Yellow" + Write-Log "$NewMods newer Mods downloaded/copied to local path: $($WAUConfig.InstallLocation.TrimEnd(" ", "\"))\mods" "Yellow" } else { if (Test-Path "$WorkingDir\mods\*.ps1") { @@ -177,7 +177,7 @@ if (Test-Network) { } } if ($DeletedMods -gt 0) { - Write-Log "$DeletedMods Mods deleted (not externally managed) from local path: $($WAUConfig.InstallLocation)\mods" "Red" + Write-Log "$DeletedMods Mods deleted (not externally managed) from local path: $($WAUConfig.InstallLocation.TrimEnd(" ", "\"))\mods" "Red" } } } From e2c446a2be919d3c0f29ca19cde2ec36eb4cdbbf Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Wed, 28 Dec 2022 17:28:22 +0100 Subject: [PATCH 10/86] Optimized if run as System... --- Winget-AutoUpdate/Winget-Upgrade.ps1 | 37 +++++++++++----------------- 1 file changed, 15 insertions(+), 22 deletions(-) diff --git a/Winget-AutoUpdate/Winget-Upgrade.ps1 b/Winget-AutoUpdate/Winget-Upgrade.ps1 index c01d3b80..5a54b7ea 100644 --- a/Winget-AutoUpdate/Winget-Upgrade.ps1 +++ b/Winget-AutoUpdate/Winget-Upgrade.ps1 @@ -14,18 +14,12 @@ $Script:IsSystem = [System.Security.Principal.WindowsIdentity]::GetCurrent().IsS #Run log initialisation function Start-Init -#Log running context -if ($IsSystem) { - Write-Log "Running in System context" -} -else { - Write-Log "Running in User context" -} - #Get WAU Configurations $Script:WAUConfig = Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate" +#Log running context and more... if ($IsSystem) { + Write-Log "Running in System context" #Get WAU Policies and set the Configurations Registry Accordingly $WAUPolicies = Get-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Romanitho\Winget-AutoUpdate" -ErrorAction SilentlyContinue if ($WAUPolicies) { @@ -89,18 +83,17 @@ if ($IsSystem) { } } } -} - -#Run post update actions if necessary -if (!($WAUConfig.WAU_PostUpdateActions -eq 0)) { - Invoke-PostUpdateActions -} - -#Run Scope Machine funtion if run as system -if ($IsSystem) { + #Run post update actions if necessary if run as System + if (!($WAUConfig.WAU_PostUpdateActions -eq 0)) { + Invoke-PostUpdateActions + } + #Run Scope Machine funtion if run as System $SettingsPath = "$Env:windir\system32\config\systemprofile\AppData\Local\Microsoft\WinGet\Settings\defaultState\settings.json" Add-ScopeMachine $SettingsPath } +else { + Write-Log "Running in User context" +} #Get Notif Locale function $LocaleDisplayName = Get-NotifLocale @@ -116,9 +109,9 @@ if (Test-Network) { $WAUCurrentVersion = $WAUConfig.DisplayVersion Write-Log "WAU current version: $WAUCurrentVersion" if ($IsSystem) { - #Check if WAU update feature is enabled or not + #Check if WAU update feature is enabled or not if run as System $WAUDisableAutoUpdate = $WAUConfig.WAU_DisableAutoUpdate - #If yes then check WAU update if System + #If yes then check WAU update if run as System if ($WAUDisableAutoUpdate -eq 1) { Write-Log "WAU AutoUpdate is Disabled." "Grey" } @@ -137,12 +130,12 @@ if (Test-Network) { } } - #Delete previous list_/winget_error (if they exist) if System + #Delete previous list_/winget_error (if they exist) if run as System if (Test-Path "$WorkingDir\logs\error.txt") { Remove-Item "$WorkingDir\logs\error.txt" -Force } - #Get External ListPath if System + #Get External ListPath if run as System if ($WAUConfig.WAU_ListPath) { Write-Log "WAU uses External Lists from: $($WAUConfig.WAU_ListPath.TrimEnd(" ", "\", "/"))" $NewList = Test-ListPath $WAUConfig.WAU_ListPath.TrimEnd(" ", "\", "/") $WAUConfig.WAU_UseWhiteList $WAUConfig.InstallLocation.TrimEnd(" ", "\") @@ -161,7 +154,7 @@ if (Test-Network) { } } - #Get External ModsPath if System + #Get External ModsPath if run as System if ($WAUConfig.WAU_ModsPath) { Write-Log "WAU uses External Mods from: $($WAUConfig.WAU_ModsPath.TrimEnd(" ", "\", "/"))" $NewMods, $DeletedMods = Test-ModsPath $WAUConfig.WAU_ModsPath.TrimEnd(" ", "\", "/") $WAUConfig.InstallLocation.TrimEnd(" ", "\") From ce3a8f30aea62fa45ffef6edc3fe9cebf6dae591 Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Wed, 28 Dec 2022 18:20:17 +0100 Subject: [PATCH 11/86] WhiteList handling with Conf. after Pol. change... --- Winget-AutoUpdate/Winget-Upgrade.ps1 | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Winget-AutoUpdate/Winget-Upgrade.ps1 b/Winget-AutoUpdate/Winget-Upgrade.ps1 index 5a54b7ea..891bd734 100644 --- a/Winget-AutoUpdate/Winget-Upgrade.ps1 +++ b/Winget-AutoUpdate/Winget-Upgrade.ps1 @@ -54,11 +54,11 @@ if ($IsSystem) { New-ItemProperty $regPath -Name WAU_UpdatePrerelease -Value 0 -PropertyType DWord -Force | Out-Null } - if ($null -ne $WAUPolicies.WAU_UseWhiteList -and ($WAUPolicies.WAU_UseWhiteList -ne $WAUConfig.WAU_UseWhiteList)) { + if ($null -ne $WAUPolicies.WAU_UseWhiteList -and ($WAUPolicies.WAU_UseWhiteList -eq 1) -and ($WAUPolicies.WAU_UseWhiteList -ne $WAUConfig.WAU_UseWhiteList)) { New-ItemProperty $regPath -Name WAU_UseWhiteList -Value $WAUPolicies.WAU_UseWhiteList -PropertyType DWord -Force | Out-Null } - elseif ($null -eq $WAUPolicies.WAU_UseWhiteList) { - Remove-ItemProperty $regPath"\" -Name WAU_UseWhiteList -Force -ErrorAction SilentlyContinue | Out-Null + elseif ($null -eq $WAUPolicies.WAU_UseWhiteList -or $WAUPolicies.WAU_UseWhiteList -eq 0) { + Remove-ItemProperty $regPath -Name WAU_UseWhiteList -Force -ErrorAction SilentlyContinue | Out-Null } if ($null -ne $WAUPolicies.WAU_ListPath -and ($WAUPolicies.WAU_ListPath -ne $WAUConfig.WAU_ListPath)) { @@ -82,6 +82,8 @@ if ($IsSystem) { New-ItemProperty $regPath -Name WAU_NotificationLevel -Value "Full" -Force | Out-Null } } + #Get WAU Configurations after Policies change + $Script:WAUConfig = Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate" } #Run post update actions if necessary if run as System if (!($WAUConfig.WAU_PostUpdateActions -eq 0)) { From 6146dad3d89b00b16b41a0876a5250e054842ee4 Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Wed, 28 Dec 2022 19:02:58 +0100 Subject: [PATCH 12/86] Count changed settings in log --- Winget-AutoUpdate/Winget-Upgrade.ps1 | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Winget-AutoUpdate/Winget-Upgrade.ps1 b/Winget-AutoUpdate/Winget-Upgrade.ps1 index 891bd734..b4cd3c77 100644 --- a/Winget-AutoUpdate/Winget-Upgrade.ps1 +++ b/Winget-AutoUpdate/Winget-Upgrade.ps1 @@ -24,64 +24,84 @@ if ($IsSystem) { $WAUPolicies = Get-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Romanitho\Winget-AutoUpdate" -ErrorAction SilentlyContinue if ($WAUPolicies) { if ($WAUPolicies.WAU_ActivateGPOManagement -eq 1) { + $ChangedSettings = -1 Write-Log "Activated WAU GPO Management detected, comparing..." $regPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate" if ($null -ne $WAUPolicies.WAU_BypassListForUsers -and ($WAUPolicies.WAU_BypassListForUsers -ne $WAUConfig.WAU_BypassListForUsers)) { New-ItemProperty $regPath -Name WAU_BypassListForUsers -Value $WAUPolicies.WAU_BypassListForUsers -PropertyType DWord -Force | Out-Null + $ChangedSettings++ } elseif ($null -eq $WAUPolicies.WAU_BypassListForUsers) { Remove-ItemProperty $regPath"\" -Name WAU_BypassListForUsers -Force -ErrorAction SilentlyContinue | Out-Null + $ChangedSettings++ } if ($null -ne $WAUPolicies.WAU_DisableAutoUpdate -and ($WAUPolicies.WAU_DisableAutoUpdate -ne $WAUConfig.WAU_DisableAutoUpdate)) { New-ItemProperty $regPath -Name WAU_DisableAutoUpdate -Value $WAUPolicies.WAU_DisableAutoUpdate -PropertyType DWord -Force | Out-Null + $ChangedSettings++ } elseif ($null -eq $WAUPolicies.WAU_DisableAutoUpdate) { Remove-ItemProperty $regPath"\" -Name WAU_DisableAutoUpdate -Force -ErrorAction SilentlyContinue | Out-Null + $ChangedSettings++ } if ($null -ne $WAUPolicies.WAU_DoNotRunOnMetered -and ($WAUPolicies.WAU_DoNotRunOnMetered -ne $WAUConfig.WAU_DoNotRunOnMetered)) { New-ItemProperty $regPath -Name WAU_DoNotRunOnMetered -Value $WAUPolicies.WAU_DoNotRunOnMetered -PropertyType DWord -Force | Out-Null + $ChangedSettings++ } elseif ($null -eq $WAUPolicies.WAU_DoNotRunOnMetered) { New-ItemProperty $regPath -Name WAU_DoNotRunOnMetered -Value 1 -PropertyType DWord -Force | Out-Null + $ChangedSettings++ } if ($null -ne $WAUPolicies.WAU_UpdatePrerelease -and ($WAUPolicies.WAU_UpdatePrerelease -ne $WAUConfig.WAU_UpdatePrerelease)) { New-ItemProperty $regPath -Name WAU_UpdatePrerelease -Value $WAUPolicies.WAU_UpdatePrerelease -PropertyType DWord -Force | Out-Null + $ChangedSettings++ } elseif ($null -eq $WAUPolicies.WAU_UpdatePrerelease) { New-ItemProperty $regPath -Name WAU_UpdatePrerelease -Value 0 -PropertyType DWord -Force | Out-Null + $ChangedSettings++ } if ($null -ne $WAUPolicies.WAU_UseWhiteList -and ($WAUPolicies.WAU_UseWhiteList -eq 1) -and ($WAUPolicies.WAU_UseWhiteList -ne $WAUConfig.WAU_UseWhiteList)) { New-ItemProperty $regPath -Name WAU_UseWhiteList -Value $WAUPolicies.WAU_UseWhiteList -PropertyType DWord -Force | Out-Null + $ChangedSettings++ } elseif ($null -eq $WAUPolicies.WAU_UseWhiteList -or $WAUPolicies.WAU_UseWhiteList -eq 0) { Remove-ItemProperty $regPath -Name WAU_UseWhiteList -Force -ErrorAction SilentlyContinue | Out-Null + $ChangedSettings++ } if ($null -ne $WAUPolicies.WAU_ListPath -and ($WAUPolicies.WAU_ListPath -ne $WAUConfig.WAU_ListPath)) { New-ItemProperty $regPath -Name WAU_ListPath -Value $WAUPolicies.WAU_ListPath -Force | Out-Null + $ChangedSettings++ } elseif ($null -eq $WAUPolicies.WAU_ListPath) { Remove-ItemProperty $regPath"\" -Name WAU_ListPath -Force -ErrorAction SilentlyContinue | Out-Null + $ChangedSettings++ } if ($null -ne $WAUPolicies.WAU_ModsPath -and ($WAUPolicies.WAU_ModsPath -ne $WAUConfig.WAU_ModsPath)) { New-ItemProperty $regPath -Name WAU_ModsPath -Value $WAUPolicies.WAU_ModsPath -Force | Out-Null + $ChangedSettings++ } elseif ($null -eq $WAUPolicies.WAU_ModsPath) { Remove-ItemProperty $regPath"\" -Name WAU_ModsPath -Force -ErrorAction SilentlyContinue | Out-Null + $ChangedSettings++ } if ($null -ne $WAUPolicies.WAU_NotificationLevel -and ($WAUPolicies.WAU_NotificationLevel -ne $WAUConfig.WAU_NotificationLevel)) { New-ItemProperty $regPath -Name WAU_NotificationLevel -Value $WAUPolicies.WAU_NotificationLevel -Force | Out-Null + $ChangedSettings++ } elseif ($null -eq $WAUPolicies.WAU_NotificationLevel) { New-ItemProperty $regPath -Name WAU_NotificationLevel -Value "Full" -Force | Out-Null + $ChangedSettings++ } } + if ($ChangedSettings -gt 0) { + Write-Log "Changed settings: $ChangedSettings" "Yellow" + } #Get WAU Configurations after Policies change $Script:WAUConfig = Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate" } From db7b0762cccb7d6aac9d19d6ce93155e4667cdda Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Wed, 28 Dec 2022 19:15:43 +0100 Subject: [PATCH 13/86] Reverted. --- Winget-AutoUpdate/Winget-Upgrade.ps1 | 25 +++---------------------- 1 file changed, 3 insertions(+), 22 deletions(-) diff --git a/Winget-AutoUpdate/Winget-Upgrade.ps1 b/Winget-AutoUpdate/Winget-Upgrade.ps1 index b4cd3c77..a09ed27f 100644 --- a/Winget-AutoUpdate/Winget-Upgrade.ps1 +++ b/Winget-AutoUpdate/Winget-Upgrade.ps1 @@ -24,86 +24,67 @@ if ($IsSystem) { $WAUPolicies = Get-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Romanitho\Winget-AutoUpdate" -ErrorAction SilentlyContinue if ($WAUPolicies) { if ($WAUPolicies.WAU_ActivateGPOManagement -eq 1) { - $ChangedSettings = -1 Write-Log "Activated WAU GPO Management detected, comparing..." $regPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate" if ($null -ne $WAUPolicies.WAU_BypassListForUsers -and ($WAUPolicies.WAU_BypassListForUsers -ne $WAUConfig.WAU_BypassListForUsers)) { New-ItemProperty $regPath -Name WAU_BypassListForUsers -Value $WAUPolicies.WAU_BypassListForUsers -PropertyType DWord -Force | Out-Null - $ChangedSettings++ } elseif ($null -eq $WAUPolicies.WAU_BypassListForUsers) { Remove-ItemProperty $regPath"\" -Name WAU_BypassListForUsers -Force -ErrorAction SilentlyContinue | Out-Null - $ChangedSettings++ } if ($null -ne $WAUPolicies.WAU_DisableAutoUpdate -and ($WAUPolicies.WAU_DisableAutoUpdate -ne $WAUConfig.WAU_DisableAutoUpdate)) { New-ItemProperty $regPath -Name WAU_DisableAutoUpdate -Value $WAUPolicies.WAU_DisableAutoUpdate -PropertyType DWord -Force | Out-Null - $ChangedSettings++ } elseif ($null -eq $WAUPolicies.WAU_DisableAutoUpdate) { Remove-ItemProperty $regPath"\" -Name WAU_DisableAutoUpdate -Force -ErrorAction SilentlyContinue | Out-Null - $ChangedSettings++ } if ($null -ne $WAUPolicies.WAU_DoNotRunOnMetered -and ($WAUPolicies.WAU_DoNotRunOnMetered -ne $WAUConfig.WAU_DoNotRunOnMetered)) { New-ItemProperty $regPath -Name WAU_DoNotRunOnMetered -Value $WAUPolicies.WAU_DoNotRunOnMetered -PropertyType DWord -Force | Out-Null - $ChangedSettings++ } elseif ($null -eq $WAUPolicies.WAU_DoNotRunOnMetered) { New-ItemProperty $regPath -Name WAU_DoNotRunOnMetered -Value 1 -PropertyType DWord -Force | Out-Null - $ChangedSettings++ } if ($null -ne $WAUPolicies.WAU_UpdatePrerelease -and ($WAUPolicies.WAU_UpdatePrerelease -ne $WAUConfig.WAU_UpdatePrerelease)) { New-ItemProperty $regPath -Name WAU_UpdatePrerelease -Value $WAUPolicies.WAU_UpdatePrerelease -PropertyType DWord -Force | Out-Null - $ChangedSettings++ } elseif ($null -eq $WAUPolicies.WAU_UpdatePrerelease) { New-ItemProperty $regPath -Name WAU_UpdatePrerelease -Value 0 -PropertyType DWord -Force | Out-Null - $ChangedSettings++ } if ($null -ne $WAUPolicies.WAU_UseWhiteList -and ($WAUPolicies.WAU_UseWhiteList -eq 1) -and ($WAUPolicies.WAU_UseWhiteList -ne $WAUConfig.WAU_UseWhiteList)) { New-ItemProperty $regPath -Name WAU_UseWhiteList -Value $WAUPolicies.WAU_UseWhiteList -PropertyType DWord -Force | Out-Null - $ChangedSettings++ } elseif ($null -eq $WAUPolicies.WAU_UseWhiteList -or $WAUPolicies.WAU_UseWhiteList -eq 0) { Remove-ItemProperty $regPath -Name WAU_UseWhiteList -Force -ErrorAction SilentlyContinue | Out-Null - $ChangedSettings++ } if ($null -ne $WAUPolicies.WAU_ListPath -and ($WAUPolicies.WAU_ListPath -ne $WAUConfig.WAU_ListPath)) { New-ItemProperty $regPath -Name WAU_ListPath -Value $WAUPolicies.WAU_ListPath -Force | Out-Null - $ChangedSettings++ } elseif ($null -eq $WAUPolicies.WAU_ListPath) { Remove-ItemProperty $regPath"\" -Name WAU_ListPath -Force -ErrorAction SilentlyContinue | Out-Null - $ChangedSettings++ } if ($null -ne $WAUPolicies.WAU_ModsPath -and ($WAUPolicies.WAU_ModsPath -ne $WAUConfig.WAU_ModsPath)) { New-ItemProperty $regPath -Name WAU_ModsPath -Value $WAUPolicies.WAU_ModsPath -Force | Out-Null - $ChangedSettings++ } elseif ($null -eq $WAUPolicies.WAU_ModsPath) { Remove-ItemProperty $regPath"\" -Name WAU_ModsPath -Force -ErrorAction SilentlyContinue | Out-Null - $ChangedSettings++ } if ($null -ne $WAUPolicies.WAU_NotificationLevel -and ($WAUPolicies.WAU_NotificationLevel -ne $WAUConfig.WAU_NotificationLevel)) { New-ItemProperty $regPath -Name WAU_NotificationLevel -Value $WAUPolicies.WAU_NotificationLevel -Force | Out-Null - $ChangedSettings++ } elseif ($null -eq $WAUPolicies.WAU_NotificationLevel) { New-ItemProperty $regPath -Name WAU_NotificationLevel -Value "Full" -Force | Out-Null - $ChangedSettings++ } + + #Get WAU Configurations after Policies change + $Script:WAUConfig = Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate" } - if ($ChangedSettings -gt 0) { - Write-Log "Changed settings: $ChangedSettings" "Yellow" - } - #Get WAU Configurations after Policies change - $Script:WAUConfig = Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate" } #Run post update actions if necessary if run as System if (!($WAUConfig.WAU_PostUpdateActions -eq 0)) { From f758f7ed86d2199ac4da09fec39ccbcba12fc163 Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Thu, 29 Dec 2022 03:59:39 +0100 Subject: [PATCH 14/86] Counter and adopting all settings --- Winget-AutoUpdate/Winget-Upgrade.ps1 | 78 +++++++++++++++++----------- 1 file changed, 49 insertions(+), 29 deletions(-) diff --git a/Winget-AutoUpdate/Winget-Upgrade.ps1 b/Winget-AutoUpdate/Winget-Upgrade.ps1 index a09ed27f..d082ea0d 100644 --- a/Winget-AutoUpdate/Winget-Upgrade.ps1 +++ b/Winget-AutoUpdate/Winget-Upgrade.ps1 @@ -23,65 +23,85 @@ if ($IsSystem) { #Get WAU Policies and set the Configurations Registry Accordingly $WAUPolicies = Get-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Romanitho\Winget-AutoUpdate" -ErrorAction SilentlyContinue if ($WAUPolicies) { - if ($WAUPolicies.WAU_ActivateGPOManagement -eq 1) { + if ($($WAUPolicies.WAU_ActivateGPOManagement -eq 1)) { + $ChangedSettings = 0 Write-Log "Activated WAU GPO Management detected, comparing..." $regPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate" - if ($null -ne $WAUPolicies.WAU_BypassListForUsers -and ($WAUPolicies.WAU_BypassListForUsers -ne $WAUConfig.WAU_BypassListForUsers)) { - New-ItemProperty $regPath -Name WAU_BypassListForUsers -Value $WAUPolicies.WAU_BypassListForUsers -PropertyType DWord -Force | Out-Null + if ($null -ne $($WAUPolicies.WAU_BypassListForUsers) -and ($($WAUPolicies.WAU_BypassListForUsers) -ne $($WAUConfig.WAU_BypassListForUsers))) { + New-ItemProperty $regPath -Name WAU_BypassListForUsers -Value $($WAUPolicies.WAU_BypassListForUsers) -PropertyType DWord -Force | Out-Null + $ChangedSettings++ } - elseif ($null -eq $WAUPolicies.WAU_BypassListForUsers) { - Remove-ItemProperty $regPath"\" -Name WAU_BypassListForUsers -Force -ErrorAction SilentlyContinue | Out-Null + elseif ($null -eq $($WAUPolicies.WAU_BypassListForUsers) -and ($($WAUConfig.WAU_BypassListForUsers) -or $($WAUConfig.WAU_BypassListForUsers) -eq 0)) { + Remove-ItemProperty $regPath -Name WAU_BypassListForUsers -Force -ErrorAction SilentlyContinue | Out-Null + $ChangedSettings++ } - if ($null -ne $WAUPolicies.WAU_DisableAutoUpdate -and ($WAUPolicies.WAU_DisableAutoUpdate -ne $WAUConfig.WAU_DisableAutoUpdate)) { - New-ItemProperty $regPath -Name WAU_DisableAutoUpdate -Value $WAUPolicies.WAU_DisableAutoUpdate -PropertyType DWord -Force | Out-Null + if ($null -ne $($WAUPolicies.WAU_DisableAutoUpdate) -and ($($WAUPolicies.WAU_DisableAutoUpdate) -ne $($WAUConfig.WAU_DisableAutoUpdate))) { + New-ItemProperty $regPath -Name WAU_DisableAutoUpdate -Value $($WAUPolicies.WAU_DisableAutoUpdate) -PropertyType DWord -Force | Out-Null + $ChangedSettings++ } - elseif ($null -eq $WAUPolicies.WAU_DisableAutoUpdate) { - Remove-ItemProperty $regPath"\" -Name WAU_DisableAutoUpdate -Force -ErrorAction SilentlyContinue | Out-Null + elseif ($null -eq $($WAUPolicies.WAU_DisableAutoUpdate) -and ($($WAUConfig.WAU_DisableAutoUpdate) -or $($WAUConfig.WAU_DisableAutoUpdate) -eq 0)) { + Remove-ItemProperty $regPath -Name WAU_DisableAutoUpdate -Force -ErrorAction SilentlyContinue | Out-Null + $ChangedSettings++ } - if ($null -ne $WAUPolicies.WAU_DoNotRunOnMetered -and ($WAUPolicies.WAU_DoNotRunOnMetered -ne $WAUConfig.WAU_DoNotRunOnMetered)) { - New-ItemProperty $regPath -Name WAU_DoNotRunOnMetered -Value $WAUPolicies.WAU_DoNotRunOnMetered -PropertyType DWord -Force | Out-Null + if ($null -ne $($WAUPolicies.WAU_DoNotRunOnMetered) -and ($($WAUPolicies.WAU_DoNotRunOnMetered) -ne $($WAUConfig.WAU_DoNotRunOnMetered))) { + New-ItemProperty $regPath -Name WAU_DoNotRunOnMetered -Value $($WAUPolicies.WAU_DoNotRunOnMetered) -PropertyType DWord -Force | Out-Null + $ChangedSettings++ } - elseif ($null -eq $WAUPolicies.WAU_DoNotRunOnMetered) { + elseif ($null -eq $($WAUPolicies.WAU_DoNotRunOnMetered) -and !$($WAUConfig.WAU_DoNotRunOnMetered)) { New-ItemProperty $regPath -Name WAU_DoNotRunOnMetered -Value 1 -PropertyType DWord -Force | Out-Null + $ChangedSettings++ } - if ($null -ne $WAUPolicies.WAU_UpdatePrerelease -and ($WAUPolicies.WAU_UpdatePrerelease -ne $WAUConfig.WAU_UpdatePrerelease)) { - New-ItemProperty $regPath -Name WAU_UpdatePrerelease -Value $WAUPolicies.WAU_UpdatePrerelease -PropertyType DWord -Force | Out-Null + if ($null -ne $($WAUPolicies.WAU_UpdatePrerelease) -and ($($WAUPolicies.WAU_UpdatePrerelease) -ne $($WAUConfig.WAU_UpdatePrerelease))) { + New-ItemProperty $regPath -Name WAU_UpdatePrerelease -Value $($WAUPolicies.WAU_UpdatePrerelease) -PropertyType DWord -Force | Out-Null + $ChangedSettings++ } - elseif ($null -eq $WAUPolicies.WAU_UpdatePrerelease) { + elseif ($null -eq $($WAUPolicies.WAU_UpdatePrerelease) -and $($WAUConfig.WAU_UpdatePrerelease)) { New-ItemProperty $regPath -Name WAU_UpdatePrerelease -Value 0 -PropertyType DWord -Force | Out-Null + $ChangedSettings++ } - if ($null -ne $WAUPolicies.WAU_UseWhiteList -and ($WAUPolicies.WAU_UseWhiteList -eq 1) -and ($WAUPolicies.WAU_UseWhiteList -ne $WAUConfig.WAU_UseWhiteList)) { - New-ItemProperty $regPath -Name WAU_UseWhiteList -Value $WAUPolicies.WAU_UseWhiteList -PropertyType DWord -Force | Out-Null + if ($null -ne $($WAUPolicies.WAU_UseWhiteList) -and ($($WAUPolicies.WAU_UseWhiteList) -ne $($WAUConfig.WAU_UseWhiteList))) { + New-ItemProperty $regPath -Name WAU_UseWhiteList -Value $($WAUPolicies.WAU_UseWhiteList) -PropertyType DWord -Force | Out-Null + $ChangedSettings++ } - elseif ($null -eq $WAUPolicies.WAU_UseWhiteList -or $WAUPolicies.WAU_UseWhiteList -eq 0) { + elseif ($null -eq $($WAUPolicies.WAU_UseWhiteList) -and ($($WAUConfig.WAU_UseWhiteList) -or $($WAUConfig.WAU_UseWhiteList) -eq 0)) { Remove-ItemProperty $regPath -Name WAU_UseWhiteList -Force -ErrorAction SilentlyContinue | Out-Null + $ChangedSettings++ } - if ($null -ne $WAUPolicies.WAU_ListPath -and ($WAUPolicies.WAU_ListPath -ne $WAUConfig.WAU_ListPath)) { - New-ItemProperty $regPath -Name WAU_ListPath -Value $WAUPolicies.WAU_ListPath -Force | Out-Null + if ($null -ne $($WAUPolicies.WAU_ListPath) -and ($($WAUPolicies.WAU_ListPath) -ne $($WAUConfig.WAU_ListPath))) { + New-ItemProperty $regPath -Name WAU_ListPath -Value $($WAUPolicies.WAU_ListPath) -Force | Out-Null + $ChangedSettings++ } - elseif ($null -eq $WAUPolicies.WAU_ListPath) { - Remove-ItemProperty $regPath"\" -Name WAU_ListPath -Force -ErrorAction SilentlyContinue | Out-Null + elseif ($null -eq $($WAUPolicies.WAU_ListPath) -and $($WAUConfig.WAU_ListPath)) { + Remove-ItemProperty $regPath -Name WAU_ListPath -Force -ErrorAction SilentlyContinue | Out-Null + $ChangedSettings++ } - if ($null -ne $WAUPolicies.WAU_ModsPath -and ($WAUPolicies.WAU_ModsPath -ne $WAUConfig.WAU_ModsPath)) { - New-ItemProperty $regPath -Name WAU_ModsPath -Value $WAUPolicies.WAU_ModsPath -Force | Out-Null + if ($null -ne $($WAUPolicies.WAU_ModsPath) -and ($($WAUPolicies.WAU_ModsPath) -ne $($WAUConfig.WAU_ModsPath))) { + New-ItemProperty $regPath -Name WAU_ModsPath -Value $($WAUPolicies.WAU_ModsPath) -Force | Out-Null + $ChangedSettings++ } - elseif ($null -eq $WAUPolicies.WAU_ModsPath) { - Remove-ItemProperty $regPath"\" -Name WAU_ModsPath -Force -ErrorAction SilentlyContinue | Out-Null + elseif ($null -eq $($WAUPolicies.WAU_ModsPath) -and $($WAUConfig.WAU_ModsPath)) { + Remove-ItemProperty $regPath -Name WAU_ModsPath -Force -ErrorAction SilentlyContinue | Out-Null + $ChangedSettings++ } - if ($null -ne $WAUPolicies.WAU_NotificationLevel -and ($WAUPolicies.WAU_NotificationLevel -ne $WAUConfig.WAU_NotificationLevel)) { - New-ItemProperty $regPath -Name WAU_NotificationLevel -Value $WAUPolicies.WAU_NotificationLevel -Force | Out-Null + if ($null -ne $($WAUPolicies.WAU_NotificationLevel) -and ($($WAUPolicies.WAU_NotificationLevel) -ne $($WAUConfig.WAU_NotificationLevel))) { + New-ItemProperty $regPath -Name WAU_NotificationLevel -Value $($WAUPolicies.WAU_NotificationLevel) -Force | Out-Null + $ChangedSettings++ } - elseif ($null -eq $WAUPolicies.WAU_NotificationLevel) { + elseif ($null -eq $($WAUPolicies.WAU_NotificationLevel) -and $($WAUConfig.WAU_NotificationLevel) -ne "Full") { New-ItemProperty $regPath -Name WAU_NotificationLevel -Value "Full" -Force | Out-Null + $ChangedSettings++ } + if ($ChangedSettings -gt 0) { + Write-Log "Changed settings: $ChangedSettings" "Yellow" + } #Get WAU Configurations after Policies change $Script:WAUConfig = Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate" } From 449152437825a10edda9ac802d05a0a4cf331ce1 Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Thu, 29 Dec 2022 04:31:01 +0100 Subject: [PATCH 15/86] Lists/Mods Path error handling --- Winget-AutoUpdate/Winget-Upgrade.ps1 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Winget-AutoUpdate/Winget-Upgrade.ps1 b/Winget-AutoUpdate/Winget-Upgrade.ps1 index d082ea0d..09c3e014 100644 --- a/Winget-AutoUpdate/Winget-Upgrade.ps1 +++ b/Winget-AutoUpdate/Winget-Upgrade.ps1 @@ -72,8 +72,8 @@ if ($IsSystem) { $ChangedSettings++ } - if ($null -ne $($WAUPolicies.WAU_ListPath) -and ($($WAUPolicies.WAU_ListPath) -ne $($WAUConfig.WAU_ListPath))) { - New-ItemProperty $regPath -Name WAU_ListPath -Value $($WAUPolicies.WAU_ListPath) -Force | Out-Null + if ($null -ne $($WAUPolicies.WAU_ListPath) -and ($($WAUPolicies.WAU_ListPath.TrimEnd(" ", "\", "/")) -ne $($WAUConfig.WAU_ListPath.TrimEnd(" ", "\", "/")))) { + New-ItemProperty $regPath -Name WAU_ListPath -Value $($WAUPolicies.WAU_ListPath.TrimEnd(" ", "\", "/")) -Force | Out-Null $ChangedSettings++ } elseif ($null -eq $($WAUPolicies.WAU_ListPath) -and $($WAUConfig.WAU_ListPath)) { @@ -81,8 +81,8 @@ if ($IsSystem) { $ChangedSettings++ } - if ($null -ne $($WAUPolicies.WAU_ModsPath) -and ($($WAUPolicies.WAU_ModsPath) -ne $($WAUConfig.WAU_ModsPath))) { - New-ItemProperty $regPath -Name WAU_ModsPath -Value $($WAUPolicies.WAU_ModsPath) -Force | Out-Null + if ($null -ne $($WAUPolicies.WAU_ModsPath) -and ($($WAUPolicies.WAU_ModsPath.TrimEnd(" ", "\", "/")) -ne $($WAUConfig.WAU_ModsPath.TrimEnd(" ", "\", "/")))) { + New-ItemProperty $regPath -Name WAU_ModsPath -Value $($WAUPolicies.WAU_ModsPath.TrimEnd(" ", "\", "/")) -Force | Out-Null $ChangedSettings++ } elseif ($null -eq $($WAUPolicies.WAU_ModsPath) -and $($WAUConfig.WAU_ModsPath)) { From 937e281ad081990c0d9a0f0baebadd11c4acdd90 Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Thu, 29 Dec 2022 07:57:36 +0100 Subject: [PATCH 16/86] Managed Update Frequency for the Scheduler --- Policies/WAU.admx | 38 ++++++++++++++++++++++++++++ Policies/en-US/WAU.adml | 19 ++++++++++++++ Winget-AutoUpdate/Winget-Upgrade.ps1 | 20 +++++++++++++++ 3 files changed, 77 insertions(+) diff --git a/Policies/WAU.admx b/Policies/WAU.admx index bcf4d137..6b7b0ecf 100644 --- a/Policies/WAU.admx +++ b/Policies/WAU.admx @@ -113,5 +113,43 @@ + + + + + + + + -Daily -At 06am + + + + + -Daily -At 06am -DaysInterval 2 + + + + + -Weekly -At 06am + + + + + -Weekly -At 06am -WeeksInterval 2 + + + + + -Weekly -At 06am -WeeksInterval 4 + + + + + Never + + + + + \ No newline at end of file diff --git a/Policies/en-US/WAU.adml b/Policies/en-US/WAU.adml index 99d26243..02bf0c6a 100644 --- a/Policies/en-US/WAU.adml +++ b/Policies/en-US/WAU.adml @@ -32,6 +32,22 @@ If this policy is not configured or disabled, the Default displays all notificat 1. Full (Default, displays all notifications) 2. SuccessOnly (Only displays notifications for success) 3. None (Does not display any notification) + Update Frequency + If this policy is enabled, you can configure the Update Frequency: +1. Daily (Default) +2. BiDaily +3. Weekly +4. BiWeekly +5. Monthly +6. Never (Can be set to 'Never' in combination with '-UpdatesAtLogon' for instance) + +If this policy is not configured or disabled, update frequency: (1. Daily). + 1. Daily (Default) + 2. BiDaily + 3. Weekly + 4. BiWeekly + 5. Monthly + 6. Never (Can be set to 'Never' in combination with '-UpdatesAtLogon' for instance) @@ -47,6 +63,9 @@ If this policy is not configured or disabled, the Default displays all notificat + + + diff --git a/Winget-AutoUpdate/Winget-Upgrade.ps1 b/Winget-AutoUpdate/Winget-Upgrade.ps1 index 09c3e014..3240d403 100644 --- a/Winget-AutoUpdate/Winget-Upgrade.ps1 +++ b/Winget-AutoUpdate/Winget-Upgrade.ps1 @@ -99,6 +99,26 @@ if ($IsSystem) { $ChangedSettings++ } + if ($null -ne $($WAUPolicies.WAU_UpdatesInterval) -and ($($WAUPolicies.WAU_UpdatesInterval) -ne $($WAUConfig.UpdatesInterval))) { + New-ItemProperty $regPath -Name WAU_UpdatesInterval -Value $($WAUPolicies.WAU_UpdatesInterval) -Force | Out-Null + switch ($($WAUPolicies.WAU_UpdatesInterval)) { + "-Daily -At 06am" {$tasktrigger = New-ScheduledTaskTrigger -Daily -At 06am; Set-ScheduledTask -TaskName "Winget-AutoUpdate" -Trigger $tasktrigger; break} + "-Daily -At 06am -DaysInterval 2" {$tasktrigger = New-ScheduledTaskTrigger -Daily -At 06am -DaysInterval 2; Set-ScheduledTask -TaskName "Winget-AutoUpdate" -Trigger $tasktrigger; break} + "-Weekly -At 06am" {$tasktrigger = New-ScheduledTaskTrigger -Weekly -At 06am; Set-ScheduledTask -TaskName "Winget-AutoUpdate" -Trigger $tasktrigger; break} + "-Weekly -At 06am -WeeksInterval 2" {$tasktrigger = New-ScheduledTaskTrigger -Weekly -At 06am -WeeksInterval 2; Set-ScheduledTask -TaskName "Winget-AutoUpdate" -Trigger $tasktrigger; break} + "-Weekly -At 06am -WeeksInterval 4" {$tasktrigger = New-ScheduledTaskTrigger -Weekly -At 06am -WeeksInterval 4; Set-ScheduledTask -TaskName "Winget-AutoUpdate" -Trigger $tasktrigger; break} + "Never" {$service = New-Object -ComObject Schedule.Service; $service.Connect($env:COMPUTERNAME); $folder = $service.GetFolder('\'); $task = $folder.GetTask("Winget-AutoUpdate"); $definition = $task.Definition; $definition.Triggers.Remove(1); $folder.RegisterTaskDefinition($task.Name, $definition, 4, $null, $null, $null) | Out-Null; break} + default {"Something else happened"; break} + } + $ChangedSettings++ + } + elseif ($null -eq $($WAUPolicies.WAU_UpdatesInterval) -and $($WAUConfig.WAU_UpdatesInterval) -ne "-Daily -At 06am") { + New-ItemProperty $regPath -Name WAU_UpdatesInterval -Value "-Daily -At 06am" -Force | Out-Null + $tasktrigger = New-ScheduledTaskTrigger -Daily -At 06am + Set-ScheduledTask -TaskName "Winget-AutoUpdate" -Trigger $tasktrigger + $ChangedSettings++ + } + if ($ChangedSettings -gt 0) { Write-Log "Changed settings: $ChangedSettings" "Yellow" } From 633da298b2b61961ff4dd6244448ba37dff4bfe2 Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Thu, 29 Dec 2022 08:58:46 +0100 Subject: [PATCH 17/86] Fixes --- Policies/WAU.admx | 10 +++++----- Policies/en-US/WAU.adml | 4 ++-- Winget-AutoUpdate/Winget-Upgrade.ps1 | 28 +++++++++++++++++++--------- 3 files changed, 26 insertions(+), 16 deletions(-) diff --git a/Policies/WAU.admx b/Policies/WAU.admx index 6b7b0ecf..c485b861 100644 --- a/Policies/WAU.admx +++ b/Policies/WAU.admx @@ -120,27 +120,27 @@ - -Daily -At 06am + Daily - -Daily -At 06am -DaysInterval 2 + BiDaily - -Weekly -At 06am + Weekly - -Weekly -At 06am -WeeksInterval 2 + BiWeekly - -Weekly -At 06am -WeeksInterval 4 + Monthly diff --git a/Policies/en-US/WAU.adml b/Policies/en-US/WAU.adml index 02bf0c6a..8e08f997 100644 --- a/Policies/en-US/WAU.adml +++ b/Policies/en-US/WAU.adml @@ -39,7 +39,7 @@ If this policy is not configured or disabled, the Default displays all notificat 3. Weekly 4. BiWeekly 5. Monthly -6. Never (Can be set to 'Never' in combination with '-UpdatesAtLogon' for instance) +6. Never (in combination with '-UpdatesAtLogon' for instance) If this policy is not configured or disabled, update frequency: (1. Daily). 1. Daily (Default) @@ -47,7 +47,7 @@ If this policy is not configured or disabled, update frequency: (1. Daily).3. Weekly 4. BiWeekly 5. Monthly - 6. Never (Can be set to 'Never' in combination with '-UpdatesAtLogon' for instance) + 6. Never (in combination with '-UpdatesAtLogon' for instance) diff --git a/Winget-AutoUpdate/Winget-Upgrade.ps1 b/Winget-AutoUpdate/Winget-Upgrade.ps1 index 3240d403..1087d3db 100644 --- a/Winget-AutoUpdate/Winget-Upgrade.ps1 +++ b/Winget-AutoUpdate/Winget-Upgrade.ps1 @@ -99,21 +99,31 @@ if ($IsSystem) { $ChangedSettings++ } - if ($null -ne $($WAUPolicies.WAU_UpdatesInterval) -and ($($WAUPolicies.WAU_UpdatesInterval) -ne $($WAUConfig.UpdatesInterval))) { + if ($null -ne $($WAUPolicies.WAU_UpdatesInterval) -and ($($WAUPolicies.WAU_UpdatesInterval) -ne $($WAUConfig.WAU_UpdatesInterval))) { New-ItemProperty $regPath -Name WAU_UpdatesInterval -Value $($WAUPolicies.WAU_UpdatesInterval) -Force | Out-Null switch ($($WAUPolicies.WAU_UpdatesInterval)) { - "-Daily -At 06am" {$tasktrigger = New-ScheduledTaskTrigger -Daily -At 06am; Set-ScheduledTask -TaskName "Winget-AutoUpdate" -Trigger $tasktrigger; break} - "-Daily -At 06am -DaysInterval 2" {$tasktrigger = New-ScheduledTaskTrigger -Daily -At 06am -DaysInterval 2; Set-ScheduledTask -TaskName "Winget-AutoUpdate" -Trigger $tasktrigger; break} - "-Weekly -At 06am" {$tasktrigger = New-ScheduledTaskTrigger -Weekly -At 06am; Set-ScheduledTask -TaskName "Winget-AutoUpdate" -Trigger $tasktrigger; break} - "-Weekly -At 06am -WeeksInterval 2" {$tasktrigger = New-ScheduledTaskTrigger -Weekly -At 06am -WeeksInterval 2; Set-ScheduledTask -TaskName "Winget-AutoUpdate" -Trigger $tasktrigger; break} - "-Weekly -At 06am -WeeksInterval 4" {$tasktrigger = New-ScheduledTaskTrigger -Weekly -At 06am -WeeksInterval 4; Set-ScheduledTask -TaskName "Winget-AutoUpdate" -Trigger $tasktrigger; break} - "Never" {$service = New-Object -ComObject Schedule.Service; $service.Connect($env:COMPUTERNAME); $folder = $service.GetFolder('\'); $task = $folder.GetTask("Winget-AutoUpdate"); $definition = $task.Definition; $definition.Triggers.Remove(1); $folder.RegisterTaskDefinition($task.Name, $definition, 4, $null, $null, $null) | Out-Null; break} + "Daily" {$tasktrigger = New-ScheduledTaskTrigger -Daily -At 06am; Set-ScheduledTask -TaskName "Winget-AutoUpdate" -Trigger $tasktrigger; break} + "BiDaily" {$tasktrigger = New-ScheduledTaskTrigger -Daily -At 06am -DaysInterval 2; Set-ScheduledTask -TaskName "Winget-AutoUpdate" -Trigger $tasktrigger; break} + "Weekly" {$tasktrigger = New-ScheduledTaskTrigger -Weekly -At 06am -DaysOfWeek 2; Set-ScheduledTask -TaskName "Winget-AutoUpdate" -Trigger $tasktrigger; break} + "BiWeekly" {$tasktrigger = New-ScheduledTaskTrigger -Weekly -At 06am -DaysOfWeek 2 -WeeksInterval 2; Set-ScheduledTask -TaskName "Winget-AutoUpdate" -Trigger $tasktrigger; break} + "Monthly" {$tasktrigger = New-ScheduledTaskTrigger -Weekly -At 06am -DaysOfWeek 2 -WeeksInterval 4; Set-ScheduledTask -TaskName "Winget-AutoUpdate" -Trigger $tasktrigger; break} + "Never" {"Deleting the Scheduled trigger..."; break} default {"Something else happened"; break} } + if ($($WAUPolicies.WAU_UpdatesInterval) -eq "Never") { + $service = New-Object -ComObject Schedule.Service + $service.Connect($env:COMPUTERNAME) + $folder = $service.GetFolder('\') + $task = $folder.GetTask("Winget-AutoUpdate") + $definition = $task.Definition + $definition.Triggers.Remove(1) + $folder.RegisterTaskDefinition($task.Name, $definition, 4, $null, $null, $null) | Out-Null + + } $ChangedSettings++ } - elseif ($null -eq $($WAUPolicies.WAU_UpdatesInterval) -and $($WAUConfig.WAU_UpdatesInterval) -ne "-Daily -At 06am") { - New-ItemProperty $regPath -Name WAU_UpdatesInterval -Value "-Daily -At 06am" -Force | Out-Null + elseif ($null -eq $($WAUPolicies.WAU_UpdatesInterval) -and $($WAUConfig.WAU_UpdatesInterval) -ne "Daily") { + New-ItemProperty $regPath -Name WAU_UpdatesInterval -Value "Daily" -Force | Out-Null $tasktrigger = New-ScheduledTaskTrigger -Daily -At 06am Set-ScheduledTask -TaskName "Winget-AutoUpdate" -Trigger $tasktrigger $ChangedSettings++ From 87cf2af1712d39b2600fda0c73fb288b2c3f61ff Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Fri, 30 Dec 2022 08:55:27 +0100 Subject: [PATCH 18/86] Mostly done --- Policies/WAU.admx | 20 +- Policies/en-US/WAU.adml | 14 +- Winget-AutoUpdate/Winget-Upgrade.ps1 | 116 +--------- Winget-AutoUpdate/functions/Get-Policies.ps1 | 226 +++++++++++++++++++ 4 files changed, 251 insertions(+), 125 deletions(-) create mode 100644 Winget-AutoUpdate/functions/Get-Policies.ps1 diff --git a/Policies/WAU.admx b/Policies/WAU.admx index c485b861..e58a8433 100644 --- a/Policies/WAU.admx +++ b/Policies/WAU.admx @@ -76,21 +76,21 @@ - + - + - + @@ -113,7 +113,7 @@ - + @@ -150,6 +150,16 @@ + + + + + + + + + + - \ No newline at end of file + diff --git a/Policies/en-US/WAU.adml b/Policies/en-US/WAU.adml index 8e08f997..dc50669e 100644 --- a/Policies/en-US/WAU.adml +++ b/Policies/en-US/WAU.adml @@ -18,11 +18,11 @@ This policy setting specifies whether to update WAU (if enabled) to PreRelease versions or not. Default No. Use WhiteList instead of BlackList This policy setting specifies whether to use a WhiteList or not. Default Blacklist. - Get Black/White List from external Path (URL/UNC/Local) + Get Black/White List from external Path (URL/UNC/Local) If this policy is enabled, you can set a (URL/UNC/Local) Path to external lists other than the default. If this policy is disabled or not configured, the default ListPath is used. - Get Mods from external Path (URL/UNC/Local) + Get Mods from external Path (URL/UNC/Local) If this policy is enabled, you can set a (URL/UNC/Local) Path to external mods other than the default. If this policy is disabled or not configured, the default ModsPath is used. - Notification Level + Notification Level If this policy is enabled, you can configure the Notification Level: 1. Full (Default, displays all notifications) 2. SuccessOnly (Only displays notifications for success) @@ -32,8 +32,8 @@ If this policy is not configured or disabled, the Default displays all notificat 1. Full (Default, displays all notifications) 2. SuccessOnly (Only displays notifications for success) 3. None (Does not display any notification) - Update Frequency - If this policy is enabled, you can configure the Update Frequency: + Updates Interval + If this policy is enabled, you can configure the Updates Interval: 1. Daily (Default) 2. BiDaily 3. Weekly @@ -41,13 +41,15 @@ If this policy is not configured or disabled, the Default displays all notificat 5. Monthly 6. Never (in combination with '-UpdatesAtLogon' for instance) -If this policy is not configured or disabled, update frequency: (1. Daily). +If this policy is not configured or disabled, Updates Interval: (1. Daily). 1. Daily (Default) 2. BiDaily 3. Weekly 4. BiWeekly 5. Monthly 6. Never (in combination with '-UpdatesAtLogon' for instance) + Updates at Logon + This policy setting specifies whether to set WAU to run at user logon or not. By default, No. diff --git a/Winget-AutoUpdate/Winget-Upgrade.ps1 b/Winget-AutoUpdate/Winget-Upgrade.ps1 index 1087d3db..38703cb9 100644 --- a/Winget-AutoUpdate/Winget-Upgrade.ps1 +++ b/Winget-AutoUpdate/Winget-Upgrade.ps1 @@ -20,122 +20,10 @@ $Script:WAUConfig = Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\Cur #Log running context and more... if ($IsSystem) { Write-Log "Running in System context" - #Get WAU Policies and set the Configurations Registry Accordingly - $WAUPolicies = Get-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Romanitho\Winget-AutoUpdate" -ErrorAction SilentlyContinue - if ($WAUPolicies) { - if ($($WAUPolicies.WAU_ActivateGPOManagement -eq 1)) { - $ChangedSettings = 0 - Write-Log "Activated WAU GPO Management detected, comparing..." - $regPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate" - if ($null -ne $($WAUPolicies.WAU_BypassListForUsers) -and ($($WAUPolicies.WAU_BypassListForUsers) -ne $($WAUConfig.WAU_BypassListForUsers))) { - New-ItemProperty $regPath -Name WAU_BypassListForUsers -Value $($WAUPolicies.WAU_BypassListForUsers) -PropertyType DWord -Force | Out-Null - $ChangedSettings++ - } - elseif ($null -eq $($WAUPolicies.WAU_BypassListForUsers) -and ($($WAUConfig.WAU_BypassListForUsers) -or $($WAUConfig.WAU_BypassListForUsers) -eq 0)) { - Remove-ItemProperty $regPath -Name WAU_BypassListForUsers -Force -ErrorAction SilentlyContinue | Out-Null - $ChangedSettings++ - } - - if ($null -ne $($WAUPolicies.WAU_DisableAutoUpdate) -and ($($WAUPolicies.WAU_DisableAutoUpdate) -ne $($WAUConfig.WAU_DisableAutoUpdate))) { - New-ItemProperty $regPath -Name WAU_DisableAutoUpdate -Value $($WAUPolicies.WAU_DisableAutoUpdate) -PropertyType DWord -Force | Out-Null - $ChangedSettings++ - } - elseif ($null -eq $($WAUPolicies.WAU_DisableAutoUpdate) -and ($($WAUConfig.WAU_DisableAutoUpdate) -or $($WAUConfig.WAU_DisableAutoUpdate) -eq 0)) { - Remove-ItemProperty $regPath -Name WAU_DisableAutoUpdate -Force -ErrorAction SilentlyContinue | Out-Null - $ChangedSettings++ - } - - if ($null -ne $($WAUPolicies.WAU_DoNotRunOnMetered) -and ($($WAUPolicies.WAU_DoNotRunOnMetered) -ne $($WAUConfig.WAU_DoNotRunOnMetered))) { - New-ItemProperty $regPath -Name WAU_DoNotRunOnMetered -Value $($WAUPolicies.WAU_DoNotRunOnMetered) -PropertyType DWord -Force | Out-Null - $ChangedSettings++ - } - elseif ($null -eq $($WAUPolicies.WAU_DoNotRunOnMetered) -and !$($WAUConfig.WAU_DoNotRunOnMetered)) { - New-ItemProperty $regPath -Name WAU_DoNotRunOnMetered -Value 1 -PropertyType DWord -Force | Out-Null - $ChangedSettings++ - } - - if ($null -ne $($WAUPolicies.WAU_UpdatePrerelease) -and ($($WAUPolicies.WAU_UpdatePrerelease) -ne $($WAUConfig.WAU_UpdatePrerelease))) { - New-ItemProperty $regPath -Name WAU_UpdatePrerelease -Value $($WAUPolicies.WAU_UpdatePrerelease) -PropertyType DWord -Force | Out-Null - $ChangedSettings++ - } - elseif ($null -eq $($WAUPolicies.WAU_UpdatePrerelease) -and $($WAUConfig.WAU_UpdatePrerelease)) { - New-ItemProperty $regPath -Name WAU_UpdatePrerelease -Value 0 -PropertyType DWord -Force | Out-Null - $ChangedSettings++ - } - - if ($null -ne $($WAUPolicies.WAU_UseWhiteList) -and ($($WAUPolicies.WAU_UseWhiteList) -ne $($WAUConfig.WAU_UseWhiteList))) { - New-ItemProperty $regPath -Name WAU_UseWhiteList -Value $($WAUPolicies.WAU_UseWhiteList) -PropertyType DWord -Force | Out-Null - $ChangedSettings++ - } - elseif ($null -eq $($WAUPolicies.WAU_UseWhiteList) -and ($($WAUConfig.WAU_UseWhiteList) -or $($WAUConfig.WAU_UseWhiteList) -eq 0)) { - Remove-ItemProperty $regPath -Name WAU_UseWhiteList -Force -ErrorAction SilentlyContinue | Out-Null - $ChangedSettings++ - } - - if ($null -ne $($WAUPolicies.WAU_ListPath) -and ($($WAUPolicies.WAU_ListPath.TrimEnd(" ", "\", "/")) -ne $($WAUConfig.WAU_ListPath.TrimEnd(" ", "\", "/")))) { - New-ItemProperty $regPath -Name WAU_ListPath -Value $($WAUPolicies.WAU_ListPath.TrimEnd(" ", "\", "/")) -Force | Out-Null - $ChangedSettings++ - } - elseif ($null -eq $($WAUPolicies.WAU_ListPath) -and $($WAUConfig.WAU_ListPath)) { - Remove-ItemProperty $regPath -Name WAU_ListPath -Force -ErrorAction SilentlyContinue | Out-Null - $ChangedSettings++ - } - - if ($null -ne $($WAUPolicies.WAU_ModsPath) -and ($($WAUPolicies.WAU_ModsPath.TrimEnd(" ", "\", "/")) -ne $($WAUConfig.WAU_ModsPath.TrimEnd(" ", "\", "/")))) { - New-ItemProperty $regPath -Name WAU_ModsPath -Value $($WAUPolicies.WAU_ModsPath.TrimEnd(" ", "\", "/")) -Force | Out-Null - $ChangedSettings++ - } - elseif ($null -eq $($WAUPolicies.WAU_ModsPath) -and $($WAUConfig.WAU_ModsPath)) { - Remove-ItemProperty $regPath -Name WAU_ModsPath -Force -ErrorAction SilentlyContinue | Out-Null - $ChangedSettings++ - } - - if ($null -ne $($WAUPolicies.WAU_NotificationLevel) -and ($($WAUPolicies.WAU_NotificationLevel) -ne $($WAUConfig.WAU_NotificationLevel))) { - New-ItemProperty $regPath -Name WAU_NotificationLevel -Value $($WAUPolicies.WAU_NotificationLevel) -Force | Out-Null - $ChangedSettings++ - } - elseif ($null -eq $($WAUPolicies.WAU_NotificationLevel) -and $($WAUConfig.WAU_NotificationLevel) -ne "Full") { - New-ItemProperty $regPath -Name WAU_NotificationLevel -Value "Full" -Force | Out-Null - $ChangedSettings++ - } - - if ($null -ne $($WAUPolicies.WAU_UpdatesInterval) -and ($($WAUPolicies.WAU_UpdatesInterval) -ne $($WAUConfig.WAU_UpdatesInterval))) { - New-ItemProperty $regPath -Name WAU_UpdatesInterval -Value $($WAUPolicies.WAU_UpdatesInterval) -Force | Out-Null - switch ($($WAUPolicies.WAU_UpdatesInterval)) { - "Daily" {$tasktrigger = New-ScheduledTaskTrigger -Daily -At 06am; Set-ScheduledTask -TaskName "Winget-AutoUpdate" -Trigger $tasktrigger; break} - "BiDaily" {$tasktrigger = New-ScheduledTaskTrigger -Daily -At 06am -DaysInterval 2; Set-ScheduledTask -TaskName "Winget-AutoUpdate" -Trigger $tasktrigger; break} - "Weekly" {$tasktrigger = New-ScheduledTaskTrigger -Weekly -At 06am -DaysOfWeek 2; Set-ScheduledTask -TaskName "Winget-AutoUpdate" -Trigger $tasktrigger; break} - "BiWeekly" {$tasktrigger = New-ScheduledTaskTrigger -Weekly -At 06am -DaysOfWeek 2 -WeeksInterval 2; Set-ScheduledTask -TaskName "Winget-AutoUpdate" -Trigger $tasktrigger; break} - "Monthly" {$tasktrigger = New-ScheduledTaskTrigger -Weekly -At 06am -DaysOfWeek 2 -WeeksInterval 4; Set-ScheduledTask -TaskName "Winget-AutoUpdate" -Trigger $tasktrigger; break} - "Never" {"Deleting the Scheduled trigger..."; break} - default {"Something else happened"; break} - } - if ($($WAUPolicies.WAU_UpdatesInterval) -eq "Never") { - $service = New-Object -ComObject Schedule.Service - $service.Connect($env:COMPUTERNAME) - $folder = $service.GetFolder('\') - $task = $folder.GetTask("Winget-AutoUpdate") - $definition = $task.Definition - $definition.Triggers.Remove(1) - $folder.RegisterTaskDefinition($task.Name, $definition, 4, $null, $null, $null) | Out-Null - } - $ChangedSettings++ - } - elseif ($null -eq $($WAUPolicies.WAU_UpdatesInterval) -and $($WAUConfig.WAU_UpdatesInterval) -ne "Daily") { - New-ItemProperty $regPath -Name WAU_UpdatesInterval -Value "Daily" -Force | Out-Null - $tasktrigger = New-ScheduledTaskTrigger -Daily -At 06am - Set-ScheduledTask -TaskName "Winget-AutoUpdate" -Trigger $tasktrigger - $ChangedSettings++ - } + #Get and set Domain/Local Policies (GPO) + Get-Policies - if ($ChangedSettings -gt 0) { - Write-Log "Changed settings: $ChangedSettings" "Yellow" - } - #Get WAU Configurations after Policies change - $Script:WAUConfig = Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate" - } - } #Run post update actions if necessary if run as System if (!($WAUConfig.WAU_PostUpdateActions -eq 0)) { Invoke-PostUpdateActions diff --git a/Winget-AutoUpdate/functions/Get-Policies.ps1 b/Winget-AutoUpdate/functions/Get-Policies.ps1 new file mode 100644 index 00000000..71ef80db --- /dev/null +++ b/Winget-AutoUpdate/functions/Get-Policies.ps1 @@ -0,0 +1,226 @@ +#Function to get Domain/Local Policies (GPO) + +Function Get-Policies { + #Get WAU Policies and set the Configurations Registry Accordingly + $WAUPolicies = Get-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Romanitho\Winget-AutoUpdate" -ErrorAction SilentlyContinue + if ($WAUPolicies) { + if ($($WAUPolicies.WAU_ActivateGPOManagement -eq 1)) { + $ChangedSettings = 0 + Write-Log "Activated WAU GPO Management detected, comparing..." + $regPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate" + if ($null -ne $($WAUPolicies.WAU_BypassListForUsers) -and ($($WAUPolicies.WAU_BypassListForUsers) -ne $($WAUConfig.WAU_BypassListForUsers))) { + New-ItemProperty $regPath -Name WAU_BypassListForUsers -Value $($WAUPolicies.WAU_BypassListForUsers) -PropertyType DWord -Force | Out-Null + $ChangedSettings++ + } + elseif ($null -eq $($WAUPolicies.WAU_BypassListForUsers) -and ($($WAUConfig.WAU_BypassListForUsers) -or $($WAUConfig.WAU_BypassListForUsers) -eq 0)) { + Remove-ItemProperty $regPath -Name WAU_BypassListForUsers -Force -ErrorAction SilentlyContinue | Out-Null + $ChangedSettings++ + } + + if ($null -ne $($WAUPolicies.WAU_DisableAutoUpdate) -and ($($WAUPolicies.WAU_DisableAutoUpdate) -ne $($WAUConfig.WAU_DisableAutoUpdate))) { + New-ItemProperty $regPath -Name WAU_DisableAutoUpdate -Value $($WAUPolicies.WAU_DisableAutoUpdate) -PropertyType DWord -Force | Out-Null + $ChangedSettings++ + } + elseif ($null -eq $($WAUPolicies.WAU_DisableAutoUpdate) -and ($($WAUConfig.WAU_DisableAutoUpdate) -or $($WAUConfig.WAU_DisableAutoUpdate) -eq 0)) { + Remove-ItemProperty $regPath -Name WAU_DisableAutoUpdate -Force -ErrorAction SilentlyContinue | Out-Null + $ChangedSettings++ + } + + if ($null -ne $($WAUPolicies.WAU_DoNotRunOnMetered) -and ($($WAUPolicies.WAU_DoNotRunOnMetered) -ne $($WAUConfig.WAU_DoNotRunOnMetered))) { + New-ItemProperty $regPath -Name WAU_DoNotRunOnMetered -Value $($WAUPolicies.WAU_DoNotRunOnMetered) -PropertyType DWord -Force | Out-Null + $ChangedSettings++ + } + elseif ($null -eq $($WAUPolicies.WAU_DoNotRunOnMetered) -and !$($WAUConfig.WAU_DoNotRunOnMetered)) { + New-ItemProperty $regPath -Name WAU_DoNotRunOnMetered -Value 1 -PropertyType DWord -Force | Out-Null + $ChangedSettings++ + } + + if ($null -ne $($WAUPolicies.WAU_UpdatePrerelease) -and ($($WAUPolicies.WAU_UpdatePrerelease) -ne $($WAUConfig.WAU_UpdatePrerelease))) { + New-ItemProperty $regPath -Name WAU_UpdatePrerelease -Value $($WAUPolicies.WAU_UpdatePrerelease) -PropertyType DWord -Force | Out-Null + $ChangedSettings++ + } + elseif ($null -eq $($WAUPolicies.WAU_UpdatePrerelease) -and $($WAUConfig.WAU_UpdatePrerelease)) { + New-ItemProperty $regPath -Name WAU_UpdatePrerelease -Value 0 -PropertyType DWord -Force | Out-Null + $ChangedSettings++ + } + + if ($null -ne $($WAUPolicies.WAU_UseWhiteList) -and ($($WAUPolicies.WAU_UseWhiteList) -ne $($WAUConfig.WAU_UseWhiteList))) { + New-ItemProperty $regPath -Name WAU_UseWhiteList -Value $($WAUPolicies.WAU_UseWhiteList) -PropertyType DWord -Force | Out-Null + $ChangedSettings++ + } + elseif ($null -eq $($WAUPolicies.WAU_UseWhiteList) -and ($($WAUConfig.WAU_UseWhiteList) -or $($WAUConfig.WAU_UseWhiteList) -eq 0)) { + Remove-ItemProperty $regPath -Name WAU_UseWhiteList -Force -ErrorAction SilentlyContinue | Out-Null + $ChangedSettings++ + } + + if ($null -ne $($WAUPolicies.WAU_ListPath) -and ($($WAUPolicies.WAU_ListPath.TrimEnd(" ", "\", "/")) -ne $($WAUConfig.WAU_ListPath.TrimEnd(" ", "\", "/")))) { + New-ItemProperty $regPath -Name WAU_ListPath -Value $($WAUPolicies.WAU_ListPath.TrimEnd(" ", "\", "/")) -Force | Out-Null + $ChangedSettings++ + } + elseif ($null -eq $($WAUPolicies.WAU_ListPath) -and $($WAUConfig.WAU_ListPath)) { + Remove-ItemProperty $regPath -Name WAU_ListPath -Force -ErrorAction SilentlyContinue | Out-Null + $ChangedSettings++ + } + + if ($null -ne $($WAUPolicies.WAU_ModsPath) -and ($($WAUPolicies.WAU_ModsPath.TrimEnd(" ", "\", "/")) -ne $($WAUConfig.WAU_ModsPath.TrimEnd(" ", "\", "/")))) { + New-ItemProperty $regPath -Name WAU_ModsPath -Value $($WAUPolicies.WAU_ModsPath.TrimEnd(" ", "\", "/")) -Force | Out-Null + $ChangedSettings++ + } + elseif ($null -eq $($WAUPolicies.WAU_ModsPath) -and $($WAUConfig.WAU_ModsPath)) { + Remove-ItemProperty $regPath -Name WAU_ModsPath -Force -ErrorAction SilentlyContinue | Out-Null + $ChangedSettings++ + } + + if ($null -ne $($WAUPolicies.WAU_NotificationLevel) -and ($($WAUPolicies.WAU_NotificationLevel) -ne $($WAUConfig.WAU_NotificationLevel))) { + New-ItemProperty $regPath -Name WAU_NotificationLevel -Value $($WAUPolicies.WAU_NotificationLevel) -Force | Out-Null + $ChangedSettings++ + } + elseif ($null -eq $($WAUPolicies.WAU_NotificationLevel) -and $($WAUConfig.WAU_NotificationLevel) -ne "Full") { + New-ItemProperty $regPath -Name WAU_NotificationLevel -Value "Full" -Force | Out-Null + $ChangedSettings++ + } + + if ($null -ne $($WAUPolicies.WAU_UpdatesInterval) -and (($($WAUPolicies.WAU_UpdatesInterval) -ne $($WAUConfig.WAU_UpdatesInterval)))) { + New-ItemProperty $regPath -Name WAU_UpdatesInterval -Value $($WAUPolicies.WAU_UpdatesInterval) -Force | Out-Null + $service = New-Object -ComObject Schedule.Service + $service.Connect($env:COMPUTERNAME) + $folder = $service.GetFolder('\') + $task = $folder.GetTask("Winget-AutoUpdate") + $definition = $task.Definition + for($triggerId=1; $triggerId -le $definition.Triggers.Count; $triggerId++){ + if(($definition.Triggers.Item($triggerId).Type -eq "2") -or ($definition.Triggers.Item($triggerId).Type -eq "3")){ + $definition.Triggers.Remove($triggerId) + $triggerId-=1 + } + } + $folder.RegisterTaskDefinition($task.Name, $definition, 4, $null, $null, $null) | Out-Null + + if ($($WAUPolicies.WAU_UpdatesInterval) -ne "Never") { + #Count Triggers (correctly) + $service = New-Object -ComObject Schedule.Service + $service.Connect($env:COMPUTERNAME) + $folder = $service.GetFolder('\') + $task = $folder.GetTask("Winget-AutoUpdate") + $definition = $task.Definition + $definition.Triggers.Count | Out-Null + switch ($($WAUPolicies.WAU_UpdatesInterval)) { + "Daily" {$tasktrigger = New-ScheduledTaskTrigger -Daily -At 06am; break} + "BiDaily" {$tasktrigger = New-ScheduledTaskTrigger -Daily -At 06am -DaysInterval 2; break} + "Weekly" {$tasktrigger = New-ScheduledTaskTrigger -Weekly -At 06am -DaysOfWeek 2; break} + "BiWeekly" {$tasktrigger = New-ScheduledTaskTrigger -Weekly -At 06am -DaysOfWeek 2 -WeeksInterval 2; break} + "Monthly" {$tasktrigger = New-ScheduledTaskTrigger -Weekly -At 06am -DaysOfWeek 2 -WeeksInterval 4; break} + } + if ($definition.Triggers.Count -gt 0) { + $triggers = @() + $triggers += (Get-ScheduledTask "Winget-AutoUpdate").Triggers + $triggers += $tasktrigger + Set-ScheduledTask -TaskName "Winget-AutoUpdate" -Trigger $triggers + } + else { + Set-ScheduledTask -TaskName "Winget-AutoUpdate" -Trigger $tasktrigger + } + } + $ChangedSettings++ + } + elseif ($null -eq $($WAUPolicies.WAU_UpdatesInterval) -and $($WAUConfig.WAU_UpdatesInterval) -ne "Daily") { + New-ItemProperty $regPath -Name WAU_UpdatesInterval -Value "Daily" -Force | Out-Null + $service = New-Object -ComObject Schedule.Service + $service.Connect($env:COMPUTERNAME) + $folder = $service.GetFolder('\') + $task = $folder.GetTask("Winget-AutoUpdate") + $definition = $task.Definition + for($triggerId=1; $triggerId -le $definition.Triggers.Count; $triggerId++){ + if(($definition.Triggers.Item($triggerId).Type -eq "2") -or ($definition.Triggers.Item($triggerId).Type -eq "3")){ + $definition.Triggers.Remove($triggerId) + $triggerId-=1 + } + } + $folder.RegisterTaskDefinition($task.Name, $definition, 4, $null, $null, $null) | Out-Null + + $tasktrigger = New-ScheduledTaskTrigger -Daily -At 06am + + #Count Triggers (correctly) + $service = New-Object -ComObject Schedule.Service + $service.Connect($env:COMPUTERNAME) + $folder = $service.GetFolder('\') + $task = $folder.GetTask("Winget-AutoUpdate") + $definition = $task.Definition + $definition.Triggers.Count | Out-Null + if ($definition.Triggers.Count -gt 0) { + $triggers = @() + $triggers += (Get-ScheduledTask "Winget-AutoUpdate").Triggers + $triggers += $tasktrigger + Set-ScheduledTask -TaskName "Winget-AutoUpdate" -Trigger $triggers + } + else { + Set-ScheduledTask -TaskName "Winget-AutoUpdate" -Trigger $tasktrigger + } + $ChangedSettings++ + } + + if ($null -ne $($WAUPolicies.WAU_UpdatesAtLogon) -and ($($WAUPolicies.WAU_UpdatesAtLogon) -ne $($WAUConfig.WAU_UpdatesAtLogon))) { + if ($WAUPolicies.WAU_UpdatesAtLogon -eq 1) { + New-ItemProperty $regPath -Name WAU_UpdatesAtLogon -Value $($WAUPolicies.WAU_UpdatesAtLogon) -PropertyType DWord -Force | Out-Null + $triggers = @() + $triggers += (Get-ScheduledTask "Winget-AutoUpdate").Triggers + #Count Triggers (correctly) + $service = New-Object -ComObject Schedule.Service + $service.Connect($env:COMPUTERNAME) + $folder = $service.GetFolder('\') + $task = $folder.GetTask("Winget-AutoUpdate") + $definition = $task.Definition + $definition.Triggers.Count | Out-Null + if ($definition.Triggers.Count -gt 0) { + $triggers += New-ScheduledTaskTrigger -AtLogon + Set-ScheduledTask -TaskName "Winget-AutoUpdate" -Trigger $triggers + } + else { + $tasktrigger = New-ScheduledTaskTrigger -AtLogon + Set-ScheduledTask -TaskName "Winget-AutoUpdate" -Trigger $tasktrigger + } + } + else { + Remove-ItemProperty $regPath -Name WAU_UpdatesAtLogon -Force -ErrorAction SilentlyContinue | Out-Null + $service = New-Object -ComObject Schedule.Service + $service.Connect($env:COMPUTERNAME) + $folder = $service.GetFolder('\') + $task = $folder.GetTask("Winget-AutoUpdate") + $definition = $task.Definition + $definition.Triggers.Count | Out-Null + for($triggerId=1; $triggerId -le $definition.Triggers.Count; $triggerId++){ + if($definition.Triggers.Item($triggerId).Type -eq "9"){ + $definition.Triggers.Remove($triggerId) + $triggerId-=1 + } + } + $folder.RegisterTaskDefinition($task.Name, $definition, 4, $null, $null, $null) | Out-Null + } + $ChangedSettings++ + } + elseif ($null -eq $($WAUPolicies.WAU_UpdatesAtLogon) -and ($($WAUConfig.WAU_UpdatesAtLogon) -or $($WAUConfig.WAU_UpdatesAtLogon) -eq 0)) { + Remove-ItemProperty $regPath -Name WAU_UpdatesAtLogon -Force -ErrorAction SilentlyContinue | Out-Null + $service = New-Object -ComObject Schedule.Service + $service.Connect($env:COMPUTERNAME) + $folder = $service.GetFolder('\') + $task = $folder.GetTask("Winget-AutoUpdate") + $definition = $task.Definition + for($triggerId=1; $triggerId -le $definition.Triggers.Count; $triggerId++){ + if($definition.Triggers.Item($triggerId).Type -eq "9"){ + $definition.Triggers.Remove($triggerId) + $triggerId-=1 + } + } + $folder.RegisterTaskDefinition($task.Name, $definition, 4, $null, $null, $null) | Out-Null + $ChangedSettings++ + } + + if ($ChangedSettings -gt 0) { + Write-Log "Changed settings: $ChangedSettings" "Yellow" + } + #Get WAU Configurations after Policies change + $Script:WAUConfig = Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate" + } + } + + Return +} From a6b92b47c965a599da203e4d85a347a79461840f Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Fri, 30 Dec 2022 11:46:10 +0100 Subject: [PATCH 19/86] WAU_UpdatesAtTime now read and saved --- Winget-AutoUpdate/functions/Get-Policies.ps1 | 24 +++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/Winget-AutoUpdate/functions/Get-Policies.ps1 b/Winget-AutoUpdate/functions/Get-Policies.ps1 index 71ef80db..f896560e 100644 --- a/Winget-AutoUpdate/functions/Get-Policies.ps1 +++ b/Winget-AutoUpdate/functions/Get-Policies.ps1 @@ -89,12 +89,18 @@ Function Get-Policies { $definition = $task.Definition for($triggerId=1; $triggerId -le $definition.Triggers.Count; $triggerId++){ if(($definition.Triggers.Item($triggerId).Type -eq "2") -or ($definition.Triggers.Item($triggerId).Type -eq "3")){ + $UpdatesAtTime = ($definition.Triggers.Item($triggerId).StartBoundary).Substring(11,8) $definition.Triggers.Remove($triggerId) $triggerId-=1 } } $folder.RegisterTaskDefinition($task.Name, $definition, 4, $null, $null, $null) | Out-Null + if (!$($WAUConfig.WAU_UpdatesAtTime)) { + New-ItemProperty $regPath -Name WAU_UpdatesAtTime -Value $UpdatesAtTime -Force | Out-Null + $Script:WAUConfig = Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate" + } + if ($($WAUPolicies.WAU_UpdatesInterval) -ne "Never") { #Count Triggers (correctly) $service = New-Object -ComObject Schedule.Service @@ -104,11 +110,11 @@ Function Get-Policies { $definition = $task.Definition $definition.Triggers.Count | Out-Null switch ($($WAUPolicies.WAU_UpdatesInterval)) { - "Daily" {$tasktrigger = New-ScheduledTaskTrigger -Daily -At 06am; break} - "BiDaily" {$tasktrigger = New-ScheduledTaskTrigger -Daily -At 06am -DaysInterval 2; break} - "Weekly" {$tasktrigger = New-ScheduledTaskTrigger -Weekly -At 06am -DaysOfWeek 2; break} - "BiWeekly" {$tasktrigger = New-ScheduledTaskTrigger -Weekly -At 06am -DaysOfWeek 2 -WeeksInterval 2; break} - "Monthly" {$tasktrigger = New-ScheduledTaskTrigger -Weekly -At 06am -DaysOfWeek 2 -WeeksInterval 4; break} + "Daily" {$tasktrigger = New-ScheduledTaskTrigger -Daily -At $($WAUConfig.WAU_UpdatesAtTime); break} + "BiDaily" {$tasktrigger = New-ScheduledTaskTrigger -Daily -At $($WAUConfig.WAU_UpdatesAtTime) -DaysInterval 2; break} + "Weekly" {$tasktrigger = New-ScheduledTaskTrigger -Weekly -At $($WAUConfig.WAU_UpdatesAtTime) -DaysOfWeek 2; break} + "BiWeekly" {$tasktrigger = New-ScheduledTaskTrigger -Weekly -At $($WAUConfig.WAU_UpdatesAtTime) -DaysOfWeek 2 -WeeksInterval 2; break} + "Monthly" {$tasktrigger = New-ScheduledTaskTrigger -Weekly -At $($WAUConfig.WAU_UpdatesAtTime) -DaysOfWeek 2 -WeeksInterval 4; break} } if ($definition.Triggers.Count -gt 0) { $triggers = @() @@ -131,13 +137,19 @@ Function Get-Policies { $definition = $task.Definition for($triggerId=1; $triggerId -le $definition.Triggers.Count; $triggerId++){ if(($definition.Triggers.Item($triggerId).Type -eq "2") -or ($definition.Triggers.Item($triggerId).Type -eq "3")){ + $UpdatesAtTime = ($definition.Triggers.Item($triggerId).StartBoundary).Substring(11,8) $definition.Triggers.Remove($triggerId) $triggerId-=1 } } $folder.RegisterTaskDefinition($task.Name, $definition, 4, $null, $null, $null) | Out-Null - $tasktrigger = New-ScheduledTaskTrigger -Daily -At 06am + if (!$($WAUConfig.WAU_UpdatesAtTime)) { + New-ItemProperty $regPath -Name WAU_UpdatesAtTime -Value $UpdatesAtTime -Force | Out-Null + $Script:WAUConfig = Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate" + } + + $tasktrigger = New-ScheduledTaskTrigger -Daily -At $($WAUConfig.WAU_UpdatesAtTime) #Count Triggers (correctly) $service = New-Object -ComObject Schedule.Service From c712872826ba04031f6dc80202a5cc9634944b21 Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Fri, 30 Dec 2022 19:56:06 +0100 Subject: [PATCH 20/86] $UpdatesAtTime now managed in Policies too --- Policies/WAU.admx | 132 ++++++++++++++++++- Policies/en-US/WAU.adml | 34 +++++ Winget-AutoUpdate/functions/Get-Policies.ps1 | 11 ++ 3 files changed, 175 insertions(+), 2 deletions(-) diff --git a/Policies/WAU.admx b/Policies/WAU.admx index e58a8433..e155d37e 100644 --- a/Policies/WAU.admx +++ b/Policies/WAU.admx @@ -80,14 +80,14 @@ - + - + @@ -161,5 +161,133 @@ + + + + + + + + 01:00:00 + + + + + 02:00:00 + + + + + 03:00:00 + + + + + 04:00:00 + + + + + 05:00:00 + + + + + 06:00:00 + + + + + 07:00:00 + + + + + 08:00:00 + + + + + 09:00:00 + + + + + 10:00:00 + + + + + 11:00:00 + + + + + 12:00:00 + + + + + 13:00:00 + + + + + 14:00:00 + + + + + 15:00:00 + + + + + 16:00:00 + + + + + 17:00:00 + + + + + 18:00:00 + + + + + 19:00:00 + + + + + 20:00:00 + + + + + 21:00:00 + + + + + 22:00:00 + + + + + 23:00:00 + + + + + 24:00:00 + + + + + diff --git a/Policies/en-US/WAU.adml b/Policies/en-US/WAU.adml index dc50669e..3a1e1899 100644 --- a/Policies/en-US/WAU.adml +++ b/Policies/en-US/WAU.adml @@ -50,6 +50,37 @@ If this policy is not configured or disabled, Updates Interval: (1. Daily).6. Never (in combination with '-UpdatesAtLogon' for instance) Updates at Logon This policy setting specifies whether to set WAU to run at user logon or not. By default, No. + Updates at Time + If this policy is enabled, you can configure the Sheduled Task Update time: +From 01:00 to 24:00 (Military Time/24 Hour Time) + +If set, it will not take effect until the setting "Updates Interval" also been changed! + +If this policy is not configured or disabled, Sheduled Task Update time: 06:00. + 01:00 + 02:00 + 03:00 + 04:00 + 05:00 + 06:00 + 07:00 + 08:00 + 09:00 + 10:00 + 11:00 + 12:00 + 13:00 + 14:00 + 15:00 + 16:00 + 17:00 + 18:00 + 19:00 + 20:00 + 21:00 + 22:00 + 23:00 + 24:00 @@ -68,6 +99,9 @@ If this policy is not configured or disabled, Updates Interval: (1. Daily). + + + diff --git a/Winget-AutoUpdate/functions/Get-Policies.ps1 b/Winget-AutoUpdate/functions/Get-Policies.ps1 index f896560e..0761cb34 100644 --- a/Winget-AutoUpdate/functions/Get-Policies.ps1 +++ b/Winget-AutoUpdate/functions/Get-Policies.ps1 @@ -80,6 +80,17 @@ Function Get-Policies { $ChangedSettings++ } + if ($null -ne $($WAUPolicies.WAU_UpdatesAtTime) -and ($($WAUPolicies.WAU_UpdatesAtTime) -ne $($WAUConfig.WAU_UpdatesAtTime))) { + New-ItemProperty $regPath -Name WAU_UpdatesAtTime -Value $($WAUPolicies.WAU_UpdatesAtTime) -Force | Out-Null + $Script:WAUConfig = Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate" + $ChangedSettings++ + } + elseif ($null -eq $($WAUPolicies.WAU_UpdatesAtTime) -and $($WAUConfig.WAU_UpdatesAtTime) -ne "06:00:00") { + New-ItemProperty $regPath -Name WAU_UpdatesAtTime -Value "06:00:00" -Force | Out-Null + $Script:WAUConfig = Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate" + $ChangedSettings++ + } + if ($null -ne $($WAUPolicies.WAU_UpdatesInterval) -and (($($WAUPolicies.WAU_UpdatesInterval) -ne $($WAUConfig.WAU_UpdatesInterval)))) { New-ItemProperty $regPath -Name WAU_UpdatesInterval -Value $($WAUPolicies.WAU_UpdatesInterval) -Force | Out-Null $service = New-Object -ComObject Schedule.Service From 32c92e6b1dd2963320e2c2b17e4d43e631efc6ce Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Fri, 30 Dec 2022 20:41:39 +0100 Subject: [PATCH 21/86] Text changes/improvements in ADMX/ADML begins... --- Policies/en-US/WAU.adml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Policies/en-US/WAU.adml b/Policies/en-US/WAU.adml index 3a1e1899..4b7bad8d 100644 --- a/Policies/en-US/WAU.adml +++ b/Policies/en-US/WAU.adml @@ -52,24 +52,24 @@ If this policy is not configured or disabled, Updates Interval: (1. Daily).This policy setting specifies whether to set WAU to run at user logon or not. By default, No. Updates at Time If this policy is enabled, you can configure the Sheduled Task Update time: -From 01:00 to 24:00 (Military Time/24 Hour Time) +From 01:00 to 24:00 (Military/24 Hour Time) If set, it will not take effect until the setting "Updates Interval" also been changed! -If this policy is not configured or disabled, Sheduled Task Update time: 06:00. - 01:00 +If this policy is not configured or disabled, Sheduled Task Update time: 06:00 AM. + 01:00 AM 02:00 03:00 04:00 05:00 - 06:00 + 06:00 (Default) 07:00 08:00 09:00 10:00 11:00 12:00 - 13:00 + 13:00 PM 14:00 15:00 16:00 From 06ef630fff43cbd533f46810a3974dda4423bb2f Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Fri, 30 Dec 2022 21:02:41 +0100 Subject: [PATCH 22/86] Ongoing... --- Policies/en-US/WAU.adml | 50 ++++++++++++++++++++++++++--------------- 1 file changed, 32 insertions(+), 18 deletions(-) diff --git a/Policies/en-US/WAU.adml b/Policies/en-US/WAU.adml index 4b7bad8d..51403f97 100644 --- a/Policies/en-US/WAU.adml +++ b/Policies/en-US/WAU.adml @@ -11,27 +11,39 @@ Bypass Black/White list for User This policy setting specifies whether to Bypass Black/White list when run in user context or not. Disable Winget-AutoUpdate update checking - This policy setting specifies whether to Disable Winget-AutoUpdate update checking or not. By default, WAU auto updates if new version is available on Github. + This policy setting specifies whether to Disable Winget-AutoUpdate update checking or not. + +If this policy is disabled or not configured, the default is No. Do not run WAU on metered connection - This policy setting specifies whether to Run WAU on metered connection or not. Default No. + This policy setting specifies whether to Run WAU on metered connection or not. + +If this policy is disabled or not configured, the default is No. Update WAU to PreRelease versions - This policy setting specifies whether to update WAU (if enabled) to PreRelease versions or not. Default No. + This policy setting specifies whether to update WAU to PreRelease versions or not. + +If this policy is disabled or not configured, the default is No. Use WhiteList instead of BlackList - This policy setting specifies whether to use a WhiteList or not. Default Blacklist. + This policy setting specifies whether to use a WhiteList or not. + +If this policy is disabled or not configured, the default is Blacklist. Get Black/White List from external Path (URL/UNC/Local) - If this policy is enabled, you can set a (URL/UNC/Local) Path to external lists other than the default. If this policy is disabled or not configured, the default ListPath is used. + If this policy is enabled, you can set a (URL/UNC/Local) Path to external lists other than the default. + +If this policy is disabled or not configured, the default ListPath is used (WAU InstallLocation). Get Mods from external Path (URL/UNC/Local) - If this policy is enabled, you can set a (URL/UNC/Local) Path to external mods other than the default. If this policy is disabled or not configured, the default ModsPath is used. + If this policy is enabled, you can set a (URL/UNC/Local) Path to external mods other than the default. + +If this policy is disabled or not configured, the default ModsPath is used (WAU InstallLocation). Notification Level If this policy is enabled, you can configure the Notification Level: -1. Full (Default, displays all notifications) -2. SuccessOnly (Only displays notifications for success) -3. None (Does not display any notification) +1. Full (Default) +2. SuccessOnly +3. None -If this policy is not configured or disabled, the Default displays all notifications (1. Full). - 1. Full (Default, displays all notifications) - 2. SuccessOnly (Only displays notifications for success) - 3. None (Does not display any notification) +If this policy is not configured or disabled, Notification Level: (1. Full). + 1. Full (Default) + 2. SuccessOnly + 3. None Updates Interval If this policy is enabled, you can configure the Updates Interval: 1. Daily (Default) @@ -39,7 +51,7 @@ If this policy is not configured or disabled, the Default displays all notificat 3. Weekly 4. BiWeekly 5. Monthly -6. Never (in combination with '-UpdatesAtLogon' for instance) +6. Never (e.g. in combination with '-Updates at Logon') If this policy is not configured or disabled, Updates Interval: (1. Daily). 1. Daily (Default) @@ -47,16 +59,18 @@ If this policy is not configured or disabled, Updates Interval: (1. Daily).3. Weekly 4. BiWeekly 5. Monthly - 6. Never (in combination with '-UpdatesAtLogon' for instance) + 6. Never (e.g. in combination with 'Updates Interval') Updates at Logon - This policy setting specifies whether to set WAU to run at user logon or not. By default, No. + This policy setting specifies whether to set WAU to run at user logon or not. + +If this policy is disabled or not configured, the default is No. Updates at Time If this policy is enabled, you can configure the Sheduled Task Update time: From 01:00 to 24:00 (Military/24 Hour Time) -If set, it will not take effect until the setting "Updates Interval" also been changed! +If set, it will not take effect until 'Updates Interval' also has been changed! -If this policy is not configured or disabled, Sheduled Task Update time: 06:00 AM. +If this policy is not configured or disabled, Sheduled Task Update time: (06:00 AM). 01:00 AM 02:00 03:00 From 071b6b15a967864a6af68f40b38ea6e2c1ff2e45 Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Fri, 30 Dec 2022 21:20:42 +0100 Subject: [PATCH 23/86] ADMX/ADML done! --- Policies/en-US/WAU.adml | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Policies/en-US/WAU.adml b/Policies/en-US/WAU.adml index 51403f97..566b6701 100644 --- a/Policies/en-US/WAU.adml +++ b/Policies/en-US/WAU.adml @@ -9,7 +9,9 @@ Activate WAU GPO Management This policy setting is an overriding toggle for GPO Management of Winget-AutoUpdate. Bypass Black/White list for User - This policy setting specifies whether to Bypass Black/White list when run in user context or not. + This policy setting specifies whether to Bypass Black/White list when run in user context or not. + +If this policy is disabled or not configured, the default is No. Disable Winget-AutoUpdate update checking This policy setting specifies whether to Disable Winget-AutoUpdate update checking or not. @@ -17,7 +19,7 @@ If this policy is disabled or not configured, the default is No. Do not run WAU on metered connection This policy setting specifies whether to Run WAU on metered connection or not. -If this policy is disabled or not configured, the default is No. +If this policy is disabled or not configured, the default is Yes. Update WAU to PreRelease versions This policy setting specifies whether to update WAU to PreRelease versions or not. @@ -25,7 +27,7 @@ If this policy is disabled or not configured, the default is No. Use WhiteList instead of BlackList This policy setting specifies whether to use a WhiteList or not. -If this policy is disabled or not configured, the default is Blacklist. +If this policy is disabled or not configured, the default is No. Get Black/White List from external Path (URL/UNC/Local) If this policy is enabled, you can set a (URL/UNC/Local) Path to external lists other than the default. @@ -51,7 +53,7 @@ If this policy is not configured or disabled, Notification Level: (1. Full). 1. Daily (Default) @@ -70,7 +72,7 @@ From 01:00 to 24:00 (Military/24 Hour Time) If set, it will not take effect until 'Updates Interval' also has been changed! -If this policy is not configured or disabled, Sheduled Task Update time: (06:00 AM). +If this policy is not configured or disabled, Updates at Time: (06:00 AM). 01:00 AM 02:00 03:00 From 94f26b25c962f3a8d783a58f4e98188cf7b5b858 Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Fri, 30 Dec 2022 21:44:41 +0100 Subject: [PATCH 24/86] Documented --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8ce79a48..00dd6a01 100644 --- a/README.md +++ b/README.md @@ -157,7 +157,11 @@ Another finess is the **AppID** followed by the `-override` suffix as a **text f > Example: > **Canneverbe.CDBurnerXP-override.txt** with the content `ADDLOCAL=All REMOVE=Desktop_Shortcut /qn` -This will use the content from the text file as a native **winget --override** parameter when upgrading (as proposed by [Nesovj](https://github.com/Nesovj) in [Mod for --override argument #244](https://github.com/Romanitho/Winget-AutoUpdate/discussions/244#discussion-4637666)). +## GPO Management +In an enterprise environment it's crucial that different groups can have different settings in an application etc. or to implement other mandatory settings. +**WAU** doesn't have any setting that can be changed except for when installing (or editing the registry as **Admin** for a few settings). +Now it's possible to manage every setting with **GPO**. +Read more in the `README.md` under the directory **Policies** ## Help In some cases, you need to "unblock" the `install.bat` file (Windows Defender SmartScreen). Right click, properties and unblock. Then, you'll be able to run it. From 55fb2870f9ac89bcad71fd88c5e9abbfa12d96ab Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Fri, 30 Dec 2022 21:56:04 +0100 Subject: [PATCH 25/86] Image --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 00dd6a01..9ac447b1 100644 --- a/README.md +++ b/README.md @@ -163,6 +163,8 @@ In an enterprise environment it's crucial that different groups can have differe Now it's possible to manage every setting with **GPO**. Read more in the `README.md` under the directory **Policies** +![image](https://user-images.githubusercontent.com/102996177/210110986-b19dca08-f653-498b-958e-66e8553c33ab.png) + ## Help In some cases, you need to "unblock" the `install.bat` file (Windows Defender SmartScreen). Right click, properties and unblock. Then, you'll be able to run it. From 57733fbcf63a06121e193932dfa3191e553dcf86 Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Fri, 30 Dec 2022 22:21:50 +0100 Subject: [PATCH 26/86] Text --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9ac447b1..610025e6 100644 --- a/README.md +++ b/README.md @@ -159,8 +159,8 @@ Another finess is the **AppID** followed by the `-override` suffix as a **text f ## GPO Management In an enterprise environment it's crucial that different groups can have different settings in an application etc. or to implement other mandatory settings. -**WAU** doesn't have any setting that can be changed except for when installing (or editing the registry as **Admin** for a few settings). -Now it's possible to manage every setting with **GPO**. +**WAU** doesn't have any setting that can be changed except for when installing (or editing the registry/the task `Winget-AutoUpdate` as **Admin** for a few settings). +Now it's possible to manage nearly every setting with **GPO**. Read more in the `README.md` under the directory **Policies** ![image](https://user-images.githubusercontent.com/102996177/210110986-b19dca08-f653-498b-958e-66e8553c33ab.png) From ab215d86157e8433a2d13069045e6f7a36cb41fa Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Sat, 31 Dec 2022 00:59:46 +0100 Subject: [PATCH 27/86] UserContext and fixes to settings --- Policies/WAU.admx | 10 ++++++++++ Policies/en-US/WAU.adml | 4 ++++ Winget-AutoUpdate/functions/Get-Policies.ps1 | 19 +++++++++++++++++++ 3 files changed, 33 insertions(+) diff --git a/Policies/WAU.admx b/Policies/WAU.admx index e155d37e..c40bf32f 100644 --- a/Policies/WAU.admx +++ b/Policies/WAU.admx @@ -288,6 +288,16 @@ + + + + + + + + + + diff --git a/Policies/en-US/WAU.adml b/Policies/en-US/WAU.adml index 566b6701..558a1c92 100644 --- a/Policies/en-US/WAU.adml +++ b/Policies/en-US/WAU.adml @@ -97,6 +97,10 @@ If this policy is not configured or disabled, Updates at Time: (06:00 AM).22:00 23:00 24:00 + User context execution + This policy setting specifies whether to enable User context execution or not . + +If this policy is disabled or not configured, the default is No. diff --git a/Winget-AutoUpdate/functions/Get-Policies.ps1 b/Winget-AutoUpdate/functions/Get-Policies.ps1 index 0761cb34..0096eac1 100644 --- a/Winget-AutoUpdate/functions/Get-Policies.ps1 +++ b/Winget-AutoUpdate/functions/Get-Policies.ps1 @@ -237,6 +237,25 @@ Function Get-Policies { $ChangedSettings++ } + if ($null -ne $($WAUPolicies.WAU_UserContext) -and ($($WAUPolicies.WAU_UserContext) -ne $($WAUConfig.WAU_UserContext))) { + #Get-ScheduledTask -TaskName "Winget-AutoUpdate-UserContext" -ErrorAction SilentlyContinue | Unregister-ScheduledTask -Confirm:$False + New-ItemProperty $regPath -Name WAU_UserContext -Value $($WAUPolicies.WAU_UserContext) -PropertyType DWord -Force | Out-Null + # Settings for the scheduled task in User context + $taskAction = New-ScheduledTaskAction -Execute "wscript.exe" -Argument "`"$($WingetUpdatePath)\Invisible.vbs`" `"powershell.exe -NoProfile -ExecutionPolicy Bypass -File `"`"`"$($WingetUpdatePath)\winget-upgrade.ps1`"`"" + $taskUserPrincipal = New-ScheduledTaskPrincipal -GroupId S-1-5-11 + $taskSettings = New-ScheduledTaskSettingsSet -Compatibility Win8 -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -ExecutionTimeLimit 03:00:00 + + # Set up the task for user apps + $task = New-ScheduledTask -Action $taskAction -Principal $taskUserPrincipal -Settings $taskSettings + Register-ScheduledTask -TaskName 'Winget-AutoUpdate-UserContext' -InputObject $task -Force | Out-Null + $ChangedSettings++ + } + elseif ($null -eq $($WAUPolicies.WAU_UserContext) -and ($($WAUConfig.WAU_UserContext) -or $($WAUConfig.WAU_UserContext) -eq 0)) { + Remove-ItemProperty $regPath -Name WAU_UserContext -Force -ErrorAction SilentlyContinue | Out-Null + Get-ScheduledTask -TaskName "Winget-AutoUpdate-UserContext" -ErrorAction SilentlyContinue | Unregister-ScheduledTask -Confirm:$False + $ChangedSettings++ + } + if ($ChangedSettings -gt 0) { Write-Log "Changed settings: $ChangedSettings" "Yellow" } From 17e95793e9b9c813964f50c02da87c89fedd56ee Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Sat, 31 Dec 2022 01:23:23 +0100 Subject: [PATCH 28/86] Forgot to include changes... --- Winget-AutoUpdate/functions/Get-Policies.ps1 | 28 +++++++++++--------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/Winget-AutoUpdate/functions/Get-Policies.ps1 b/Winget-AutoUpdate/functions/Get-Policies.ps1 index 0096eac1..4c700e2d 100644 --- a/Winget-AutoUpdate/functions/Get-Policies.ps1 +++ b/Winget-AutoUpdate/functions/Get-Policies.ps1 @@ -21,7 +21,7 @@ Function Get-Policies { New-ItemProperty $regPath -Name WAU_DisableAutoUpdate -Value $($WAUPolicies.WAU_DisableAutoUpdate) -PropertyType DWord -Force | Out-Null $ChangedSettings++ } - elseif ($null -eq $($WAUPolicies.WAU_DisableAutoUpdate) -and ($($WAUConfig.WAU_DisableAutoUpdate) -or $($WAUConfig.WAU_DisableAutoUpdate) -eq 0)) { + elseif ($null -eq $($WAUPolicies.WAU_DisableAutoUpdate) -and (($($WAUConfig.WAU_DisableAutoUpdate) -or $($WAUConfig.WAU_DisableAutoUpdate) -eq 0))) { Remove-ItemProperty $regPath -Name WAU_DisableAutoUpdate -Force -ErrorAction SilentlyContinue | Out-Null $ChangedSettings++ } @@ -53,7 +53,7 @@ Function Get-Policies { $ChangedSettings++ } - if ($null -ne $($WAUPolicies.WAU_ListPath) -and ($($WAUPolicies.WAU_ListPath.TrimEnd(" ", "\", "/")) -ne $($WAUConfig.WAU_ListPath.TrimEnd(" ", "\", "/")))) { + if ($null -ne $($WAUPolicies.WAU_ListPath) -and ($($WAUPolicies.WAU_ListPath) -ne $($WAUConfig.WAU_ListPath))) { New-ItemProperty $regPath -Name WAU_ListPath -Value $($WAUPolicies.WAU_ListPath.TrimEnd(" ", "\", "/")) -Force | Out-Null $ChangedSettings++ } @@ -62,7 +62,7 @@ Function Get-Policies { $ChangedSettings++ } - if ($null -ne $($WAUPolicies.WAU_ModsPath) -and ($($WAUPolicies.WAU_ModsPath.TrimEnd(" ", "\", "/")) -ne $($WAUConfig.WAU_ModsPath.TrimEnd(" ", "\", "/")))) { + if ($null -ne $($WAUPolicies.WAU_ModsPath) -and ($($WAUPolicies.WAU_ModsPath) -ne $($WAUConfig.WAU_ModsPath))) { New-ItemProperty $regPath -Name WAU_ModsPath -Value $($WAUPolicies.WAU_ModsPath.TrimEnd(" ", "\", "/")) -Force | Out-Null $ChangedSettings++ } @@ -91,7 +91,7 @@ Function Get-Policies { $ChangedSettings++ } - if ($null -ne $($WAUPolicies.WAU_UpdatesInterval) -and (($($WAUPolicies.WAU_UpdatesInterval) -ne $($WAUConfig.WAU_UpdatesInterval)))) { + if ($null -ne $($WAUPolicies.WAU_UpdatesInterval) -and ($($WAUPolicies.WAU_UpdatesInterval) -ne $($WAUConfig.WAU_UpdatesInterval))) { New-ItemProperty $regPath -Name WAU_UpdatesInterval -Value $($WAUPolicies.WAU_UpdatesInterval) -Force | Out-Null $service = New-Object -ComObject Schedule.Service $service.Connect($env:COMPUTERNAME) @@ -238,16 +238,20 @@ Function Get-Policies { } if ($null -ne $($WAUPolicies.WAU_UserContext) -and ($($WAUPolicies.WAU_UserContext) -ne $($WAUConfig.WAU_UserContext))) { - #Get-ScheduledTask -TaskName "Winget-AutoUpdate-UserContext" -ErrorAction SilentlyContinue | Unregister-ScheduledTask -Confirm:$False New-ItemProperty $regPath -Name WAU_UserContext -Value $($WAUPolicies.WAU_UserContext) -PropertyType DWord -Force | Out-Null - # Settings for the scheduled task in User context - $taskAction = New-ScheduledTaskAction -Execute "wscript.exe" -Argument "`"$($WingetUpdatePath)\Invisible.vbs`" `"powershell.exe -NoProfile -ExecutionPolicy Bypass -File `"`"`"$($WingetUpdatePath)\winget-upgrade.ps1`"`"" - $taskUserPrincipal = New-ScheduledTaskPrincipal -GroupId S-1-5-11 - $taskSettings = New-ScheduledTaskSettingsSet -Compatibility Win8 -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -ExecutionTimeLimit 03:00:00 + if ($WAUPolicies.WAU_UserContext -eq 1) { + # Settings for the scheduled task in User context + $taskAction = New-ScheduledTaskAction -Execute "wscript.exe" -Argument "`"$($WingetUpdatePath)\Invisible.vbs`" `"powershell.exe -NoProfile -ExecutionPolicy Bypass -File `"`"`"$($WingetUpdatePath)\winget-upgrade.ps1`"`"" + $taskUserPrincipal = New-ScheduledTaskPrincipal -GroupId S-1-5-11 + $taskSettings = New-ScheduledTaskSettingsSet -Compatibility Win8 -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -ExecutionTimeLimit 03:00:00 - # Set up the task for user apps - $task = New-ScheduledTask -Action $taskAction -Principal $taskUserPrincipal -Settings $taskSettings - Register-ScheduledTask -TaskName 'Winget-AutoUpdate-UserContext' -InputObject $task -Force | Out-Null + # Set up the task for user apps + $task = New-ScheduledTask -Action $taskAction -Principal $taskUserPrincipal -Settings $taskSettings + Register-ScheduledTask -TaskName 'Winget-AutoUpdate-UserContext' -InputObject $task -Force + } + else { + Get-ScheduledTask -TaskName "Winget-AutoUpdate-UserContext" -ErrorAction SilentlyContinue | Unregister-ScheduledTask -Confirm:$False + } $ChangedSettings++ } elseif ($null -eq $($WAUPolicies.WAU_UserContext) -and ($($WAUConfig.WAU_UserContext) -or $($WAUConfig.WAU_UserContext) -eq 0)) { From 0673be5b7074b6f05dbaff767471de77e4a1a884 Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Sat, 31 Dec 2022 11:15:10 +0100 Subject: [PATCH 29/86] Shortcuts Policies and som critical fixes --- Policies/WAU.admx | 20 ++++++++++ Policies/en-US/WAU.adml | 12 ++++++ README.md | 4 +- Winget-AutoUpdate/functions/Add-Shortcut.ps1 | 10 +++++ Winget-AutoUpdate/functions/Get-Policies.ps1 | 41 +++++++++++++++++++- 5 files changed, 83 insertions(+), 4 deletions(-) create mode 100644 Winget-AutoUpdate/functions/Add-Shortcut.ps1 diff --git a/Policies/WAU.admx b/Policies/WAU.admx index c40bf32f..4850e606 100644 --- a/Policies/WAU.admx +++ b/Policies/WAU.admx @@ -298,6 +298,26 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/Policies/en-US/WAU.adml b/Policies/en-US/WAU.adml index 558a1c92..44767709 100644 --- a/Policies/en-US/WAU.adml +++ b/Policies/en-US/WAU.adml @@ -100,6 +100,18 @@ If this policy is not configured or disabled, Updates at Time: (06:00 AM).User context execution This policy setting specifies whether to enable User context execution or not . +If this policy is disabled or not configured, the default is No. + Enable Deskop Shortcut + This policy setting specifies whether to enable a Desktop Shortcut or not: +WAU - Check for updated Apps + +If this policy is disabled or not configured, the default is No. + Enable Start Menu Shortcuts + This policy setting specifies whether to enable Start Menu Shortcuts or not: +WAU - Check for updated Apps +WAU - Open logs +WAU - Web Help + If this policy is disabled or not configured, the default is No. diff --git a/README.md b/README.md index 610025e6..c71c5405 100644 --- a/README.md +++ b/README.md @@ -160,10 +160,10 @@ Another finess is the **AppID** followed by the `-override` suffix as a **text f ## GPO Management In an enterprise environment it's crucial that different groups can have different settings in an application etc. or to implement other mandatory settings. **WAU** doesn't have any setting that can be changed except for when installing (or editing the registry/the task `Winget-AutoUpdate` as **Admin** for a few settings). -Now it's possible to manage nearly every setting with **GPO**. +It's now possible to manage every setting with **GPO**. Read more in the `README.md` under the directory **Policies** -![image](https://user-images.githubusercontent.com/102996177/210110986-b19dca08-f653-498b-958e-66e8553c33ab.png) +![image](https://user-images.githubusercontent.com/102996177/210131296-0e0286e1-bf8e-4f94-81bd-76559ae49b7a.png) ## Help In some cases, you need to "unblock" the `install.bat` file (Windows Defender SmartScreen). Right click, properties and unblock. Then, you'll be able to run it. diff --git a/Winget-AutoUpdate/functions/Add-Shortcut.ps1 b/Winget-AutoUpdate/functions/Add-Shortcut.ps1 new file mode 100644 index 00000000..3feb3962 --- /dev/null +++ b/Winget-AutoUpdate/functions/Add-Shortcut.ps1 @@ -0,0 +1,10 @@ +#Function for creating shortcuts +function Add-Shortcut ($Target, $Shortcut, $Arguments, $Icon, $Description) { + $WScriptShell = New-Object -ComObject WScript.Shell + $Shortcut = $WScriptShell.CreateShortcut($Shortcut) + $Shortcut.TargetPath = $Target + $Shortcut.Arguments = $Arguments + $Shortcut.IconLocation = $Icon + $Shortcut.Description = $Description + $Shortcut.Save() +} diff --git a/Winget-AutoUpdate/functions/Get-Policies.ps1 b/Winget-AutoUpdate/functions/Get-Policies.ps1 index 4c700e2d..72289e23 100644 --- a/Winget-AutoUpdate/functions/Get-Policies.ps1 +++ b/Winget-AutoUpdate/functions/Get-Policies.ps1 @@ -21,7 +21,7 @@ Function Get-Policies { New-ItemProperty $regPath -Name WAU_DisableAutoUpdate -Value $($WAUPolicies.WAU_DisableAutoUpdate) -PropertyType DWord -Force | Out-Null $ChangedSettings++ } - elseif ($null -eq $($WAUPolicies.WAU_DisableAutoUpdate) -and (($($WAUConfig.WAU_DisableAutoUpdate) -or $($WAUConfig.WAU_DisableAutoUpdate) -eq 0))) { + elseif ($null -eq $($WAUPolicies.WAU_DisableAutoUpdate) -and ($($WAUConfig.WAU_DisableAutoUpdate) -or $($WAUConfig.WAU_DisableAutoUpdate) -eq 0)) { Remove-ItemProperty $regPath -Name WAU_DisableAutoUpdate -Force -ErrorAction SilentlyContinue | Out-Null $ChangedSettings++ } @@ -241,7 +241,7 @@ Function Get-Policies { New-ItemProperty $regPath -Name WAU_UserContext -Value $($WAUPolicies.WAU_UserContext) -PropertyType DWord -Force | Out-Null if ($WAUPolicies.WAU_UserContext -eq 1) { # Settings for the scheduled task in User context - $taskAction = New-ScheduledTaskAction -Execute "wscript.exe" -Argument "`"$($WingetUpdatePath)\Invisible.vbs`" `"powershell.exe -NoProfile -ExecutionPolicy Bypass -File `"`"`"$($WingetUpdatePath)\winget-upgrade.ps1`"`"" + $taskAction = New-ScheduledTaskAction -Execute "wscript.exe" -Argument "`"$($WAUConfig.InstallLocation)\Invisible.vbs`" `"powershell.exe -NoProfile -ExecutionPolicy Bypass -File `"`"`"$($WAUConfig.InstallLocation)\winget-upgrade.ps1`"`"" $taskUserPrincipal = New-ScheduledTaskPrincipal -GroupId S-1-5-11 $taskSettings = New-ScheduledTaskSettingsSet -Compatibility Win8 -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -ExecutionTimeLimit 03:00:00 @@ -260,6 +260,43 @@ Function Get-Policies { $ChangedSettings++ } + if ($null -ne $($WAUPolicies.WAU_DesktopShortcut) -and ($($WAUPolicies.WAU_DesktopShortcut) -ne $($WAUConfig.WAU_DesktopShortcut))) { + New-ItemProperty $regPath -Name WAU_DesktopShortcut -Value $($WAUPolicies.WAU_DesktopShortcut) -PropertyType DWord -Force | Out-Null + if ($WAUPolicies.WAU_DesktopShortcut -eq 1) { + Add-Shortcut "wscript.exe" "${env:Public}\Desktop\WAU - Check for updated Apps.lnk" "`"$($WAUConfig.InstallLocation)\Invisible.vbs`" `"powershell.exe -NoProfile -ExecutionPolicy Bypass -File `"`"`"$($WAUConfig.InstallLocation)\user-run.ps1`"`"" "${env:SystemRoot}\System32\shell32.dll,-16739" "Manual start of Winget-AutoUpdate (WAU)..." + } + else { + Remove-Item -Path "${env:Public}\Desktop\WAU - Check for updated Apps.lnk" -Force | Out-Null + } + $ChangedSettings++ + } + elseif ($null -eq $($WAUPolicies.WAU_DesktopShortcut) -and ($($WAUConfig.WAU_DesktopShortcut) -or $($WAUConfig.WAU_DesktopShortcut) -eq 0)) { + Remove-ItemProperty $regPath -Name WAU_DesktopShortcut -Force -ErrorAction SilentlyContinue | Out-Null + Remove-Item -Path "${env:Public}\Desktop\WAU - Check for updated Apps.lnk" -Force | Out-Null + $ChangedSettings++ + } + + if ($null -ne $($WAUPolicies.WAU_StartMenuShortcut) -and ($($WAUPolicies.WAU_StartMenuShortcut) -ne $($WAUConfig.WAU_StartMenuShortcut))) { + New-ItemProperty $regPath -Name WAU_StartMenuShortcut -Value $($WAUPolicies.WAU_StartMenuShortcut) -PropertyType DWord -Force | Out-Null + if ($WAUPolicies.WAU_StartMenuShortcut -eq 1) { + if (!(Test-Path "${env:ProgramData}\Microsoft\Windows\Start Menu\Programs\Winget-AutoUpdate (WAU)")) { + New-Item -ItemType Directory -Force -Path "${env:ProgramData}\Microsoft\Windows\Start Menu\Programs\Winget-AutoUpdate (WAU)" | Out-Null + } + Add-Shortcut "wscript.exe" "${env:ProgramData}\Microsoft\Windows\Start Menu\Programs\Winget-AutoUpdate (WAU)\WAU - Check for updated Apps.lnk" "`"$($WAUConfig.InstallLocation)\Invisible.vbs`" `"powershell.exe -NoProfile -ExecutionPolicy Bypass -File `"`"`"$($WAUConfig.InstallLocation)\user-run.ps1`"`"" "${env:SystemRoot}\System32\shell32.dll,-16739" "Manual start of Winget-AutoUpdate (WAU)..." + Add-Shortcut "wscript.exe" "${env:ProgramData}\Microsoft\Windows\Start Menu\Programs\Winget-AutoUpdate (WAU)\WAU - Open logs.lnk" "`"$($WAUConfig.InstallLocation)\Invisible.vbs`" `"powershell.exe -NoProfile -ExecutionPolicy Bypass -File `"`"`"$($WAUConfig.InstallLocation)\user-run.ps1`" -Logs`"" "${env:SystemRoot}\System32\shell32.dll,-16763" "Open existing WAU logs..." + Add-Shortcut "wscript.exe" "${env:ProgramData}\Microsoft\Windows\Start Menu\Programs\Winget-AutoUpdate (WAU)\WAU - Web Help.lnk" "`"$($WAUConfig.InstallLocation)\Invisible.vbs`" `"powershell.exe -NoProfile -ExecutionPolicy Bypass -File `"`"`"$($WAUConfig.InstallLocation)\user-run.ps1`" -Help`"" "${env:SystemRoot}\System32\shell32.dll,-24" "Help for WAU..." + } + else { + Remove-Item -Path "${env:ProgramData}\Microsoft\Windows\Start Menu\Programs\Winget-AutoUpdate (WAU)" -Recurse -Force | Out-Null + } + $ChangedSettings++ + } + elseif ($null -eq $($WAUPolicies.WAU_StartMenuShortcut) -and ($($WAUConfig.WAU_StartMenuShortcut) -or $($WAUConfig.WAU_StartMenuShortcut) -eq 0)) { + Remove-ItemProperty $regPath -Name WAU_StartMenuShortcut -Force -ErrorAction SilentlyContinue | Out-Null + Remove-Item -Path "${env:ProgramData}\Microsoft\Windows\Start Menu\Programs\Winget-AutoUpdate (WAU)" -Recurse -Force | Out-Null + $ChangedSettings++ + } + if ($ChangedSettings -gt 0) { Write-Log "Changed settings: $ChangedSettings" "Yellow" } From e01f428fb803b9ec77a3cf18ea9339c5f71bec68 Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Sat, 31 Dec 2022 11:50:15 +0100 Subject: [PATCH 30/86] Text --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c71c5405..548a84f4 100644 --- a/README.md +++ b/README.md @@ -150,7 +150,8 @@ The **-install** mod will be used for upgrades too if **-upgrade** doesn't exist If you want to run a script that removes the shortcut from **%PUBLIC%\Desktop** (we don't want to fill the desktop with shortcuts our users can't delete) just after installing **Acrobat Reader DC** (32-bit), prepare a powershell script that removes the Public Desktop shortcut **Acrobat Reader DC.lnk** and name your script like this: `Adobe.Acrobat.Reader.32-bit-installed.ps1` and put it in the **mods** folder. -You can find more information on [Winget-Install Repo](https://github.com/Romanitho/Winget-Install#custom-mods), as it's a related feature +You can find more information on [Winget-Install Repo](https://github.com/Romanitho/Winget-Install#custom-mods), as it's a related feature +Read more in the `README.md` under the directory **mods** ### Winget native parameters Another finess is the **AppID** followed by the `-override` suffix as a **text file** (.txt) that you can place under the **mods** folder. From a35c803e83b3f137bab5346a32c7073487285169 Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Sat, 31 Dec 2022 12:00:04 +0100 Subject: [PATCH 31/86] Reverted an accidential text deletion --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 548a84f4..f45cca8b 100644 --- a/README.md +++ b/README.md @@ -158,6 +158,8 @@ Another finess is the **AppID** followed by the `-override` suffix as a **text f > Example: > **Canneverbe.CDBurnerXP-override.txt** with the content `ADDLOCAL=All REMOVE=Desktop_Shortcut /qn` +This will use the content from the text file as a native **winget --override** parameter when upgrading (as proposed by [Nesovj](https://github.com/Nesovj) in [Mod for --override argument #244](https://github.com/Romanitho/Winget-AutoUpdate/discussions/244#discussion-4637666)). + ## GPO Management In an enterprise environment it's crucial that different groups can have different settings in an application etc. or to implement other mandatory settings. **WAU** doesn't have any setting that can be changed except for when installing (or editing the registry/the task `Winget-AutoUpdate` as **Admin** for a few settings). From 395a94c63ab3cf530a0ee1f46b79dd545f1f45b1 Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Sat, 31 Dec 2022 12:07:40 +0100 Subject: [PATCH 32/86] Text --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f45cca8b..331bb55d 100644 --- a/README.md +++ b/README.md @@ -163,7 +163,7 @@ This will use the content from the text file as a native **winget --override** p ## GPO Management In an enterprise environment it's crucial that different groups can have different settings in an application etc. or to implement other mandatory settings. **WAU** doesn't have any setting that can be changed except for when installing (or editing the registry/the task `Winget-AutoUpdate` as **Admin** for a few settings). -It's now possible to manage every setting with **GPO**. +It's now possible to manage every setting within **GPO**. Read more in the `README.md` under the directory **Policies** ![image](https://user-images.githubusercontent.com/102996177/210131296-0e0286e1-bf8e-4f94-81bd-76559ae49b7a.png) From ad7333136aaaf3cb84747eaecd13989bc27279bb Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Sat, 31 Dec 2022 13:16:57 +0100 Subject: [PATCH 33/86] Log also Changed settings if None --- Winget-AutoUpdate/functions/Get-Policies.ps1 | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Winget-AutoUpdate/functions/Get-Policies.ps1 b/Winget-AutoUpdate/functions/Get-Policies.ps1 index 72289e23..e7a31a2d 100644 --- a/Winget-AutoUpdate/functions/Get-Policies.ps1 +++ b/Winget-AutoUpdate/functions/Get-Policies.ps1 @@ -300,6 +300,10 @@ Function Get-Policies { if ($ChangedSettings -gt 0) { Write-Log "Changed settings: $ChangedSettings" "Yellow" } + else { + Write-Log "Changed settings: None" "Yellow" + } + #Get WAU Configurations after Policies change $Script:WAUConfig = Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate" } From bc66d8f98ec30c4dea369704247b9494d65359fb Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Sat, 31 Dec 2022 13:42:30 +0100 Subject: [PATCH 34/86] Text and Image --- Policies/en-US/WAU.adml | 2 +- README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Policies/en-US/WAU.adml b/Policies/en-US/WAU.adml index 44767709..3ab3b13c 100644 --- a/Policies/en-US/WAU.adml +++ b/Policies/en-US/WAU.adml @@ -107,7 +107,7 @@ WAU - Check for updated Apps If this policy is disabled or not configured, the default is No. Enable Start Menu Shortcuts - This policy setting specifies whether to enable Start Menu Shortcuts or not: + This policy setting specifies whether to enable the Start Menu Shortcuts or not: WAU - Check for updated Apps WAU - Open logs WAU - Web Help diff --git a/README.md b/README.md index 331bb55d..4b81b242 100644 --- a/README.md +++ b/README.md @@ -166,7 +166,7 @@ In an enterprise environment it's crucial that different groups can have differe It's now possible to manage every setting within **GPO**. Read more in the `README.md` under the directory **Policies** -![image](https://user-images.githubusercontent.com/102996177/210131296-0e0286e1-bf8e-4f94-81bd-76559ae49b7a.png) +![image](https://user-images.githubusercontent.com/102996177/210137062-1f65457f-953a-4026-ad47-4a60535d1fdc.png) ## Help In some cases, you need to "unblock" the `install.bat` file (Windows Defender SmartScreen). Right click, properties and unblock. Then, you'll be able to run it. From 13ff4355066b0c662394bd1aac1ea3403c8e9b30 Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Sat, 31 Dec 2022 16:25:19 +0100 Subject: [PATCH 35/86] Updates at Time now active standalone + fixes --- Policies/en-US/WAU.adml | 2 - Winget-AutoUpdate/functions/Get-Policies.ps1 | 44 ++++++++++++++++---- 2 files changed, 35 insertions(+), 11 deletions(-) diff --git a/Policies/en-US/WAU.adml b/Policies/en-US/WAU.adml index 3ab3b13c..7830262d 100644 --- a/Policies/en-US/WAU.adml +++ b/Policies/en-US/WAU.adml @@ -70,8 +70,6 @@ If this policy is disabled or not configured, the default is No. If this policy is enabled, you can configure the Sheduled Task Update time: From 01:00 to 24:00 (Military/24 Hour Time) -If set, it will not take effect until 'Updates Interval' also has been changed! - If this policy is not configured or disabled, Updates at Time: (06:00 AM). 01:00 AM 02:00 diff --git a/Winget-AutoUpdate/functions/Get-Policies.ps1 b/Winget-AutoUpdate/functions/Get-Policies.ps1 index e7a31a2d..9996bfb9 100644 --- a/Winget-AutoUpdate/functions/Get-Policies.ps1 +++ b/Winget-AutoUpdate/functions/Get-Policies.ps1 @@ -1,5 +1,6 @@ #Function to get Domain/Local Policies (GPO) + Function Get-Policies { #Get WAU Policies and set the Configurations Registry Accordingly $WAUPolicies = Get-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Romanitho\Winget-AutoUpdate" -ErrorAction SilentlyContinue @@ -82,12 +83,42 @@ Function Get-Policies { if ($null -ne $($WAUPolicies.WAU_UpdatesAtTime) -and ($($WAUPolicies.WAU_UpdatesAtTime) -ne $($WAUConfig.WAU_UpdatesAtTime))) { New-ItemProperty $regPath -Name WAU_UpdatesAtTime -Value $($WAUPolicies.WAU_UpdatesAtTime) -Force | Out-Null - $Script:WAUConfig = Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate" + $service = New-Object -ComObject Schedule.Service + $service.Connect($env:COMPUTERNAME) + $folder = $service.GetFolder('\') + $task = $folder.GetTask("Winget-AutoUpdate") + $definition = $task.Definition + for($triggerId=1; $triggerId -le $definition.Triggers.Count; $triggerId++){ + if(($definition.Triggers.Item($triggerId).Type -eq "2") -or ($definition.Triggers.Item($triggerId).Type -eq "3")){ + $PreStartBoundary = ($definition.Triggers.Item($triggerId).StartBoundary).Substring(0,11) + $PostStartBoundary = ($definition.Triggers.Item($triggerId).StartBoundary).Substring(19,6) + $Boundary = $PreStartBoundary + $($WAUPolicies.WAU_UpdatesAtTime) + $PostStartBoundary + $definition.Triggers.Item($triggerId).StartBoundary = $Boundary + break + $triggerId-=1 + } + } + $folder.RegisterTaskDefinition($task.Name, $definition, 4, $null, $null, $null) | Out-Null $ChangedSettings++ } elseif ($null -eq $($WAUPolicies.WAU_UpdatesAtTime) -and $($WAUConfig.WAU_UpdatesAtTime) -ne "06:00:00") { New-ItemProperty $regPath -Name WAU_UpdatesAtTime -Value "06:00:00" -Force | Out-Null - $Script:WAUConfig = Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate" + $service = New-Object -ComObject Schedule.Service + $service.Connect($env:COMPUTERNAME) + $folder = $service.GetFolder('\') + $task = $folder.GetTask("Winget-AutoUpdate") + $definition = $task.Definition + for($triggerId=1; $triggerId -le $definition.Triggers.Count; $triggerId++){ + if(($definition.Triggers.Item($triggerId).Type -eq "2") -or ($definition.Triggers.Item($triggerId).Type -eq "3")){ + $PreStartBoundary = ($definition.Triggers.Item($triggerId).StartBoundary).Substring(0,11) + $PostStartBoundary = ($definition.Triggers.Item($triggerId).StartBoundary).Substring(19,6) + $Boundary = $PreStartBoundary + "06:00:00" + $PostStartBoundary + $definition.Triggers.Item($triggerId).StartBoundary = $Boundary + break + $triggerId-=1 + } + } + $folder.RegisterTaskDefinition($task.Name, $definition, 4, $null, $null, $null) | Out-Null $ChangedSettings++ } @@ -203,7 +234,7 @@ Function Get-Policies { } } else { - Remove-ItemProperty $regPath -Name WAU_UpdatesAtLogon -Force -ErrorAction SilentlyContinue | Out-Null + New-ItemProperty $regPath -Name WAU_UpdatesAtLogon -Value $($WAUPolicies.WAU_UpdatesAtLogon) -PropertyType DWord -Force | Out-Null $service = New-Object -ComObject Schedule.Service $service.Connect($env:COMPUTERNAME) $folder = $service.GetFolder('\') @@ -297,12 +328,7 @@ Function Get-Policies { $ChangedSettings++ } - if ($ChangedSettings -gt 0) { - Write-Log "Changed settings: $ChangedSettings" "Yellow" - } - else { - Write-Log "Changed settings: None" "Yellow" - } + Write-Log "Changed settings: $ChangedSettings" "Yellow" #Get WAU Configurations after Policies change $Script:WAUConfig = Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate" From 5a649f318cefdb8ec5d1c32d176ce15aa4f36381 Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Sat, 31 Dec 2022 16:45:23 +0100 Subject: [PATCH 36/86] Final fix ;) --- Winget-AutoUpdate/functions/Get-Policies.ps1 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Winget-AutoUpdate/functions/Get-Policies.ps1 b/Winget-AutoUpdate/functions/Get-Policies.ps1 index 9996bfb9..258fb626 100644 --- a/Winget-AutoUpdate/functions/Get-Policies.ps1 +++ b/Winget-AutoUpdate/functions/Get-Policies.ps1 @@ -1,6 +1,5 @@ #Function to get Domain/Local Policies (GPO) - Function Get-Policies { #Get WAU Policies and set the Configurations Registry Accordingly $WAUPolicies = Get-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Romanitho\Winget-AutoUpdate" -ErrorAction SilentlyContinue @@ -83,6 +82,7 @@ Function Get-Policies { if ($null -ne $($WAUPolicies.WAU_UpdatesAtTime) -and ($($WAUPolicies.WAU_UpdatesAtTime) -ne $($WAUConfig.WAU_UpdatesAtTime))) { New-ItemProperty $regPath -Name WAU_UpdatesAtTime -Value $($WAUPolicies.WAU_UpdatesAtTime) -Force | Out-Null + $Script:WAUConfig = Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate" $service = New-Object -ComObject Schedule.Service $service.Connect($env:COMPUTERNAME) $folder = $service.GetFolder('\') @@ -103,6 +103,7 @@ Function Get-Policies { } elseif ($null -eq $($WAUPolicies.WAU_UpdatesAtTime) -and $($WAUConfig.WAU_UpdatesAtTime) -ne "06:00:00") { New-ItemProperty $regPath -Name WAU_UpdatesAtTime -Value "06:00:00" -Force | Out-Null + $Script:WAUConfig = Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate" $service = New-Object -ComObject Schedule.Service $service.Connect($env:COMPUTERNAME) $folder = $service.GetFolder('\') From af12a09dbbfe20e3b819302992f693bcc7041b15 Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Sat, 31 Dec 2022 17:44:42 +0100 Subject: [PATCH 37/86] Just better text for Disable WAU AutoUpdate... --- Policies/en-US/WAU.adml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Policies/en-US/WAU.adml b/Policies/en-US/WAU.adml index 7830262d..d23e98e2 100644 --- a/Policies/en-US/WAU.adml +++ b/Policies/en-US/WAU.adml @@ -12,8 +12,10 @@ This policy setting specifies whether to Bypass Black/White list when run in user context or not. If this policy is disabled or not configured, the default is No. - Disable Winget-AutoUpdate update checking - This policy setting specifies whether to Disable Winget-AutoUpdate update checking or not. + Disable WAU AutoUpdate + This policy setting specifies whether to Disable WAU AutoUpdate or not: +By default, WAU AutoUpdate is enabled. +It will not overwrite the configurations, icons (if personalised), excluded_apps list... If this policy is disabled or not configured, the default is No. Do not run WAU on metered connection From 91079f6b7b0043e17ae984194eb7bb8618b0e636 Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Sat, 31 Dec 2022 18:16:52 +0100 Subject: [PATCH 38/86] Better text --- Policies/en-US/WAU.adml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Policies/en-US/WAU.adml b/Policies/en-US/WAU.adml index d23e98e2..c32bc645 100644 --- a/Policies/en-US/WAU.adml +++ b/Policies/en-US/WAU.adml @@ -18,12 +18,12 @@ By default, WAU AutoUpdate is enabled. It will not overwrite the configurations, icons (if personalised), excluded_apps list... If this policy is disabled or not configured, the default is No. - Do not run WAU on metered connection + Run WAU on metered connection This policy setting specifies whether to Run WAU on metered connection or not. If this policy is disabled or not configured, the default is Yes. Update WAU to PreRelease versions - This policy setting specifies whether to update WAU to PreRelease versions or not. + This policy setting specifies whether to update WAU to PreRelease versions or not (via WAU AutoUpdate). If this policy is disabled or not configured, the default is No. Use WhiteList instead of BlackList From 4637815b24ccf2acb3bf28073794084abaf4080d Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Sat, 31 Dec 2022 18:22:07 +0100 Subject: [PATCH 39/86] No instead of Yes... --- Policies/en-US/WAU.adml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Policies/en-US/WAU.adml b/Policies/en-US/WAU.adml index c32bc645..4952d15e 100644 --- a/Policies/en-US/WAU.adml +++ b/Policies/en-US/WAU.adml @@ -21,7 +21,7 @@ If this policy is disabled or not configured, the default is No. Run WAU on metered connection This policy setting specifies whether to Run WAU on metered connection or not. -If this policy is disabled or not configured, the default is Yes. +If this policy is disabled or not configured, the default is No. Update WAU to PreRelease versions This policy setting specifies whether to update WAU to PreRelease versions or not (via WAU AutoUpdate). From 4c3828c724c3990a3e7e1adb51ec1a6beaa17ee6 Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Sat, 31 Dec 2022 18:35:10 +0100 Subject: [PATCH 40/86] Negations... --- Policies/WAU.admx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Policies/WAU.admx b/Policies/WAU.admx index 4850e606..a5754b36 100644 --- a/Policies/WAU.admx +++ b/Policies/WAU.admx @@ -50,10 +50,10 @@ - + - + From 7124aa7bf88a05170e3a2ce866dbfbdeb9ad9dd0 Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Sun, 1 Jan 2023 00:20:23 +0100 Subject: [PATCH 41/86] Nesovj changed username + text/image --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 4b81b242..68f28dcb 100644 --- a/README.md +++ b/README.md @@ -158,15 +158,15 @@ Another finess is the **AppID** followed by the `-override` suffix as a **text f > Example: > **Canneverbe.CDBurnerXP-override.txt** with the content `ADDLOCAL=All REMOVE=Desktop_Shortcut /qn` -This will use the content from the text file as a native **winget --override** parameter when upgrading (as proposed by [Nesovj](https://github.com/Nesovj) in [Mod for --override argument #244](https://github.com/Romanitho/Winget-AutoUpdate/discussions/244#discussion-4637666)). +This will use the **content** of the text file as a native **winget --override** parameter when upgrading (as proposed by [JonNesovic](https://github.com/JonNesovic) in [Mod for --override argument #244](https://github.com/Romanitho/Winget-AutoUpdate/discussions/244#discussion-4637666)). ## GPO Management -In an enterprise environment it's crucial that different groups can have different settings in an application etc. or to implement other mandatory settings. -**WAU** doesn't have any setting that can be changed except for when installing (or editing the registry/the task `Winget-AutoUpdate` as **Admin** for a few settings). -It's now possible to manage every setting within **GPO**. +In an enterprise environment it's crucial that different groups can have different settings in applications etc. or to implement other mandatory settings, i.e for security/management reasons. +**WAU** doesn't have any settings that can be changed except for when installing (or editing the registry/the task `Winget-AutoUpdate` as **Admin**). +With the use of **ADML/ADMX** files you can manage every setting from within **GPO**. Read more in the `README.md` under the directory **Policies** -![image](https://user-images.githubusercontent.com/102996177/210137062-1f65457f-953a-4026-ad47-4a60535d1fdc.png) +![image](https://user-images.githubusercontent.com/102996177/210157417-60e84023-088e-4299-9d76-b34bb0c5f088.png) ## Help In some cases, you need to "unblock" the `install.bat` file (Windows Defender SmartScreen). Right click, properties and unblock. Then, you'll be able to run it. From b50b6e76980c5823e17bd16e02a0611b8bb2d049 Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Sun, 1 Jan 2023 00:23:02 +0100 Subject: [PATCH 42/86] s- --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 68f28dcb..6ad0c66a 100644 --- a/README.md +++ b/README.md @@ -162,7 +162,7 @@ This will use the **content** of the text file as a native **winget --override** ## GPO Management In an enterprise environment it's crucial that different groups can have different settings in applications etc. or to implement other mandatory settings, i.e for security/management reasons. -**WAU** doesn't have any settings that can be changed except for when installing (or editing the registry/the task `Winget-AutoUpdate` as **Admin**). +**WAU** doesn't have any setting that can be changed except for when installing (or editing the registry/the task `Winget-AutoUpdate` as **Admin**). With the use of **ADML/ADMX** files you can manage every setting from within **GPO**. Read more in the `README.md` under the directory **Policies** From fb9117b77a48245368c03fe7e4e7536245044054 Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Sun, 1 Jan 2023 00:45:02 +0100 Subject: [PATCH 43/86] $NativeUninstallString in Mods-Functions too --- Winget-AutoUpdate/mods/_Mods-Functions.ps1 | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/Winget-AutoUpdate/mods/_Mods-Functions.ps1 b/Winget-AutoUpdate/mods/_Mods-Functions.ps1 index 4c97cf71..d9d9d5db 100644 --- a/Winget-AutoUpdate/mods/_Mods-Functions.ps1 +++ b/Winget-AutoUpdate/mods/_Mods-Functions.ps1 @@ -51,7 +51,12 @@ function Uninstall-ModsApp ($App) { Start-Process $UninstallString -ArgumentList "/VERYSILENT /SUPPRESSMSGBOXES /NORESTART /SP-" -Wait } else { - Write-Host "x64 Uninstaller unknown..." + Write-Host "x64 Uninstaller unknown, trying the UninstallString from registry..." + $NativeUninstallString = Select-String "(\x22.*\x22) +(.*)" -inputobject $UninstallString + $Command = $NativeUninstallString.matches.groups[1].value + $Parameter = $NativeUninstallString.matches.groups[2].value + #All EXE x64 Installers (native defined uninstall) + Start-Process $Command -ArgumentList $Parameter -Wait } } } @@ -97,7 +102,12 @@ function Uninstall-ModsApp ($App) { Start-Process $UninstallString -ArgumentList "/VERYSILENT /SUPPRESSMSGBOXES /NORESTART /SP-" -Wait } else { - Write-Host "x86 Uninstaller unknown..." + Write-Host "x86 Uninstaller unknown, trying the UninstallString from registry..." + $NativeUninstallString = Select-String "(\x22.*\x22) +(.*)" -inputobject $UninstallString + $Command = $NativeUninstallString.matches.groups[1].value + $Parameter = $NativeUninstallString.matches.groups[2].value + #All EXE x86 Installers (native defined uninstall) + Start-Process $Command -ArgumentList $Parameter -Wait } } } From 637f2108bbdb13f8aacce19d22bc2e5c4f735aca Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Sun, 1 Jan 2023 01:21:42 +0100 Subject: [PATCH 44/86] Test-Path --- Winget-AutoUpdate/mods/_Mods-Functions.ps1 | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/Winget-AutoUpdate/mods/_Mods-Functions.ps1 b/Winget-AutoUpdate/mods/_Mods-Functions.ps1 index d9d9d5db..88a6b4db 100644 --- a/Winget-AutoUpdate/mods/_Mods-Functions.ps1 +++ b/Winget-AutoUpdate/mods/_Mods-Functions.ps1 @@ -39,13 +39,17 @@ function Uninstall-ModsApp ($App) { Start-Process $Command -ArgumentList $Parameter -Wait } else { - $NullSoft = Select-String -Path $UninstallString.Trim([char]0x0022) -Pattern "Nullsoft" + if ((Test-Path "$UninstallString")) { + $NullSoft = Select-String -Path $UninstallString.Trim([char]0x0022) -Pattern "Nullsoft" + } if ($NullSoft) { #NSIS x64 Installer Start-Process $UninstallString -ArgumentList "/S" -Wait } else { - $Inno = Select-String -Path $UninstallString.Trim([char]0x0022) -Pattern "Inno Setup" + if ((Test-Path "$UninstallString")) { + $Inno = Select-String -Path $UninstallString.Trim([char]0x0022) -Pattern "Inno Setup" + } if ($Inno) { #Inno x64 Installer Start-Process $UninstallString -ArgumentList "/VERYSILENT /SUPPRESSMSGBOXES /NORESTART /SP-" -Wait @@ -90,13 +94,17 @@ function Uninstall-ModsApp ($App) { Start-Process $Command -ArgumentList $Parameter -Wait } else { - $NullSoft = Select-String -Path $UninstallString.Trim([char]0x0022) -Pattern "Nullsoft" + if ((Test-Path "$UninstallString")) { + $NullSoft = Select-String -Path $UninstallString.Trim([char]0x0022) -Pattern "Nullsoft" + } if ($NullSoft) { #NSIS x86 Installer Start-Process $UninstallString -ArgumentList "/S" -Wait } else { - $Inno = Select-String -Path $UninstallString.Trim([char]0x0022) -Pattern "Inno Setup" + if ((Test-Path "$UninstallString")) { + $Inno = Select-String -Path $UninstallString.Trim([char]0x0022) -Pattern "Inno Setup" + } if ($Inno) { #Inno x86 Installer Start-Process $UninstallString -ArgumentList "/VERYSILENT /SUPPRESSMSGBOXES /NORESTART /SP-" -Wait From 6659404bd77e7c60b909d04324c664c8aa02843d Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Sun, 1 Jan 2023 01:58:43 +0100 Subject: [PATCH 45/86] Corrected --- Winget-AutoUpdate/mods/_Mods-Functions.ps1 | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/Winget-AutoUpdate/mods/_Mods-Functions.ps1 b/Winget-AutoUpdate/mods/_Mods-Functions.ps1 index 88a6b4db..9bd8bc42 100644 --- a/Winget-AutoUpdate/mods/_Mods-Functions.ps1 +++ b/Winget-AutoUpdate/mods/_Mods-Functions.ps1 @@ -19,6 +19,7 @@ function Uninstall-ModsApp ($App) { foreach ($obj in $InstalledSoftware){ if ($obj.GetValue('DisplayName') -like $App) { $UninstallString = $obj.GetValue('UninstallString') + $CleanedUninstallString = $UninstallString.Trim([char]0x0022) if ($UninstallString -like "MsiExec.exe*") { $ProductCode = Select-String "{.*}" -inputobject $UninstallString $ProductCode = $ProductCode.matches.groups[0].value @@ -39,16 +40,16 @@ function Uninstall-ModsApp ($App) { Start-Process $Command -ArgumentList $Parameter -Wait } else { - if ((Test-Path "$UninstallString")) { - $NullSoft = Select-String -Path $UninstallString.Trim([char]0x0022) -Pattern "Nullsoft" + if ((Test-Path $CleanedUninstallString)) { + $NullSoft = Select-String -Path $CleanedUninstallString -Pattern "Nullsoft" } if ($NullSoft) { #NSIS x64 Installer Start-Process $UninstallString -ArgumentList "/S" -Wait } else { - if ((Test-Path "$UninstallString")) { - $Inno = Select-String -Path $UninstallString.Trim([char]0x0022) -Pattern "Inno Setup" + if ((Test-Path $CleanedUninstallString)) { + $Inno = Select-String -Path $CleanedUninstallString -Pattern "Inno Setup" } if ($Inno) { #Inno x64 Installer @@ -74,6 +75,7 @@ function Uninstall-ModsApp ($App) { foreach ($obj in $InstalledSoftware){ if ($obj.GetValue('DisplayName') -like $App) { $UninstallString = $obj.GetValue('UninstallString') + $CleanedUninstallString = $UninstallString.Trim([char]0x0022) if ($UninstallString -like "MsiExec.exe*") { $ProductCode = Select-String "{.*}" -inputobject $UninstallString $ProductCode = $ProductCode.matches.groups[0].value @@ -94,16 +96,16 @@ function Uninstall-ModsApp ($App) { Start-Process $Command -ArgumentList $Parameter -Wait } else { - if ((Test-Path "$UninstallString")) { - $NullSoft = Select-String -Path $UninstallString.Trim([char]0x0022) -Pattern "Nullsoft" + if ((Test-Path $CleanedUninstallString)) { + $NullSoft = Select-String -Path $CleanedUninstallString -Pattern "Nullsoft" } if ($NullSoft) { #NSIS x86 Installer Start-Process $UninstallString -ArgumentList "/S" -Wait } else { - if ((Test-Path "$UninstallString")) { - $Inno = Select-String -Path $UninstallString.Trim([char]0x0022) -Pattern "Inno Setup" + if ((Test-Path $CleanedUninstallString)) { + $Inno = Select-String -Path $CleanedUninstallString -Pattern "Inno Setup" } if ($Inno) { #Inno x86 Installer From 276c20aae47eaf59c39293de1b3a268c75e387dd Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Sun, 1 Jan 2023 18:28:24 +0100 Subject: [PATCH 46/86] Text --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 6ad0c66a..06f1e366 100644 --- a/README.md +++ b/README.md @@ -163,7 +163,8 @@ This will use the **content** of the text file as a native **winget --override** ## GPO Management In an enterprise environment it's crucial that different groups can have different settings in applications etc. or to implement other mandatory settings, i.e for security/management reasons. **WAU** doesn't have any setting that can be changed except for when installing (or editing the registry/the task `Winget-AutoUpdate` as **Admin**). -With the use of **ADML/ADMX** files you can manage every setting from within **GPO**. +With the use of **ADML/ADMX** files you can manage every **WAU** setting from within **GPO**. +The will be detected/evaluated during the next run of **WAU** (taking effect before any actions). Read more in the `README.md` under the directory **Policies** ![image](https://user-images.githubusercontent.com/102996177/210157417-60e84023-088e-4299-9d76-b34bb0c5f088.png) From a49d8521d8ba663798c9321ade3d61c4a86c67ef Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Sun, 1 Jan 2023 18:29:01 +0100 Subject: [PATCH 47/86] Spelling --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 06f1e366..26f88625 100644 --- a/README.md +++ b/README.md @@ -164,7 +164,7 @@ This will use the **content** of the text file as a native **winget --override** In an enterprise environment it's crucial that different groups can have different settings in applications etc. or to implement other mandatory settings, i.e for security/management reasons. **WAU** doesn't have any setting that can be changed except for when installing (or editing the registry/the task `Winget-AutoUpdate` as **Admin**). With the use of **ADML/ADMX** files you can manage every **WAU** setting from within **GPO**. -The will be detected/evaluated during the next run of **WAU** (taking effect before any actions). +They will be detected/evaluated during the next run of **WAU** (taking effect before any actions). Read more in the `README.md` under the directory **Policies** ![image](https://user-images.githubusercontent.com/102996177/210157417-60e84023-088e-4299-9d76-b34bb0c5f088.png) From f460b26fe371ef3f88bc8add70414bd10b82185c Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Tue, 3 Jan 2023 05:22:31 +0100 Subject: [PATCH 48/86] Add-ModsReg/Remove-ModsReg in Template/Functions --- Winget-AutoUpdate/mods/_AppID-template.ps1 | 24 ++++++++++++++++++++++ Winget-AutoUpdate/mods/_Mods-Functions.ps1 | 14 +++++++++++++ 2 files changed, 38 insertions(+) diff --git a/Winget-AutoUpdate/mods/_AppID-template.ps1 b/Winget-AutoUpdate/mods/_AppID-template.ps1 index db1b47d9..0a991205 100644 --- a/Winget-AutoUpdate/mods/_AppID-template.ps1 +++ b/Winget-AutoUpdate/mods/_AppID-template.ps1 @@ -12,6 +12,24 @@ $App = "" #Beginning of Desktop Link Name to Remove - optional wildcard (*) after, without .lnk, multiple: "lnk1","lnk2" $Lnk = @("") +#Registry _value_ (DWord/String) to add in existing registry Key +#Example: +#$AddKey = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate" +#$AddValue = "WAU_BypassListForUsers" +#$AddTypeValue = "1" +#$AddType = "DWord" +$AddKey = "" +$AddValue = "" +$AddTypeValue = "" +$AddType = "" + +#Registry _value_ to delete in existing registry Key +#Example: +#$DelKey = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate" +#$DelValue = "WAU_BypassListForUsers" +$DelKey = "" +$DelValue = "" + <# FUNCTIONS #> . $PSScriptRoot\_Mods-Functions.ps1 @@ -28,5 +46,11 @@ if ($App) { if ($Lnk) { Remove-ModsLnk $Lnk } +if ($AddKey -and $AddValue -and $AddTypeValue -and $AddType) { + Add-ModsReg $AddKey $AddValue $AddTypeValue $AddType +} +if ($DelKey -and $DelValue) { + Remove-ModsReg $DelKey $DelValue +} <# EXTRAS #> diff --git a/Winget-AutoUpdate/mods/_Mods-Functions.ps1 b/Winget-AutoUpdate/mods/_Mods-Functions.ps1 index 9bd8bc42..9c4978b1 100644 --- a/Winget-AutoUpdate/mods/_Mods-Functions.ps1 +++ b/Winget-AutoUpdate/mods/_Mods-Functions.ps1 @@ -135,3 +135,17 @@ function Remove-ModsLnk ($Lnk) { } Return } + +function Add-ModsReg ($AddKey, $AddValue, $AddTypeValue, $AddType) { + if (Test-Path "$AddKey") { + New-ItemProperty $AddKey -Name $AddValue -Value $AddTypeValue -PropertyType $AddType -Force | Out-Null + } + Return +} + +function Remove-ModsReg ($DelKey, $DelValue) { + if (Test-Path "$DelKey") { + Remove-ItemProperty $DelKey -Name $DelValue -Force -ErrorAction SilentlyContinue | Out-Null + } + Return +} From f087b134101bdd2f3cfc900069a6684e30cfe4ad Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Tue, 3 Jan 2023 05:25:42 +0100 Subject: [PATCH 49/86] Example delete --- Winget-AutoUpdate/mods/_AppID-template.ps1 | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Winget-AutoUpdate/mods/_AppID-template.ps1 b/Winget-AutoUpdate/mods/_AppID-template.ps1 index 0a991205..fa33216e 100644 --- a/Winget-AutoUpdate/mods/_AppID-template.ps1 +++ b/Winget-AutoUpdate/mods/_AppID-template.ps1 @@ -12,8 +12,7 @@ $App = "" #Beginning of Desktop Link Name to Remove - optional wildcard (*) after, without .lnk, multiple: "lnk1","lnk2" $Lnk = @("") -#Registry _value_ (DWord/String) to add in existing registry Key -#Example: +#Registry _value_ (DWord/String) to add in existing registry Key. Example: #$AddKey = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate" #$AddValue = "WAU_BypassListForUsers" #$AddTypeValue = "1" @@ -23,8 +22,7 @@ $AddValue = "" $AddTypeValue = "" $AddType = "" -#Registry _value_ to delete in existing registry Key -#Example: +#Registry _value_ to delete in existing registry Key. Example: #$DelKey = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate" #$DelValue = "WAU_BypassListForUsers" $DelKey = "" From 909257386138f2d1ea6a36e0ce178ffeb5ea06b8 Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Tue, 3 Jan 2023 05:29:13 +0100 Subject: [PATCH 50/86] Data instead of Value --- Winget-AutoUpdate/mods/_AppID-template.ps1 | 8 ++++---- Winget-AutoUpdate/mods/_Mods-Functions.ps1 | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Winget-AutoUpdate/mods/_AppID-template.ps1 b/Winget-AutoUpdate/mods/_AppID-template.ps1 index fa33216e..f22124f1 100644 --- a/Winget-AutoUpdate/mods/_AppID-template.ps1 +++ b/Winget-AutoUpdate/mods/_AppID-template.ps1 @@ -15,11 +15,11 @@ $Lnk = @("") #Registry _value_ (DWord/String) to add in existing registry Key. Example: #$AddKey = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate" #$AddValue = "WAU_BypassListForUsers" -#$AddTypeValue = "1" +#$AddTypeData = "1" #$AddType = "DWord" $AddKey = "" $AddValue = "" -$AddTypeValue = "" +$AddTypeData = "" $AddType = "" #Registry _value_ to delete in existing registry Key. Example: @@ -44,8 +44,8 @@ if ($App) { if ($Lnk) { Remove-ModsLnk $Lnk } -if ($AddKey -and $AddValue -and $AddTypeValue -and $AddType) { - Add-ModsReg $AddKey $AddValue $AddTypeValue $AddType +if ($AddKey -and $AddValue -and $AddTypeData -and $AddType) { + Add-ModsReg $AddKey $AddValue $AddTypeData $AddType } if ($DelKey -and $DelValue) { Remove-ModsReg $DelKey $DelValue diff --git a/Winget-AutoUpdate/mods/_Mods-Functions.ps1 b/Winget-AutoUpdate/mods/_Mods-Functions.ps1 index 9c4978b1..877bc930 100644 --- a/Winget-AutoUpdate/mods/_Mods-Functions.ps1 +++ b/Winget-AutoUpdate/mods/_Mods-Functions.ps1 @@ -136,9 +136,9 @@ function Remove-ModsLnk ($Lnk) { Return } -function Add-ModsReg ($AddKey, $AddValue, $AddTypeValue, $AddType) { +function Add-ModsReg ($AddKey, $AddValue, $AddTypeData, $AddType) { if (Test-Path "$AddKey") { - New-ItemProperty $AddKey -Name $AddValue -Value $AddTypeValue -PropertyType $AddType -Force | Out-Null + New-ItemProperty $AddKey -Name $AddValue -Value $AddTypeData -PropertyType $AddType -Force | Out-Null } Return } From a9868e30c3dd1a4a22aa83ced32de5d661a3fc23 Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Tue, 3 Jan 2023 06:16:19 +0100 Subject: [PATCH 51/86] Key if not existing --- Winget-AutoUpdate/mods/_AppID-template.ps1 | 2 +- Winget-AutoUpdate/mods/_Mods-Functions.ps1 | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Winget-AutoUpdate/mods/_AppID-template.ps1 b/Winget-AutoUpdate/mods/_AppID-template.ps1 index f22124f1..12d8f471 100644 --- a/Winget-AutoUpdate/mods/_AppID-template.ps1 +++ b/Winget-AutoUpdate/mods/_AppID-template.ps1 @@ -12,7 +12,7 @@ $App = "" #Beginning of Desktop Link Name to Remove - optional wildcard (*) after, without .lnk, multiple: "lnk1","lnk2" $Lnk = @("") -#Registry _value_ (DWord/String) to add in existing registry Key. Example: +#Registry _value_ (DWord/String) to add in existing registry Key (Key created if not existing). Example: #$AddKey = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate" #$AddValue = "WAU_BypassListForUsers" #$AddTypeData = "1" diff --git a/Winget-AutoUpdate/mods/_Mods-Functions.ps1 b/Winget-AutoUpdate/mods/_Mods-Functions.ps1 index 877bc930..8db0a141 100644 --- a/Winget-AutoUpdate/mods/_Mods-Functions.ps1 +++ b/Winget-AutoUpdate/mods/_Mods-Functions.ps1 @@ -137,9 +137,10 @@ function Remove-ModsLnk ($Lnk) { } function Add-ModsReg ($AddKey, $AddValue, $AddTypeData, $AddType) { - if (Test-Path "$AddKey") { - New-ItemProperty $AddKey -Name $AddValue -Value $AddTypeData -PropertyType $AddType -Force | Out-Null + if (!Test-Path "$AddKey") { + New-Item $AddKey -Force -ErrorAction SilentlyContinue | Out-Null } + New-ItemProperty $AddKey -Name $AddValue -Value $AddTypeData -PropertyType $AddType -Force | Out-Null Return } From feaaa6566ade1effb42c9279487eb90a805624cb Mon Sep 17 00:00:00 2001 From: GAJ-san Date: Tue, 3 Jan 2023 15:22:29 +0100 Subject: [PATCH 52/86] Started adoption of Test-ModsPath for IIS --- Winget-AutoUpdate/functions/Test-ModsPath.ps1 | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Winget-AutoUpdate/functions/Test-ModsPath.ps1 b/Winget-AutoUpdate/functions/Test-ModsPath.ps1 index 7b3e91a6..7f49c2df 100644 --- a/Winget-AutoUpdate/functions/Test-ModsPath.ps1 +++ b/Winget-AutoUpdate/functions/Test-ModsPath.ps1 @@ -25,6 +25,15 @@ function Test-ModsPath ($ModsPath, $WingetUpdatePath) { # Collect the external list of href links $ModLinks = $WebResponse.Links | Select-Object -ExpandProperty href + + #If there's a directory path in the HREF:s, delete it (IIS) + $ModLinks -replace "/.*/", "" + #$ModLinks -add "" + $$ModLinks + "" + + # Microsoft.PowerToys-installed.ps1 + #Microsoft.PowerToys-installed.ps1 + #(\x3Ca\x20href=\x22)(.*|.*) + #Delete Local Mods that don't exist Externally foreach ($Mod in $InternalModsNames) { If ($Mod -notin $ModLinks) { From d7039653b89f3643372fdf01eea11b504388ae2f Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Wed, 4 Jan 2023 00:46:24 +0100 Subject: [PATCH 53/86] List-/ModsPath rewritten, now validated on Apache --- README.md | 3 +++ Winget-AutoUpdate/functions/Test-ModsPath.ps1 | 25 ++++++++++++------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 26f88625..cb1202bd 100644 --- a/README.md +++ b/README.md @@ -91,6 +91,7 @@ Get Black/White List from Path (URL/UNC/Local) (download/copy to Winget-AutoUpda **-ModsPath** Get Mods from Path (URL/UNC/Local) (download/copy to `mods` in Winget-AutoUpdate installation location if external mods are newer). For URL: This requires a site directory with `Options +Indexes` in `.htaccess` and no index page overriding the listing of files. +Validated on IIS/Apache. Or an index page with href listing of all the Mods to be downloaded: ```
    @@ -165,6 +166,8 @@ In an enterprise environment it's crucial that different groups can have differe **WAU** doesn't have any setting that can be changed except for when installing (or editing the registry/the task `Winget-AutoUpdate` as **Admin**). With the use of **ADML/ADMX** files you can manage every **WAU** setting from within **GPO**. They will be detected/evaluated during the next run of **WAU** (taking effect before any actions). +The **GPO ADMX/ADML** validated with: +[Windows 10 - Validate ADMX for Ingestion](https://developer.vmware.com/samples/7115/windows-10---validate-admx-for-ingestion) Read more in the `README.md` under the directory **Policies** ![image](https://user-images.githubusercontent.com/102996177/210157417-60e84023-088e-4299-9d76-b34bb0c5f088.png) diff --git a/Winget-AutoUpdate/functions/Test-ModsPath.ps1 b/Winget-AutoUpdate/functions/Test-ModsPath.ps1 index 7f49c2df..83ab47f7 100644 --- a/Winget-AutoUpdate/functions/Test-ModsPath.ps1 +++ b/Winget-AutoUpdate/functions/Test-ModsPath.ps1 @@ -11,8 +11,6 @@ function Test-ModsPath ($ModsPath, $WingetUpdatePath) { # If path is URL if ($ExternalMods -like "http*") { - $wc = New-Object System.Net.WebClient - # enable TLS 1.2 and TLS 1.1 protocols [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12, [Net.SecurityProtocolType]::Tls11 #Get Index of $ExternalMods (or index page with href listing of all the Mods) @@ -24,25 +22,34 @@ function Test-ModsPath ($ModsPath, $WingetUpdatePath) { } # Collect the external list of href links - $ModLinks = $WebResponse.Links | Select-Object -ExpandProperty href + $ModLinks = $WebResponse.Links | Select-Object -ExpandProperty HREF #If there's a directory path in the HREF:s, delete it (IIS) - $ModLinks -replace "/.*/", "" - #$ModLinks -add "" + $$ModLinks + "" + $CleanLinks = $ModLinks -replace "/.*/","" - # Microsoft.PowerToys-installed.ps1 - #Microsoft.PowerToys-installed.ps1 - #(\x3Ca\x20href=\x22)(.*|.*) + #Modify strings to HREF:s + $index = 0 + foreach ($Mod in $CleanLinks) { + if ($Mod) { + $CleanLinks[$index] = ' ' + $Mod + '' + } + $index++ + } #Delete Local Mods that don't exist Externally + $DeletedMods = 0 + # 0 is the parent HTTP Directory + $index = 1 foreach ($Mod in $InternalModsNames) { - If ($Mod -notin $ModLinks) { + If ($ModLinks -notcontains "$Mod") { Remove-Item $LocalMods\$Mod -Force -ErrorAction SilentlyContinue | Out-Null $DeletedMods++ } + $index++ } #Loop through all links + $wc = New-Object System.Net.WebClient $WebResponse.Links | Select-Object -ExpandProperty href | ForEach-Object { #Check for .ps1/.txt in listing/HREF:s in an index page pointing to .ps1/.txt if (($_ -like "*.ps1") -or ($_ -like "*.txt")) { From 4b0165b7e784e0a013d8ea2d45094360bfdd4105 Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Wed, 4 Jan 2023 00:50:56 +0100 Subject: [PATCH 54/86] Linebreak --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index cb1202bd..f3a2fc02 100644 --- a/README.md +++ b/README.md @@ -91,7 +91,7 @@ Get Black/White List from Path (URL/UNC/Local) (download/copy to Winget-AutoUpda **-ModsPath** Get Mods from Path (URL/UNC/Local) (download/copy to `mods` in Winget-AutoUpdate installation location if external mods are newer). For URL: This requires a site directory with `Options +Indexes` in `.htaccess` and no index page overriding the listing of files. -Validated on IIS/Apache. +Validated on IIS/Apache. Or an index page with href listing of all the Mods to be downloaded: ```
      From a248215c6410f8275595872cf485bdb318a82c84 Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Wed, 4 Jan 2023 18:56:07 +0100 Subject: [PATCH 55/86] Done, ISS must be confed to handle ++ in filename! --- Winget-AutoUpdate/functions/Test-ModsPath.ps1 | 45 +++---------------- 1 file changed, 7 insertions(+), 38 deletions(-) diff --git a/Winget-AutoUpdate/functions/Test-ModsPath.ps1 b/Winget-AutoUpdate/functions/Test-ModsPath.ps1 index 83ab47f7..b3e52532 100644 --- a/Winget-AutoUpdate/functions/Test-ModsPath.ps1 +++ b/Winget-AutoUpdate/functions/Test-ModsPath.ps1 @@ -5,7 +5,7 @@ function Test-ModsPath ($ModsPath, $WingetUpdatePath) { # Get local and external Mods paths $LocalMods = -join ($WingetUpdatePath, "\", "mods") $ExternalMods = "$ModsPath" - + #Get File Names Locally $InternalModsNames = Get-ChildItem -Path $LocalMods -Name -Recurse -Include *.ps1, *.txt @@ -26,7 +26,7 @@ function Test-ModsPath ($ModsPath, $WingetUpdatePath) { #If there's a directory path in the HREF:s, delete it (IIS) $CleanLinks = $ModLinks -replace "/.*/","" - + #Modify strings to HREF:s $index = 0 foreach ($Mod in $CleanLinks) { @@ -40,17 +40,20 @@ function Test-ModsPath ($ModsPath, $WingetUpdatePath) { $DeletedMods = 0 # 0 is the parent HTTP Directory $index = 1 + $CleanLinks = $ModLinks -replace "/.*/","" foreach ($Mod in $InternalModsNames) { - If ($ModLinks -notcontains "$Mod") { + If ($CleanLinks -notcontains "$Mod") { Remove-Item $LocalMods\$Mod -Force -ErrorAction SilentlyContinue | Out-Null $DeletedMods++ } $index++ } + $CleanLinks = $ModLinks -replace "/.*/","" + #Loop through all links $wc = New-Object System.Net.WebClient - $WebResponse.Links | Select-Object -ExpandProperty href | ForEach-Object { + $CleanLinks | ForEach-Object { #Check for .ps1/.txt in listing/HREF:s in an index page pointing to .ps1/.txt if (($_ -like "*.ps1") -or ($_ -like "*.txt")) { try { @@ -81,38 +84,4 @@ function Test-ModsPath ($ModsPath, $WingetUpdatePath) { } return $ModsUpdated, $DeletedMods } - # If path is UNC or local - else { - if ((Test-Path -Path $ExternalMods"\*.ps1") -or (Test-Path -Path $ExternalMods"\*.txt")) { - #Get File Names Externally - $ExternalModsNames = Get-ChildItem -Path $ExternalMods -Name -Recurse -Include *.ps1, *.txt - #Delete Local Mods that don't exist Externally - foreach ($Mod in $InternalModsNames){ - If($Mod -notin $ExternalModsNames ){ - Remove-Item $LocalMods\$Mod -Force -ErrorAction SilentlyContinue | Out-Null - $DeletedMods++ - } - } - try { - foreach ($Mod in $ExternalModsNames){ - $dateExternalMod = "" - $dateLocalMod ="" - if (Test-Path -Path $LocalMods"\"$Mod) { - $dateLocalMod = (Get-Item "$LocalMods\$Mod").LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss") - } - $dateExternalMod = (Get-Item "$ExternalMods\$Mod").LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss") - if ($dateExternalMod -gt $dateLocalMod) { - Copy-Item $ExternalMods\$Mod -Destination $LocalMods\$Mod -Force -ErrorAction SilentlyContinue | Out-Null - $ModsUpdated++ - } - } - - } - catch { - return $False - } - return $ModsUpdated, $DeletedMods - } - return $False - } } From 407efdd8f726d64185849ce129f4663772dc2bc5 Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Thu, 5 Jan 2023 03:31:45 +0100 Subject: [PATCH 56/86] Forgot test deletions... --- Winget-AutoUpdate/functions/Test-ModsPath.ps1 | 37 ++++++++++++++++++- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/Winget-AutoUpdate/functions/Test-ModsPath.ps1 b/Winget-AutoUpdate/functions/Test-ModsPath.ps1 index b3e52532..ecb2842f 100644 --- a/Winget-AutoUpdate/functions/Test-ModsPath.ps1 +++ b/Winget-AutoUpdate/functions/Test-ModsPath.ps1 @@ -73,15 +73,48 @@ function Test-ModsPath ($ModsPath, $WingetUpdatePath) { $ModsUpdated++ } catch { - return $False + # Error handling } } } catch { - return $False + # Error handling } } } return $ModsUpdated, $DeletedMods } + # If path is UNC or local + else { + if ((Test-Path -Path $ExternalMods"\*.ps1") -or (Test-Path -Path $ExternalMods"\*.txt")) { + #Get File Names Externally + $ExternalModsNames = Get-ChildItem -Path $ExternalMods -Name -Recurse -Include *.ps1, *.txt + #Delete Local Mods that don't exist Externally + foreach ($Mod in $InternalModsNames){ + If($Mod -notin $ExternalModsNames ){ + Remove-Item $LocalMods\$Mod -Force -ErrorAction SilentlyContinue | Out-Null + $DeletedMods++ + } + } + try { + foreach ($Mod in $ExternalModsNames){ + $dateExternalMod = "" + $dateLocalMod ="" + if (Test-Path -Path $LocalMods"\"$Mod) { + $dateLocalMod = (Get-Item "$LocalMods\$Mod").LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss") + } + $dateExternalMod = (Get-Item "$ExternalMods\$Mod").LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss") + if ($dateExternalMod -gt $dateLocalMod) { + Copy-Item $ExternalMods\$Mod -Destination $LocalMods\$Mod -Force -ErrorAction SilentlyContinue | Out-Null + $ModsUpdated++ + } + } + + } + catch { + # Error handling + } + } + return $ModsUpdated, $DeletedMods + } } From 6301fd9622c3ed7953a9d00ddf3945128a25ba4e Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Thu, 5 Jan 2023 06:57:37 +0100 Subject: [PATCH 57/86] Remove file/directory in Mod Template/Functions --- Winget-AutoUpdate/mods/_AppID-template.ps1 | 6 ++++++ Winget-AutoUpdate/mods/_Mods-Functions.ps1 | 10 ++++++++++ 2 files changed, 16 insertions(+) diff --git a/Winget-AutoUpdate/mods/_AppID-template.ps1 b/Winget-AutoUpdate/mods/_AppID-template.ps1 index 12d8f471..ef6392c9 100644 --- a/Winget-AutoUpdate/mods/_AppID-template.ps1 +++ b/Winget-AutoUpdate/mods/_AppID-template.ps1 @@ -28,6 +28,9 @@ $AddType = "" $DelKey = "" $DelValue = "" +#Remove file/directory, multiple: "file1","file2" +$DelFile = @("") + <# FUNCTIONS #> . $PSScriptRoot\_Mods-Functions.ps1 @@ -50,5 +53,8 @@ if ($AddKey -and $AddValue -and $AddTypeData -and $AddType) { if ($DelKey -and $DelValue) { Remove-ModsReg $DelKey $DelValue } +if ($DelFile) { + Remove-ModsFile $DelFile +} <# EXTRAS #> diff --git a/Winget-AutoUpdate/mods/_Mods-Functions.ps1 b/Winget-AutoUpdate/mods/_Mods-Functions.ps1 index 8db0a141..a4202a22 100644 --- a/Winget-AutoUpdate/mods/_Mods-Functions.ps1 +++ b/Winget-AutoUpdate/mods/_Mods-Functions.ps1 @@ -150,3 +150,13 @@ function Remove-ModsReg ($DelKey, $DelValue) { } Return } + +function Remove-ModsFile ($DelFile) { + foreach ($file in $DelFile) + { + if (Test-Path "$file") { + Remove-Item -Path $file -Force -Recurse -ErrorAction SilentlyContinue | Out-Null + } + } + Return +} From 53113310c0a1c8042e6ac7abb7303d1807df0fc0 Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Thu, 5 Jan 2023 08:00:41 +0100 Subject: [PATCH 58/86] Delete entire Key in Mod Template/Functions too --- Winget-AutoUpdate/mods/_AppID-template.ps1 | 5 +++-- Winget-AutoUpdate/mods/_Mods-Functions.ps1 | 7 ++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/Winget-AutoUpdate/mods/_AppID-template.ps1 b/Winget-AutoUpdate/mods/_AppID-template.ps1 index ef6392c9..e7d942f6 100644 --- a/Winget-AutoUpdate/mods/_AppID-template.ps1 +++ b/Winget-AutoUpdate/mods/_AppID-template.ps1 @@ -22,7 +22,8 @@ $AddValue = "" $AddTypeData = "" $AddType = "" -#Registry _value_ to delete in existing registry Key. Example: +#Registry _value_ to delete in existing registry Key. +#Value can be omitted for deleting entire Key!. Example: #$DelKey = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate" #$DelValue = "WAU_BypassListForUsers" $DelKey = "" @@ -50,7 +51,7 @@ if ($Lnk) { if ($AddKey -and $AddValue -and $AddTypeData -and $AddType) { Add-ModsReg $AddKey $AddValue $AddTypeData $AddType } -if ($DelKey -and $DelValue) { +if ($DelKey) { Remove-ModsReg $DelKey $DelValue } if ($DelFile) { diff --git a/Winget-AutoUpdate/mods/_Mods-Functions.ps1 b/Winget-AutoUpdate/mods/_Mods-Functions.ps1 index a4202a22..569253ea 100644 --- a/Winget-AutoUpdate/mods/_Mods-Functions.ps1 +++ b/Winget-AutoUpdate/mods/_Mods-Functions.ps1 @@ -146,7 +146,12 @@ function Add-ModsReg ($AddKey, $AddValue, $AddTypeData, $AddType) { function Remove-ModsReg ($DelKey, $DelValue) { if (Test-Path "$DelKey") { - Remove-ItemProperty $DelKey -Name $DelValue -Force -ErrorAction SilentlyContinue | Out-Null + if (!$DelValue) { + Remove-Item $DelKey -Recurse -Force -ErrorAction SilentlyContinue | Out-Null + } + else { + Remove-ItemProperty $DelKey -Name $DelValue -Force -ErrorAction SilentlyContinue | Out-Null + } } Return } From 91e788ebb5eaf72deedee5be14ffcb7b7ed47e9f Mon Sep 17 00:00:00 2001 From: GAJ-san Date: Thu, 5 Jan 2023 15:37:30 +0100 Subject: [PATCH 59/86] Multiple App uninstall in Mod Template/Functions --- Winget-AutoUpdate/mods/_AppID-template.ps1 | 4 +- Winget-AutoUpdate/mods/_Mods-Functions.ps1 | 129 +++++++++++---------- 2 files changed, 68 insertions(+), 65 deletions(-) diff --git a/Winget-AutoUpdate/mods/_AppID-template.ps1 b/Winget-AutoUpdate/mods/_AppID-template.ps1 index e7d942f6..07ac85b5 100644 --- a/Winget-AutoUpdate/mods/_AppID-template.ps1 +++ b/Winget-AutoUpdate/mods/_AppID-template.ps1 @@ -6,8 +6,8 @@ $Proc = @("") $Wait = @("") #Beginning of App Name string to Silently Uninstall (MSI/NSIS/INNO/EXE with defined silent uninstall in registry) -#Required wildcard (*) after, search is done with "-like"! -$App = "" +#Multiple: "app1*","app2*", required wildcard (*) after; search is done with "-like"! +$App = @("") #Beginning of Desktop Link Name to Remove - optional wildcard (*) after, without .lnk, multiple: "lnk1","lnk2" $Lnk = @("") diff --git a/Winget-AutoUpdate/mods/_Mods-Functions.ps1 b/Winget-AutoUpdate/mods/_Mods-Functions.ps1 index 569253ea..96c5c791 100644 --- a/Winget-AutoUpdate/mods/_Mods-Functions.ps1 +++ b/Winget-AutoUpdate/mods/_Mods-Functions.ps1 @@ -15,63 +15,9 @@ function Wait-ModsProc ($Wait) { Return } function Uninstall-ModsApp ($App) { - $InstalledSoftware = Get-ChildItem "HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall" - foreach ($obj in $InstalledSoftware){ - if ($obj.GetValue('DisplayName') -like $App) { - $UninstallString = $obj.GetValue('UninstallString') - $CleanedUninstallString = $UninstallString.Trim([char]0x0022) - if ($UninstallString -like "MsiExec.exe*") { - $ProductCode = Select-String "{.*}" -inputobject $UninstallString - $ProductCode = $ProductCode.matches.groups[0].value - #MSI x64 Installer - $Exec = Start-Process "C:\Windows\System32\msiexec.exe" -ArgumentList "/x$ProductCode REBOOT=R /qn" -PassThru -Wait - #Stop Hard Reboot (if bad MSI!) - if ($Exec.ExitCode -eq 1641) { - Start-Process "C:\Windows\System32\shutdown.exe" -ArgumentList "/a" - } - } - else { - $QuietUninstallString = $obj.GetValue('QuietUninstallString') - if ($QuietUninstallString) { - $QuietUninstallString = Select-String "(\x22.*\x22) +(.*)" -inputobject $QuietUninstallString - $Command = $QuietUninstallString.matches.groups[1].value - $Parameter = $QuietUninstallString.matches.groups[2].value - #All EXE x64 Installers (already defined silent uninstall) - Start-Process $Command -ArgumentList $Parameter -Wait - } - else { - if ((Test-Path $CleanedUninstallString)) { - $NullSoft = Select-String -Path $CleanedUninstallString -Pattern "Nullsoft" - } - if ($NullSoft) { - #NSIS x64 Installer - Start-Process $UninstallString -ArgumentList "/S" -Wait - } - else { - if ((Test-Path $CleanedUninstallString)) { - $Inno = Select-String -Path $CleanedUninstallString -Pattern "Inno Setup" - } - if ($Inno) { - #Inno x64 Installer - Start-Process $UninstallString -ArgumentList "/VERYSILENT /SUPPRESSMSGBOXES /NORESTART /SP-" -Wait - } - else { - Write-Host "x64 Uninstaller unknown, trying the UninstallString from registry..." - $NativeUninstallString = Select-String "(\x22.*\x22) +(.*)" -inputobject $UninstallString - $Command = $NativeUninstallString.matches.groups[1].value - $Parameter = $NativeUninstallString.matches.groups[2].value - #All EXE x64 Installers (native defined uninstall) - Start-Process $Command -ArgumentList $Parameter -Wait - } - } - } - } - $x64 = $true - break - } - } - if (!$x64) { - $InstalledSoftware = Get-ChildItem "HKLM:\Software\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall" + foreach ($process in $Proc) + { + $InstalledSoftware = Get-ChildItem "HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall" foreach ($obj in $InstalledSoftware){ if ($obj.GetValue('DisplayName') -like $App) { $UninstallString = $obj.GetValue('UninstallString') @@ -79,7 +25,7 @@ function Uninstall-ModsApp ($App) { if ($UninstallString -like "MsiExec.exe*") { $ProductCode = Select-String "{.*}" -inputobject $UninstallString $ProductCode = $ProductCode.matches.groups[0].value - #MSI x86 Installer + #MSI x64 Installer $Exec = Start-Process "C:\Windows\System32\msiexec.exe" -ArgumentList "/x$ProductCode REBOOT=R /qn" -PassThru -Wait #Stop Hard Reboot (if bad MSI!) if ($Exec.ExitCode -eq 1641) { @@ -92,7 +38,7 @@ function Uninstall-ModsApp ($App) { $QuietUninstallString = Select-String "(\x22.*\x22) +(.*)" -inputobject $QuietUninstallString $Command = $QuietUninstallString.matches.groups[1].value $Parameter = $QuietUninstallString.matches.groups[2].value - #All EXE x86 Installers (already defined silent uninstall) + #All EXE x64 Installers (already defined silent uninstall) Start-Process $Command -ArgumentList $Parameter -Wait } else { @@ -100,7 +46,7 @@ function Uninstall-ModsApp ($App) { $NullSoft = Select-String -Path $CleanedUninstallString -Pattern "Nullsoft" } if ($NullSoft) { - #NSIS x86 Installer + #NSIS x64 Installer Start-Process $UninstallString -ArgumentList "/S" -Wait } else { @@ -108,23 +54,80 @@ function Uninstall-ModsApp ($App) { $Inno = Select-String -Path $CleanedUninstallString -Pattern "Inno Setup" } if ($Inno) { - #Inno x86 Installer + #Inno x64 Installer Start-Process $UninstallString -ArgumentList "/VERYSILENT /SUPPRESSMSGBOXES /NORESTART /SP-" -Wait } else { - Write-Host "x86 Uninstaller unknown, trying the UninstallString from registry..." + Write-Host "x64 Uninstaller unknown, trying the UninstallString from registry..." $NativeUninstallString = Select-String "(\x22.*\x22) +(.*)" -inputobject $UninstallString $Command = $NativeUninstallString.matches.groups[1].value $Parameter = $NativeUninstallString.matches.groups[2].value - #All EXE x86 Installers (native defined uninstall) + #All EXE x64 Installers (native defined uninstall) Start-Process $Command -ArgumentList $Parameter -Wait } } } } + $x64 = $true break } } + if (!$x64) { + $InstalledSoftware = Get-ChildItem "HKLM:\Software\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall" + foreach ($obj in $InstalledSoftware){ + if ($obj.GetValue('DisplayName') -like $App) { + $UninstallString = $obj.GetValue('UninstallString') + $CleanedUninstallString = $UninstallString.Trim([char]0x0022) + if ($UninstallString -like "MsiExec.exe*") { + $ProductCode = Select-String "{.*}" -inputobject $UninstallString + $ProductCode = $ProductCode.matches.groups[0].value + #MSI x86 Installer + $Exec = Start-Process "C:\Windows\System32\msiexec.exe" -ArgumentList "/x$ProductCode REBOOT=R /qn" -PassThru -Wait + #Stop Hard Reboot (if bad MSI!) + if ($Exec.ExitCode -eq 1641) { + Start-Process "C:\Windows\System32\shutdown.exe" -ArgumentList "/a" + } + } + else { + $QuietUninstallString = $obj.GetValue('QuietUninstallString') + if ($QuietUninstallString) { + $QuietUninstallString = Select-String "(\x22.*\x22) +(.*)" -inputobject $QuietUninstallString + $Command = $QuietUninstallString.matches.groups[1].value + $Parameter = $QuietUninstallString.matches.groups[2].value + #All EXE x86 Installers (already defined silent uninstall) + Start-Process $Command -ArgumentList $Parameter -Wait + } + else { + if ((Test-Path $CleanedUninstallString)) { + $NullSoft = Select-String -Path $CleanedUninstallString -Pattern "Nullsoft" + } + if ($NullSoft) { + #NSIS x86 Installer + Start-Process $UninstallString -ArgumentList "/S" -Wait + } + else { + if ((Test-Path $CleanedUninstallString)) { + $Inno = Select-String -Path $CleanedUninstallString -Pattern "Inno Setup" + } + if ($Inno) { + #Inno x86 Installer + Start-Process $UninstallString -ArgumentList "/VERYSILENT /SUPPRESSMSGBOXES /NORESTART /SP-" -Wait + } + else { + Write-Host "x86 Uninstaller unknown, trying the UninstallString from registry..." + $NativeUninstallString = Select-String "(\x22.*\x22) +(.*)" -inputobject $UninstallString + $Command = $NativeUninstallString.matches.groups[1].value + $Parameter = $NativeUninstallString.matches.groups[2].value + #All EXE x86 Installers (native defined uninstall) + Start-Process $Command -ArgumentList $Parameter -Wait + } + } + } + } + break + } + } + } } Return } From 7db30e57ef070debd789a3b7a504ba4365d592a2 Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Thu, 5 Jan 2023 17:10:19 +0100 Subject: [PATCH 60/86] Fix --- Winget-AutoUpdate/mods/_Mods-Functions.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Winget-AutoUpdate/mods/_Mods-Functions.ps1 b/Winget-AutoUpdate/mods/_Mods-Functions.ps1 index 96c5c791..4ccb78e5 100644 --- a/Winget-AutoUpdate/mods/_Mods-Functions.ps1 +++ b/Winget-AutoUpdate/mods/_Mods-Functions.ps1 @@ -15,7 +15,7 @@ function Wait-ModsProc ($Wait) { Return } function Uninstall-ModsApp ($App) { - foreach ($process in $Proc) + foreach ($app in $App) { $InstalledSoftware = Get-ChildItem "HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall" foreach ($obj in $InstalledSoftware){ From e302d8166646a8ac826bb2202d0637253eae5c4c Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Thu, 5 Jan 2023 18:30:39 +0100 Subject: [PATCH 61/86] README --- README.md | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index f3a2fc02..60ae953a 100644 --- a/README.md +++ b/README.md @@ -86,13 +86,12 @@ Disable Winget-AutoUpdate update checking. By default, WAU auto updates if new v Use White List instead of Black List. This setting will not create the "excluded_apps.txt" but "included_apps.txt" **-ListPath** -Get Black/White List from Path (URL/UNC/Local) (download/copy to Winget-AutoUpdate installation location if external list is newer). +Get Black/White List from Path (**URL/UNC/Local**) (download/copy to Winget-AutoUpdate installation location if external list is newer). **-ModsPath** -Get Mods from Path (URL/UNC/Local) (download/copy to `mods` in Winget-AutoUpdate installation location if external mods are newer). -For URL: This requires a site directory with `Options +Indexes` in `.htaccess` and no index page overriding the listing of files. -Validated on IIS/Apache. -Or an index page with href listing of all the Mods to be downloaded: +Get Mods from external Path (**URL/UNC/Local**) - download/copy to `mods` in Winget-AutoUpdate installation location if external mods are newer. + +For **URL**: This requires a site directory with **Directory Listing Enabled** and no index page overriding the listing of files (or an index page with href listing of all the **Mods** to be downloaded): ``` ``` +Validated on **IIS/Apache**. +**Nota bene IIS** : Files with special characters in the filename can't be opened by default from an IIS server - config must be administrated: **Enable Allow double escaping** in '**Request Filtering**'. **-InstallUserContext** Install WAU with system and **user** context executions (From version 1.15.3) From c35f337b433efb58309927d09e708eadccc2343a Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Thu, 5 Jan 2023 18:50:55 +0100 Subject: [PATCH 62/86] Text --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 60ae953a..75f49805 100644 --- a/README.md +++ b/README.md @@ -86,7 +86,7 @@ Disable Winget-AutoUpdate update checking. By default, WAU auto updates if new v Use White List instead of Black List. This setting will not create the "excluded_apps.txt" but "included_apps.txt" **-ListPath** -Get Black/White List from Path (**URL/UNC/Local**) (download/copy to Winget-AutoUpdate installation location if external list is newer). +Get Black/White List from external Path (**URL/UNC/Local**) - download/copy to Winget-AutoUpdate installation location if external list is newer. **-ModsPath** Get Mods from external Path (**URL/UNC/Local**) - download/copy to `mods` in Winget-AutoUpdate installation location if external mods are newer. From 134c7fb57eeaaad76bb2237b02d3010ecc46e72b Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Thu, 5 Jan 2023 18:52:27 +0100 Subject: [PATCH 63/86] Missed spaces... --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 75f49805..70afd7be 100644 --- a/README.md +++ b/README.md @@ -94,10 +94,10 @@ Get Mods from external Path (**URL/UNC/Local**) - download/copy to `mods` in Win For **URL**: This requires a site directory with **Directory Listing Enabled** and no index page overriding the listing of files (or an index page with href listing of all the **Mods** to be downloaded): ``` ``` Validated on **IIS/Apache**. From 39de5497f7b857647eaa0c984d80cd800161d759 Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Fri, 6 Jan 2023 07:37:10 +0100 Subject: [PATCH 64/86] Better explanation --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 70afd7be..179aa958 100644 --- a/README.md +++ b/README.md @@ -146,7 +146,8 @@ Just put the scripts in question with the **AppID** followed by the `-preinstall > Runs during upgrade/install (before install check): `AppID-upgrade.ps1`/`AppID-install.ps1` > Runs after upgrade/install has been confirmed: `AppID-installed.ps1` -The **-install** mod will be used for upgrades too if **-upgrade** doesn't exist +The **-install** mod will be used for upgrades too if **-upgrade** doesn't exist (**WAU** first tries `& $Winget upgrade --id` and if the app isn't detected after that `& $Winget install --id` is tried) +`AppID-install.ps1` is recommended because it's used in **both** scenarios. > Example: If you want to run a script that removes the shortcut from **%PUBLIC%\Desktop** (we don't want to fill the desktop with shortcuts our users can't delete) just after installing **Acrobat Reader DC** (32-bit), prepare a powershell script that removes the Public Desktop shortcut **Acrobat Reader DC.lnk** and name your script like this: From d7d1bf18f89999ea4f800baea92ca071d173497c Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Fri, 6 Jan 2023 09:25:30 +0100 Subject: [PATCH 65/86] Text --- README.md | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 179aa958..d55c7329 100644 --- a/README.md +++ b/README.md @@ -94,14 +94,18 @@ Get Mods from external Path (**URL/UNC/Local**) - download/copy to `mods` in Win For **URL**: This requires a site directory with **Directory Listing Enabled** and no index page overriding the listing of files (or an index page with href listing of all the **Mods** to be downloaded): ``` ``` Validated on **IIS/Apache**. -**Nota bene IIS** : Files with special characters in the filename can't be opened by default from an IIS server - config must be administrated: **Enable Allow double escaping** in '**Request Filtering**'. + +**Nota bene IIS** : + - The extension **.ps1** must be added as **allowed extension** (otherwise it's displayed in the listing but cant be opened) + - Files with special characters in the filename can't be opened by default from an IIS server - config must be administrated: **Enable Allow double escaping** in '**Request Filtering**' **-InstallUserContext** Install WAU with system and **user** context executions (From version 1.15.3) From 6f7e0d4a6211e1d90d595d333d6e8f43b1cd7b18 Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Fri, 6 Jan 2023 09:33:16 +0100 Subject: [PATCH 66/86] Last text... --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d55c7329..01252b3c 100644 --- a/README.md +++ b/README.md @@ -104,7 +104,7 @@ For **URL**: This requires a site directory with **Directory Listing Enabled** a Validated on **IIS/Apache**. **Nota bene IIS** : - - The extension **.ps1** must be added as **allowed extension** (otherwise it's displayed in the listing but cant be opened) + - The extension **.ps1** must be added as **MIME Types - text/powershell-script** (otherwise it's displayed in the listing but cant be opened) - Files with special characters in the filename can't be opened by default from an IIS server - config must be administrated: **Enable Allow double escaping** in '**Request Filtering**' **-InstallUserContext** From f194b63760b1daaf28f40a8c078674c3b9357130 Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Fri, 6 Jan 2023 09:36:11 +0100 Subject: [PATCH 67/86] ...and last deletion - done! --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 01252b3c..c41b336c 100644 --- a/README.md +++ b/README.md @@ -98,7 +98,6 @@ For **URL**: This requires a site directory with **Directory Listing Enabled** a
    • Adobe.Acrobat.Reader.64-bit-override.txt
    • Notepad++.Notepad++-installed.ps1
    • Notepad++.Notepad++-uninstalled.ps1
    • -
    • WinMerge.WinMerge-installed.ps1
    ``` Validated on **IIS/Apache**. From abf5b8e8b5dc40260caa0e79b4c82c4824149133 Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Fri, 6 Jan 2023 10:11:49 +0100 Subject: [PATCH 68/86] Punctuation --- README.md | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index c41b336c..0055ff0a 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ From 1.7.0 version, you can update only pre-selected apps. To do so, create an " > You can use WiGui to create these lists: https://github.com/Romanitho/Winget-Install-GUI ### Notification Level -From version 1.9.0, you can choose which notification will be displayed: Full, Success only or none. Use `-NotificationLevel` parameter when you run `Winget-AutoUpdate-Install.ps1` +From version 1.9.0, you can choose which notification will be displayed: Full, Success only or none. Use `-NotificationLevel` parameter when you run `Winget-AutoUpdate-Install.ps1`. ### Notification language You can easily translate toast notifications by creating your locale xml config file (and share it with us :) ). @@ -47,7 +47,7 @@ We might want to stop WAU on metered connection (to save cellular data on connec To force WAU to run on metered connections anyway, run new installation with `-RunOnMetered` parameter. ### System & user context -From version 1.15.0, WAU run with system and user contexts. This way, even apps installed on User's scope are updated. Shorcuts for manually run can also be installed +From version 1.15.0, WAU run with system and user contexts. This way, even apps installed on User's scope are updated. Shorcuts for manually run can also be installed. ## Update WAU ### Manual Update @@ -55,7 +55,7 @@ Same process as new installation : download, unzip and run `install.bat`. ### Automatic Update A new Auto-Update process has been released from version 1.5.0. By default, WAU AutoUpdate is enabled. It will not overwrite the configurations, icons (if personalised), excluded_apps list,... -To disable WAU AutoUpdate, run the `Winget-AutoUpdate-Install.ps1` with `-DisableWAUAutoUpdate` parameter +To disable WAU AutoUpdate, run the `Winget-AutoUpdate-Install.ps1` with `-DisableWAUAutoUpdate` parameter. ## Uninstall WAU Simply uninstall it from your programs: @@ -71,10 +71,10 @@ Simply uninstall it from your programs: You can run the `Winget-AutoUpdate-Install.ps1` script with parameters : **-Silent** -Install Winget-AutoUpdate and prerequisites silently +Install Winget-AutoUpdate and prerequisites silently. **-WingetUpdatePath** -Specify Winget-AutoUpdate installation location. Default: `C:\ProgramData\Winget-AutoUpdate` (Recommended to leave default) +Specify Winget-AutoUpdate installation location. Default: `C:\ProgramData\Winget-AutoUpdate` (Recommended to leave default). **-DoNotUpdate** Do not run Winget-AutoUpdate after installation. By default, Winget-AutoUpdate is run just after installation. @@ -83,7 +83,7 @@ Do not run Winget-AutoUpdate after installation. By default, Winget-AutoUpdate i Disable Winget-AutoUpdate update checking. By default, WAU auto updates if new version is available on Github. **-UseWhiteList** -Use White List instead of Black List. This setting will not create the "excluded_apps.txt" but "included_apps.txt" +Use White List instead of Black List. This setting will not create the "excluded_apps.txt" but "included_apps.txt". **-ListPath** Get Black/White List from external Path (**URL/UNC/Local**) - download/copy to Winget-AutoUpdate installation location if external list is newer. @@ -103,23 +103,23 @@ For **URL**: This requires a site directory with **Directory Listing Enabled** a Validated on **IIS/Apache**. **Nota bene IIS** : - - The extension **.ps1** must be added as **MIME Types - text/powershell-script** (otherwise it's displayed in the listing but cant be opened) + - The extension **.ps1** must be added as **MIME Types** (text/powershell-script) otherwise it's displayed in the listing but can't be opened - Files with special characters in the filename can't be opened by default from an IIS server - config must be administrated: **Enable Allow double escaping** in '**Request Filtering**' **-InstallUserContext** -Install WAU with system and **user** context executions (From version 1.15.3) +Install WAU with system and **user** context executions (From version 1.15.3). **-BypassListForUsers** -Bypass Black/White list when run in user context (From version 1.15.0) +Bypass Black/White list when run in user context (From version 1.15.0). **-NoClean** Keep critical files when installing/uninstalling. This setting will keep "excluded_apps.txt", "included_apps.txt", "mods" and "logs" as they were. **-DesktopShortcut** -Create a shortcut for user interaction on the Desktop to run task `Winget-AutoUpdate` (From version 1.15.0) +Create a shortcut for user interaction on the Desktop to run task `Winget-AutoUpdate` (From version 1.15.0). **-StartMenuShortcut** -Create shortcuts for user interaction in the Start Menu to run task `Winget-AutoUpdate`, open Logs and Web Help (From version 1.15.0) +Create shortcuts for user interaction in the Start Menu to run task `Winget-AutoUpdate`, open Logs and Web Help (From version 1.15.0). **-NotificationLevel** Specify the Notification level: Full (Default, displays all notification), SuccessOnly (Only displays notification for success) or None (Does not show any popup). @@ -128,10 +128,10 @@ Specify the Notification level: Full (Default, displays all notification), Succe Set WAU to run at user logon. **-UpdatesInterval** -Specify the update frequency: Daily (Default), BiDaily, Weekly, BiWeekly, Monthly or Never. Can be set to 'Never' in combination with '-UpdatesAtLogon' for instance +Specify the update frequency: Daily (Default), BiDaily, Weekly, BiWeekly, Monthly or Never. Can be set to 'Never' in combination with '-UpdatesAtLogon' for instance. **-UpdatesAtTime** -Specify the time of the update interval execution time. Default 6AM. (From version 1.15.0) +Specify the time of the update interval execution time. Default 6AM. (From version 1.15.0). **-RunOnMetered** Run WAU on metered connection. Default No. @@ -149,15 +149,15 @@ Just put the scripts in question with the **AppID** followed by the `-preinstall > Runs during upgrade/install (before install check): `AppID-upgrade.ps1`/`AppID-install.ps1` > Runs after upgrade/install has been confirmed: `AppID-installed.ps1` -The **-install** mod will be used for upgrades too if **-upgrade** doesn't exist (**WAU** first tries `& $Winget upgrade --id` and if the app isn't detected after that `& $Winget install --id` is tried) +The **-install** mod will be used for upgrades too if **-upgrade** doesn't exist (**WAU** first tries `& $Winget upgrade --id` and if the app isn't detected after that `& $Winget install --id` is tried). `AppID-install.ps1` is recommended because it's used in **both** scenarios. > Example: If you want to run a script that removes the shortcut from **%PUBLIC%\Desktop** (we don't want to fill the desktop with shortcuts our users can't delete) just after installing **Acrobat Reader DC** (32-bit), prepare a powershell script that removes the Public Desktop shortcut **Acrobat Reader DC.lnk** and name your script like this: `Adobe.Acrobat.Reader.32-bit-installed.ps1` and put it in the **mods** folder. -You can find more information on [Winget-Install Repo](https://github.com/Romanitho/Winget-Install#custom-mods), as it's a related feature -Read more in the `README.md` under the directory **mods** +You can find more information on [Winget-Install Repo](https://github.com/Romanitho/Winget-Install#custom-mods), as it's a related feature. +Read more in the `README.md` under the directory **mods**. ### Winget native parameters Another finess is the **AppID** followed by the `-override` suffix as a **text file** (.txt) that you can place under the **mods** folder. @@ -173,7 +173,7 @@ With the use of **ADML/ADMX** files you can manage every **WAU** setting from wi They will be detected/evaluated during the next run of **WAU** (taking effect before any actions). The **GPO ADMX/ADML** validated with: [Windows 10 - Validate ADMX for Ingestion](https://developer.vmware.com/samples/7115/windows-10---validate-admx-for-ingestion) -Read more in the `README.md` under the directory **Policies** +Read more in the `README.md` under the directory **Policies**. ![image](https://user-images.githubusercontent.com/102996177/210157417-60e84023-088e-4299-9d76-b34bb0c5f088.png) @@ -184,4 +184,4 @@ In some cases, you need to "unblock" the `install.bat` file (Windows Defender Sm * As reported by [soredake](https://github.com/soredake), Powershell from MsStore is not supported with WAU in system context. See https://github.com/Romanitho/Winget-AutoUpdate/issues/113 ## Optimization -Feel free to give us any suggestions or optimizations in code and support us by adding a star :) +Feel free to give us any suggestions or optimizations in code and support us by adding a star :). From 5889444af735b73684a12c02256379faa0d8bf87 Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Sat, 7 Jan 2023 00:53:53 +0100 Subject: [PATCH 69/86] Mods README clarified --- Winget-AutoUpdate/mods/README.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Winget-AutoUpdate/mods/README.md b/Winget-AutoUpdate/mods/README.md index dfecef74..0e08fd3e 100644 --- a/Winget-AutoUpdate/mods/README.md +++ b/Winget-AutoUpdate/mods/README.md @@ -1,7 +1,10 @@ Pre/During/Post install/uninstall custom scripts should be placed here. -A script Template and Mods Functions are included as example to get you started... +A script **Template** and **Mods Functions** are included as **example** to get you started... Scripts that are considered: -**AppID**`-preinstall.ps1`, `-upgrade.ps1`, `-install.ps1`, `-installed.ps1`, `-preuninstall.ps1`, `-uninstall.ps1` or `-uninstalled.ps1` +**AppID**`-preinstall.ps1`, `-upgrade.ps1`, `-install.ps1`, `-installed.ps1`, `-preuninstall.ps1`, `-uninstall.ps1` or `-uninstalled.ps1` + +The **-install** mod will be used for upgrades too if **-upgrade** doesn't exist (**WAU** first tries `& $Winget upgrade --id` and if the app isn't detected after that `& $Winget install --id` is tried). +`AppID-install.ps1` is recommended because it's used in **both** scenarios. **AppID**`-override.txt` (the content) will be used as a native **winget --override** parameter when upgrading From aacf0ace1ecd02554d556abe89425f687e807d46 Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Sat, 7 Jan 2023 00:55:20 +0100 Subject: [PATCH 70/86] Line Break --- Winget-AutoUpdate/mods/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Winget-AutoUpdate/mods/README.md b/Winget-AutoUpdate/mods/README.md index 0e08fd3e..1cd38e34 100644 --- a/Winget-AutoUpdate/mods/README.md +++ b/Winget-AutoUpdate/mods/README.md @@ -4,7 +4,7 @@ A script **Template** and **Mods Functions** are included as **example** to get Scripts that are considered: **AppID**`-preinstall.ps1`, `-upgrade.ps1`, `-install.ps1`, `-installed.ps1`, `-preuninstall.ps1`, `-uninstall.ps1` or `-uninstalled.ps1` -The **-install** mod will be used for upgrades too if **-upgrade** doesn't exist (**WAU** first tries `& $Winget upgrade --id` and if the app isn't detected after that `& $Winget install --id` is tried). +The **-install** mod will be used for upgrades too if **-upgrade** doesn't exist (**WAU** first tries `& $Winget upgrade --id` and if the app isn't detected after that `& $Winget install --id` is tried). `AppID-install.ps1` is recommended because it's used in **both** scenarios. **AppID**`-override.txt` (the content) will be used as a native **winget --override** parameter when upgrading From 11ee64ec57759635fcf153f9286523afd166ad74 Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Sun, 8 Jan 2023 03:30:43 +0100 Subject: [PATCH 71/86] Separate local White/Black list checking --- Winget-AutoUpdate/Winget-Upgrade.ps1 | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Winget-AutoUpdate/Winget-Upgrade.ps1 b/Winget-AutoUpdate/Winget-Upgrade.ps1 index 38703cb9..18a8f196 100644 --- a/Winget-AutoUpdate/Winget-Upgrade.ps1 +++ b/Winget-AutoUpdate/Winget-Upgrade.ps1 @@ -84,12 +84,15 @@ if (Test-Network) { Write-Log "Newer List downloaded/copied to local path: $($WAUConfig.InstallLocation.TrimEnd(" ", "\"))" "Yellow" } else { - if ((Test-Path "$WorkingDir\included_apps.txt") -or (Test-Path "$WorkingDir\excluded_apps.txt")) { - Write-Log "List is up to date." "Green" + if ($WAUConfig.WAU_UseWhiteList -and (Test-Path "$WorkingDir\included_apps.txt")) { + Write-Log "List (white) is up to date." "Green" + } + elseif (!$WAUConfig.WAU_UseWhiteList -and (Test-Path "$WorkingDir\excluded_apps.txt")) { + Write-Log "List (black) is up to date." "Green" } else { - Write-Log "Critical: List doesn't exist, exiting..." "Red" - New-Item "$WorkingDir\logs\error.txt" -Value "List doesn't exist!" -Force + Write-Log "Critical: White/Black List doesn't exist, exiting..." "Red" + New-Item "$WorkingDir\logs\error.txt" -Value "White/Black List doesn't exist!" -Force Exit 1 } } From 72bcf776721a6bf6d75223aea24999e07cd9efd3 Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Sun, 8 Jan 2023 18:57:47 +0100 Subject: [PATCH 72/86] List/ Mods Path critical corrections --- Winget-AutoUpdate/Winget-Upgrade.ps1 | 8 ++++++++ Winget-AutoUpdate/functions/Test-ListPath.ps1 | 20 +++++++++++++++---- Winget-AutoUpdate/functions/Test-ModsPath.ps1 | 16 +++++++++++---- 3 files changed, 36 insertions(+), 8 deletions(-) diff --git a/Winget-AutoUpdate/Winget-Upgrade.ps1 b/Winget-AutoUpdate/Winget-Upgrade.ps1 index 18a8f196..c137ad6f 100644 --- a/Winget-AutoUpdate/Winget-Upgrade.ps1 +++ b/Winget-AutoUpdate/Winget-Upgrade.ps1 @@ -80,6 +80,10 @@ if (Test-Network) { if ($WAUConfig.WAU_ListPath) { Write-Log "WAU uses External Lists from: $($WAUConfig.WAU_ListPath.TrimEnd(" ", "\", "/"))" $NewList = Test-ListPath $WAUConfig.WAU_ListPath.TrimEnd(" ", "\", "/") $WAUConfig.WAU_UseWhiteList $WAUConfig.InstallLocation.TrimEnd(" ", "\") + if ($ReachNoPath) { + Write-Log "Couldn't reach/find/compare/copy from $($WAUConfig.WAU_ListPath.TrimEnd(" ", "\", "/"))..." "Red" + $Script:ReachNoPath = $False + } if ($NewList) { Write-Log "Newer List downloaded/copied to local path: $($WAUConfig.InstallLocation.TrimEnd(" ", "\"))" "Yellow" } @@ -102,6 +106,10 @@ if (Test-Network) { if ($WAUConfig.WAU_ModsPath) { Write-Log "WAU uses External Mods from: $($WAUConfig.WAU_ModsPath.TrimEnd(" ", "\", "/"))" $NewMods, $DeletedMods = Test-ModsPath $WAUConfig.WAU_ModsPath.TrimEnd(" ", "\", "/") $WAUConfig.InstallLocation.TrimEnd(" ", "\") + if ($ReachNoPath) { + Write-Log "Couldn't reach/find/compare/copy from $($WAUConfig.WAU_ModsPath.TrimEnd(" ", "\", "/"))..." "Red" + $Script:ReachNoPath = $False + } if ($NewMods -gt 0) { Write-Log "$NewMods newer Mods downloaded/copied to local path: $($WAUConfig.InstallLocation.TrimEnd(" ", "\"))\mods" "Yellow" } diff --git a/Winget-AutoUpdate/functions/Test-ListPath.ps1 b/Winget-AutoUpdate/functions/Test-ListPath.ps1 index f7dbdc2b..9284eeb4 100644 --- a/Winget-AutoUpdate/functions/Test-ListPath.ps1 +++ b/Winget-AutoUpdate/functions/Test-ListPath.ps1 @@ -30,29 +30,41 @@ function Test-ListPath ($ListPath, $UseWhiteList, $WingetUpdatePath) { $wc.DownloadFile($ExternalList, $LocalList) } catch { + $Script:ReachNoPath = $True return $False } return $true } } catch { + $Script:ReachNoPath = $True return $False } } # If path is UNC or local else { - if (Test-Path -Path $ExternalList -PathType leaf) { - $dateExternal = (Get-Item "$ExternalList").LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss") + if (Test-Path -Path $ExternalList) { + try { + $dateExternal = (Get-Item "$ExternalList").LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss") + } + catch { + $Script:ReachNoPath = $True + return $False + } if ($dateExternal -gt $dateLocal) { try { Copy-Item $ExternalList -Destination $LocalList -Force } catch { + $Script:ReachNoPath = $True return $False } - return $true + return $True } } + else { + $Script:ReachNoPath = $True + } + return $False } - return $false } diff --git a/Winget-AutoUpdate/functions/Test-ModsPath.ps1 b/Winget-AutoUpdate/functions/Test-ModsPath.ps1 index ecb2842f..b9c4c244 100644 --- a/Winget-AutoUpdate/functions/Test-ModsPath.ps1 +++ b/Winget-AutoUpdate/functions/Test-ModsPath.ps1 @@ -18,6 +18,7 @@ function Test-ModsPath ($ModsPath, $WingetUpdatePath) { $WebResponse = Invoke-WebRequest -Uri $ExternalMods -UseBasicParsing } catch { + $Script:ReachNoPath = $True return $False } @@ -73,12 +74,12 @@ function Test-ModsPath ($ModsPath, $WingetUpdatePath) { $ModsUpdated++ } catch { - # Error handling + $Script:ReachNoPath = $True } } } catch { - # Error handling + $Script:ReachNoPath = $True } } } @@ -89,13 +90,17 @@ function Test-ModsPath ($ModsPath, $WingetUpdatePath) { if ((Test-Path -Path $ExternalMods"\*.ps1") -or (Test-Path -Path $ExternalMods"\*.txt")) { #Get File Names Externally $ExternalModsNames = Get-ChildItem -Path $ExternalMods -Name -Recurse -Include *.ps1, *.txt + #Delete Local Mods that don't exist Externally + $DeletedMods = 0 foreach ($Mod in $InternalModsNames){ - If($Mod -notin $ExternalModsNames ){ + If ($Mod -notin $ExternalModsNames ){ Remove-Item $LocalMods\$Mod -Force -ErrorAction SilentlyContinue | Out-Null $DeletedMods++ } } + + #Copy newer external mods try { foreach ($Mod in $ExternalModsNames){ $dateExternalMod = "" @@ -112,9 +117,12 @@ function Test-ModsPath ($ModsPath, $WingetUpdatePath) { } catch { - # Error handling + $Script:ReachNoPath = $True } } + else { + $Script:ReachNoPath = $True + } return $ModsUpdated, $DeletedMods } } From 237e9c3106a0754137279477f34cca050f2bd3b5 Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Sun, 8 Jan 2023 23:18:40 +0100 Subject: [PATCH 73/86] Copy file/directory in Mod Template/Functions --- Winget-AutoUpdate/mods/_AppID-template.ps1 | 10 ++++++++++ Winget-AutoUpdate/mods/_Mods-Functions.ps1 | 8 ++++++++ 2 files changed, 18 insertions(+) diff --git a/Winget-AutoUpdate/mods/_AppID-template.ps1 b/Winget-AutoUpdate/mods/_AppID-template.ps1 index 07ac85b5..e824b73c 100644 --- a/Winget-AutoUpdate/mods/_AppID-template.ps1 +++ b/Winget-AutoUpdate/mods/_AppID-template.ps1 @@ -32,6 +32,13 @@ $DelValue = "" #Remove file/directory, multiple: "file1","file2" $DelFile = @("") +#Copy file/directory +#Example: +#$CopyFile = "C:\Logfiles" +#$CopyTo = "C:\Drawings\Logs" +$CopyFile = "" +$CopyTo = "" + <# FUNCTIONS #> . $PSScriptRoot\_Mods-Functions.ps1 @@ -57,5 +64,8 @@ if ($DelKey) { if ($DelFile) { Remove-ModsFile $DelFile } +if ($CopyFile -and $CopyTo) { + Copy-ModsFile $CopyFile $CopyTo +} <# EXTRAS #> diff --git a/Winget-AutoUpdate/mods/_Mods-Functions.ps1 b/Winget-AutoUpdate/mods/_Mods-Functions.ps1 index 4ccb78e5..e57e53a8 100644 --- a/Winget-AutoUpdate/mods/_Mods-Functions.ps1 +++ b/Winget-AutoUpdate/mods/_Mods-Functions.ps1 @@ -168,3 +168,11 @@ function Remove-ModsFile ($DelFile) { } Return } + +function Copy-ModsFile ($CopyFile, $CopyTo) { + if (Test-Path "$CopyFile") { + Copy-Item -Path $CopyFile -Destination $CopyTo -Recurse -Force -ErrorAction SilentlyContinue | Out-Null + } + Return +} + From 2839500448649fe7065e7fe07cb4a5be24ec7d40 Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Mon, 9 Jan 2023 01:25:39 +0100 Subject: [PATCH 74/86] Run App in Mods Template/Functions too --- Winget-AutoUpdate/mods/_AppID-template.ps1 | 8 ++++++++ Winget-AutoUpdate/mods/_Mods-Functions.ps1 | 16 ++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/Winget-AutoUpdate/mods/_AppID-template.ps1 b/Winget-AutoUpdate/mods/_AppID-template.ps1 index e824b73c..5ceac134 100644 --- a/Winget-AutoUpdate/mods/_AppID-template.ps1 +++ b/Winget-AutoUpdate/mods/_AppID-template.ps1 @@ -1,4 +1,9 @@ <# ARRAYS/VARIABLES #> +#App to Run ($RunWait = $False if it shouldn't be waited for) +$Run = "" +$RunSwitch = "" +$RunWait = $True + #Beginning of Process Name to Stop - optional wildcard (*) after, without .exe, multiple: "proc1","proc2" $Proc = @("") @@ -43,6 +48,9 @@ $CopyTo = "" . $PSScriptRoot\_Mods-Functions.ps1 <# MAIN #> +if ($Run) { + Invoke-ModsApp $Run $RunSwitch $RunWait +} if ($Proc) { Stop-ModsProc $Proc } diff --git a/Winget-AutoUpdate/mods/_Mods-Functions.ps1 b/Winget-AutoUpdate/mods/_Mods-Functions.ps1 index e57e53a8..705d3448 100644 --- a/Winget-AutoUpdate/mods/_Mods-Functions.ps1 +++ b/Winget-AutoUpdate/mods/_Mods-Functions.ps1 @@ -1,5 +1,18 @@ #Common shared functions for mods handling +function Invoke-ModsApp ($Run, $RunSwitch, $RunWait) { + if (Test-Path "$Run") { + if (!$RunWait) { + Start-Process $Run -ArgumentList $RunSwitch + } + else { + Start-Process $Run -ArgumentList $RunSwitch -Wait + } + } + Return +} + + function Stop-ModsProc ($Proc) { foreach ($process in $Proc) { @@ -7,6 +20,7 @@ function Stop-ModsProc ($Proc) { } Return } + function Wait-ModsProc ($Wait) { foreach ($process in $Wait) { @@ -14,6 +28,7 @@ function Wait-ModsProc ($Wait) { } Return } + function Uninstall-ModsApp ($App) { foreach ($app in $App) { @@ -131,6 +146,7 @@ function Uninstall-ModsApp ($App) { } Return } + function Remove-ModsLnk ($Lnk) { foreach ($link in $Lnk) { From 50263f756e7cd27693760c4254264e29727b5f3f Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Tue, 10 Jan 2023 03:35:03 +0100 Subject: [PATCH 75/86] mod\bins for placing MsiZap.exe etc. in --- Winget-AutoUpdate/functions/Test-ModsPath.ps1 | 102 ++++++++++++++---- Winget-AutoUpdate/mods/bins/README.md | 6 ++ 2 files changed, 89 insertions(+), 19 deletions(-) create mode 100644 Winget-AutoUpdate/mods/bins/README.md diff --git a/Winget-AutoUpdate/functions/Test-ModsPath.ps1 b/Winget-AutoUpdate/functions/Test-ModsPath.ps1 index b9c4c244..6eed0629 100644 --- a/Winget-AutoUpdate/functions/Test-ModsPath.ps1 +++ b/Winget-AutoUpdate/functions/Test-ModsPath.ps1 @@ -8,6 +8,7 @@ function Test-ModsPath ($ModsPath, $WingetUpdatePath) { #Get File Names Locally $InternalModsNames = Get-ChildItem -Path $LocalMods -Name -Recurse -Include *.ps1, *.txt + $InternalBinsNames = Get-ChildItem -Path $LocalMods"\bins" -Name -Recurse -Include *.exe # If path is URL if ($ExternalMods -like "http*") { @@ -22,6 +23,53 @@ function Test-ModsPath ($ModsPath, $WingetUpdatePath) { return $False } + #Check for bins, download if newer. Delete if not external + $ExternalBins = "$ModsPath/bins" + if ($WebResponse -match "bins/") { + $BinResponse = Invoke-WebRequest -Uri $ExternalBins -UseBasicParsing + # Collect the external list of href links + $BinLinks = $BinResponse.Links | Select-Object -ExpandProperty HREF + #If there's a directory path in the HREF:s, delete it (IIS) + $CleanBinLinks = $BinLinks -replace "/.*/","" + #Modify strings to HREF:s + $index = 0 + foreach ($Bin in $CleanBinLinks) { + if ($Bin) { + $CleanBinLinks[$index] = ' ' + $Bin + '' + } + $index++ + } + #Delete Local Bins that don't exist Externally + $index = 0 + $CleanLinks = $BinLinks -replace "/.*/","" + foreach ($Bin in $InternalBinsNames) { + If ($CleanLinks -notcontains "$Bin") { + Remove-Item $LocalMods\bins\$Bin -Force -ErrorAction SilentlyContinue | Out-Null + } + $index++ + } + $CleanBinLinks = $BinLinks -replace "/.*/","" + $Bin = "" + #Loop through all links + $wc = New-Object System.Net.WebClient + $CleanBinLinks | ForEach-Object { + #Check for .exe in listing/HREF:s in an index page pointing to .exe + if ($_ -like "*.exe") { + $dateExternalBin = "" + $dateLocalBin ="" + $wc.OpenRead("$ExternalBins/$_").Close() | Out-Null + $dateExternalBin = ([DateTime]$wc.ResponseHeaders['Last-Modified']).ToString("yyyy-MM-dd HH:mm:ss") + if (Test-Path -Path $LocalMods"\bins\"$_) { + $dateLocalBin = (Get-Item "$LocalMods\bins\$_").LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss") + } + if ($dateExternalBin -gt $dateLocalBin) { + $SaveBin = Join-Path -Path "$LocalMods\bins" -ChildPath $_ + Invoke-WebRequest -Uri "$ExternalBins/$_" -OutFile $SaveBin.Replace("%20"," ") -UseBasicParsing + } + } + } + } + # Collect the external list of href links $ModLinks = $WebResponse.Links | Select-Object -ExpandProperty HREF @@ -39,8 +87,7 @@ function Test-ModsPath ($ModsPath, $WingetUpdatePath) { #Delete Local Mods that don't exist Externally $DeletedMods = 0 - # 0 is the parent HTTP Directory - $index = 1 + $index = 0 $CleanLinks = $ModLinks -replace "/.*/","" foreach ($Mod in $InternalModsNames) { If ($CleanLinks -notcontains "$Mod") { @@ -49,7 +96,7 @@ function Test-ModsPath ($ModsPath, $WingetUpdatePath) { } $index++ } - + $CleanLinks = $ModLinks -replace "/.*/","" #Loop through all links @@ -87,6 +134,29 @@ function Test-ModsPath ($ModsPath, $WingetUpdatePath) { } # If path is UNC or local else { + $ExternalBins = "$ModsPath\bins" + if (Test-Path -Path $ExternalBins"\*.exe") { + $ExternalBinsNames = Get-ChildItem -Path $ExternalBins -Name -Recurse -Include *.exe + #Delete Local Bins that don't exist Externally + foreach ($Bin in $InternalBinsNames){ + If ($Bin -notin $ExternalBinsNames ){ + Remove-Item $LocalMods\bins\$Bin -Force -ErrorAction SilentlyContinue | Out-Null + } + } + #Copy newer external bins + foreach ($Bin in $ExternalBinsNames){ + $dateExternalBin = "" + $dateLocalBin ="" + if (Test-Path -Path $LocalMods"\bins\"$Bin) { + $dateLocalBin = (Get-Item "$LocalMods\bins\$Bin").LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss") + } + $dateExternalBin = (Get-Item "$ExternalBins\$Bin").LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss") + if ($dateExternalBin -gt $dateLocalBin) { + Copy-Item $ExternalBins\$Bin -Destination $LocalMods\bins\$Bin -Force -ErrorAction SilentlyContinue | Out-Null + } + } + } + if ((Test-Path -Path $ExternalMods"\*.ps1") -or (Test-Path -Path $ExternalMods"\*.txt")) { #Get File Names Externally $ExternalModsNames = Get-ChildItem -Path $ExternalMods -Name -Recurse -Include *.ps1, *.txt @@ -101,23 +171,17 @@ function Test-ModsPath ($ModsPath, $WingetUpdatePath) { } #Copy newer external mods - try { - foreach ($Mod in $ExternalModsNames){ - $dateExternalMod = "" - $dateLocalMod ="" - if (Test-Path -Path $LocalMods"\"$Mod) { - $dateLocalMod = (Get-Item "$LocalMods\$Mod").LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss") - } - $dateExternalMod = (Get-Item "$ExternalMods\$Mod").LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss") - if ($dateExternalMod -gt $dateLocalMod) { - Copy-Item $ExternalMods\$Mod -Destination $LocalMods\$Mod -Force -ErrorAction SilentlyContinue | Out-Null - $ModsUpdated++ - } + foreach ($Mod in $ExternalModsNames){ + $dateExternalMod = "" + $dateLocalMod ="" + if (Test-Path -Path $LocalMods"\"$Mod) { + $dateLocalMod = (Get-Item "$LocalMods\$Mod").LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss") + } + $dateExternalMod = (Get-Item "$ExternalMods\$Mod").LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss") + if ($dateExternalMod -gt $dateLocalMod) { + Copy-Item $ExternalMods\$Mod -Destination $LocalMods\$Mod -Force -ErrorAction SilentlyContinue | Out-Null + $ModsUpdated++ } - - } - catch { - $Script:ReachNoPath = $True } } else { diff --git a/Winget-AutoUpdate/mods/bins/README.md b/Winget-AutoUpdate/mods/bins/README.md new file mode 100644 index 00000000..57d9ff2c --- /dev/null +++ b/Winget-AutoUpdate/mods/bins/README.md @@ -0,0 +1,6 @@ +A Directory for placing useful **bins** (**MsiZap.exe** as a really good example) for running via the **Template Function**: + +#App to Run ($RunWait = $False if it shouldn't be waited for) +$Run = "" +$RunSwitch = "" +$RunWait = $True From a3cd22a8eb69d1bb997a486abf78c4d726a972a7 Mon Sep 17 00:00:00 2001 From: GAJ-san Date: Tue, 10 Jan 2023 11:33:02 +0100 Subject: [PATCH 76/86] WinGet MSIXBundle v1.3.2691 --- Winget-AutoUpdate-Install.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Winget-AutoUpdate-Install.ps1 b/Winget-AutoUpdate-Install.ps1 index 2c2a1e0f..3559112c 100644 --- a/Winget-AutoUpdate-Install.ps1 +++ b/Winget-AutoUpdate-Install.ps1 @@ -177,7 +177,7 @@ function Install-WinGet { #Check Package Install $TestWinGet = Get-AppxProvisionedPackage -Online | Where-Object { $_.DisplayName -eq "Microsoft.DesktopAppInstaller" } - If ([Version]$TestWinGet.Version -ge "2022.728.1939.0") { + If ([Version]$TestWinGet.Version -ge "2022.927.3.0") { Write-Host "WinGet is Installed" -ForegroundColor Green @@ -186,7 +186,7 @@ function Install-WinGet { #Download WinGet MSIXBundle Write-Host "-> Not installed. Downloading WinGet..." - $WinGetURL = "https://github.com/microsoft/winget-cli/releases/download/v1.3.2091/Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle" + $WinGetURL = "https://github.com/microsoft/winget-cli/releases/download/v1.3.2691/Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle" $WebClient = New-Object System.Net.WebClient $WebClient.DownloadFile($WinGetURL, "$PSScriptRoot\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle") From 4be19a4222fbeb5341acf263c88df0d022c1c07f Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Tue, 10 Jan 2023 23:53:15 +0100 Subject: [PATCH 77/86] Mods Template/Function Grant-ModsPath ($GrantPath) --- Winget-AutoUpdate/mods/_AppID-template.ps1 | 6 ++++++ Winget-AutoUpdate/mods/_Mods-Functions.ps1 | 19 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/Winget-AutoUpdate/mods/_AppID-template.ps1 b/Winget-AutoUpdate/mods/_AppID-template.ps1 index 5ceac134..7dda3817 100644 --- a/Winget-AutoUpdate/mods/_AppID-template.ps1 +++ b/Winget-AutoUpdate/mods/_AppID-template.ps1 @@ -44,6 +44,9 @@ $DelFile = @("") $CopyFile = "" $CopyTo = "" +#Grant "Modify" for directory/file to "Authenticated Users" - multiple: "dir1","dir2" +$GrantPath = @("") + <# FUNCTIONS #> . $PSScriptRoot\_Mods-Functions.ps1 @@ -75,5 +78,8 @@ if ($DelFile) { if ($CopyFile -and $CopyTo) { Copy-ModsFile $CopyFile $CopyTo } +if ($GrantPath) { + Grant-ModsPath $GrantPath +} <# EXTRAS #> diff --git a/Winget-AutoUpdate/mods/_Mods-Functions.ps1 b/Winget-AutoUpdate/mods/_Mods-Functions.ps1 index 705d3448..c76eb955 100644 --- a/Winget-AutoUpdate/mods/_Mods-Functions.ps1 +++ b/Winget-AutoUpdate/mods/_Mods-Functions.ps1 @@ -192,3 +192,22 @@ function Copy-ModsFile ($CopyFile, $CopyTo) { Return } +function Grant-ModsPath ($GrantPath) { + foreach ($path in $GrantPath) + { + if (Test-Path "$path") { + $NewAcl = Get-Acl -Path $path + $identity = New-Object System.Security.Principal.SecurityIdentifier S-1-5-11 + if ((Get-Item $path) -is [System.IO.DirectoryInfo]) { + $fileSystemAccessRuleArgumentList = $identity, 'Modify', 'ContainerInherit, ObjectInherit', 'InheritOnly', 'Allow' + } + else { + $fileSystemAccessRuleArgumentList = $identity, 'Modify', 'Allow' + } + $fileSystemAccessRule = New-Object -TypeName System.Security.AccessControl.FileSystemAccessRule -ArgumentList $fileSystemAccessRuleArgumentList + $NewAcl.SetAccessRule($fileSystemAccessRule) + Set-Acl -Path $path -AclObject $NewAcl + } + } + Return +} From 09db5c30335a69bcec23e9d0cc0d9059605844b5 Mon Sep 17 00:00:00 2001 From: GAJ-san Date: Wed, 11 Jan 2023 12:18:38 +0100 Subject: [PATCH 78/86] Fix --- Winget-AutoUpdate/functions/Test-ModsPath.ps1 | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Winget-AutoUpdate/functions/Test-ModsPath.ps1 b/Winget-AutoUpdate/functions/Test-ModsPath.ps1 index 6eed0629..29f0bdfd 100644 --- a/Winget-AutoUpdate/functions/Test-ModsPath.ps1 +++ b/Winget-AutoUpdate/functions/Test-ModsPath.ps1 @@ -126,7 +126,9 @@ function Test-ModsPath ($ModsPath, $WingetUpdatePath) { } } catch { - $Script:ReachNoPath = $True + if (($_ -like "*.ps1") -or ($_ -like "*.txt")) { + $Script:ReachNoPath = $True + } } } } From 2fe4baec0a3889589bc48ec1ee9adf0ca1e724ac Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Thu, 12 Jan 2023 21:16:03 +0100 Subject: [PATCH 79/86] LogRotation (max 3, max 1MB) --- .../functions/Invoke-LogRotation.ps1 | 79 +++++++++++++++++++ Winget-AutoUpdate/functions/Start-Init.ps1 | 11 +++ 2 files changed, 90 insertions(+) create mode 100644 Winget-AutoUpdate/functions/Invoke-LogRotation.ps1 diff --git a/Winget-AutoUpdate/functions/Invoke-LogRotation.ps1 b/Winget-AutoUpdate/functions/Invoke-LogRotation.ps1 new file mode 100644 index 00000000..ca33fdf7 --- /dev/null +++ b/Winget-AutoUpdate/functions/Invoke-LogRotation.ps1 @@ -0,0 +1,79 @@ +#Function rotate the logs + +function Invoke-LogRotation ($LogFile, $MaxLogFiles, $MaxLogSize) { + <# + .SYNOPSIS + Handle log rotation. + .DESCRIPTION + Invoke-LogRotation handles log rotation + .NOTES + Author: Øyvind Kallstad (Minimized and changed for WAU 12.01.2023 by Göran Axel Johannesson) + URL: https://www.powershellgallery.com/packages/Communary.Logger/1.1 + Date: 21.11.2014 + Version: 1.0 + #> + + try { + # get current size of log file + $currentSize = (Get-Item $LogFile).Length + + # get log name + $logFileName = Split-Path $LogFile -Leaf + $logFilePath = Split-Path $LogFile + $logFileNameWithoutExtension = [System.IO.Path]::GetFileNameWithoutExtension($logFileName) + $logFileNameExtension = [System.IO.Path]::GetExtension($logFileName) + + # if MaxLogFiles is 1 just keep the original one and let it grow + if (-not($MaxLogFiles -eq 1)) { + if ($currentSize -ge $MaxLogSize) { + + # construct name of archived log file + $newLogFileName = $logFileNameWithoutExtension + (Get-Date -Format 'yyyyMMddHHmmss').ToString() + $logFileNameExtension + + # copy old log file to new using the archived name constructed above + Copy-Item -Path $LogFile -Destination (Join-Path (Split-Path $LogFile) $newLogFileName) + + # Create a new log file + try { + Remove-Item -Path $LogFile -Force + New-Item -ItemType File -Path $LogFile -Force + #Set ACL for users on logfile + $NewAcl = Get-Acl -Path $LogFile + $identity = New-Object System.Security.Principal.SecurityIdentifier S-1-5-11 + $fileSystemRights = "Modify" + $type = "Allow" + $fileSystemAccessRuleArgumentList = $identity, $fileSystemRights, $type + $fileSystemAccessRule = New-Object -TypeName System.Security.AccessControl.FileSystemAccessRule -ArgumentList $fileSystemAccessRuleArgumentList + $NewAcl.SetAccessRule($fileSystemAccessRule) + Set-Acl -Path $LogFile -AclObject $NewAcl + } + catch { + Write-Log $_.Exception.Message + } + + # if MaxLogFiles is 0 don't delete any old archived log files + if (-not($MaxLogFiles -eq 0)) { + + # set filter to search for archived log files + $archivedLogFileFilter = $logFileNameWithoutExtension + '??????????????' + $logFileNameExtension + + # get archived log files + $oldLogFiles = Get-Item -Path "$(Join-Path -Path $logFilePath -ChildPath $archivedLogFileFilter)" + + if ([bool]$oldLogFiles) { + # compare found log files to MaxLogFiles parameter of the log object, and delete oldest until we are + # back to the correct number + if (($oldLogFiles.Count + 1) -gt $MaxLogFiles) { + [int]$numTooMany = (($oldLogFiles.Count) + 1) - $MaxLogFiles + $oldLogFiles | Sort-Object 'LastWriteTime' | Select-Object -First $numTooMany | Remove-Item + } + } + } + } + } + } + catch { + Write-Log "`n`n##################################################`n# CHECK FOR LOG ROTATION - $(Get-Date -Format (Get-culture).DateTimeFormat.ShortDatePattern)`n##################################################" + Write-Log $_.Exception.Message + } +} diff --git a/Winget-AutoUpdate/functions/Start-Init.ps1 b/Winget-AutoUpdate/functions/Start-Init.ps1 index 280ecbba..5de8bfc6 100644 --- a/Winget-AutoUpdate/functions/Start-Init.ps1 +++ b/Winget-AutoUpdate/functions/Start-Init.ps1 @@ -5,6 +5,12 @@ function Start-Init { #Config console output encoding [Console]::OutputEncoding = [System.Text.Encoding]::UTF8 + # Maximum number of log files to keep. Default is 3. Setting MaxLogFiles to 0 will keep all log files. + [int32] $MaxLogFiles = 3 + + # Maximum size of log file. + [int64] $MaxLogSize = 1048576 # in bytes, default is 1048576 = 1 MB + #Log Header $Log = "`n##################################################`n# CHECK FOR APP UPDATES - $(Get-Date -Format (Get-culture).DateTimeFormat.ShortDatePattern)`n##################################################" $Log | Write-host @@ -27,6 +33,11 @@ function Start-Init { Set-Acl -Path $LogFile -AclObject $NewAcl } + #LogRotation if System + if ($IsSystem) { + Invoke-LogRotation $LogFile $MaxLogFiles $MaxLogSize + } + #Log file $Log | out-file -filepath $LogFile -Append From bc7dd12a60c285b1257c12de782c7b98ef042590 Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Fri, 13 Jan 2023 03:33:00 +0100 Subject: [PATCH 80/86] Parameters, README, and fixes --- README.md | 10 ++++++++++ Winget-AutoUpdate-Install.ps1 | 14 ++++++++++++-- .../functions/Invoke-PostUpdateActions.ps1 | 10 ++++++++++ Winget-AutoUpdate/functions/Start-Init.ps1 | 16 ++++++++++++++-- 4 files changed, 46 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 0055ff0a..70fed0b7 100644 --- a/README.md +++ b/README.md @@ -73,6 +73,16 @@ You can run the `Winget-AutoUpdate-Install.ps1` script with parameters : **-Silent** Install Winget-AutoUpdate and prerequisites silently. +**-MaxLogFiles** +Specify number of allowed log files. +Default is 3 of 0-99: +Setting MaxLogFiles to 0 don't delete any old archived log files. +Setting it to 1 keeps the original one and just let it grow. + +**-MaxLogSize** +Specify the size of the log file in bytes before rotating. +Default is 1048576 = 1 MB + **-WingetUpdatePath** Specify Winget-AutoUpdate installation location. Default: `C:\ProgramData\Winget-AutoUpdate` (Recommended to leave default). diff --git a/Winget-AutoUpdate-Install.ps1 b/Winget-AutoUpdate-Install.ps1 index 3559112c..60876c05 100644 --- a/Winget-AutoUpdate-Install.ps1 +++ b/Winget-AutoUpdate-Install.ps1 @@ -10,6 +10,12 @@ https://github.com/Romanitho/Winget-AutoUpdate .PARAMETER Silent Install Winget-AutoUpdate and prerequisites silently +.PARAMETER MaxLogFiles +Specify number of allowed log files (Default is 3 of 0-99: Setting MaxLogFiles to 0 don't delete any old archived log files, 1 keeps the original one and just let it grow) + +.PARAMETER MaxLogSize +Specify the size of the log file in bytes before rotating. (Default is 1048576 = 1 MB) + .PARAMETER WingetUpdatePath Specify Winget-AutoUpdate installation localtion. Default: C:\ProgramData\Winget-AutoUpdate\ @@ -62,7 +68,7 @@ Install WAU with system and user context executions Configure WAU to bypass the Black/White list when run in user context .EXAMPLE -.\Winget-AutoUpdate-Install.ps1 -Silent -DoNotUpdate +.\Winget-AutoUpdate-Install.ps1 -Silent -DoNotUpdate -MaxLogFiles 4 -MaxLogSize 2097152 .EXAMPLE .\Winget-AutoUpdate-Install.ps1 -Silent -UseWhiteList @@ -100,7 +106,9 @@ param( [Parameter(Mandatory = $False)] [ValidateSet("Daily", "BiDaily", "Weekly", "BiWeekly", "Monthly", "Never")] [String] $UpdatesInterval = "Daily", [Parameter(Mandatory = $False)] [DateTime] $UpdatesAtTime = ("06am"), [Parameter(Mandatory = $False)] [Switch] $BypassListForUsers = $false, - [Parameter(Mandatory = $False)] [Switch] $InstallUserContext = $false + [Parameter(Mandatory = $False)] [Switch] $InstallUserContext = $false, + [Parameter(Mandatory = $False)] [ValidateRange(0,99)] [int32] $MaxLogFiles = 3, + [Parameter(Mandatory = $False)] [int64] $MaxLogSize = 1048576 # in bytes, default is 1048576 = 1 MB ) <# APP INFO #> @@ -337,6 +345,8 @@ function Install-WingetAutoUpdate { New-ItemProperty $regPath -Name WAU_NotificationLevel -Value $NotificationLevel -Force | Out-Null New-ItemProperty $regPath -Name WAU_UpdatePrerelease -Value 0 -PropertyType DWord -Force | Out-Null New-ItemProperty $regPath -Name WAU_PostUpdateActions -Value 0 -PropertyType DWord -Force | Out-Null + New-ItemProperty $regPath -Name WAU_MaxLogFiles -Value $MaxLogFiles -PropertyType DWord -Force | Out-Null + New-ItemProperty $regPath -Name WAU_MaxLogSize -Value $MaxLogSize -PropertyType DWord -Force | Out-Null if ($DisableWAUAutoUpdate) { New-ItemProperty $regPath -Name WAU_DisableAutoUpdate -Value 1 -Force | Out-Null } diff --git a/Winget-AutoUpdate/functions/Invoke-PostUpdateActions.ps1 b/Winget-AutoUpdate/functions/Invoke-PostUpdateActions.ps1 index 8c798249..e9eeb5d7 100644 --- a/Winget-AutoUpdate/functions/Invoke-PostUpdateActions.ps1 +++ b/Winget-AutoUpdate/functions/Invoke-PostUpdateActions.ps1 @@ -43,6 +43,16 @@ function Invoke-PostUpdateActions { Write-Log "-> Notification level setting was missing. Fixed with 'Full' option." } + #Set WAU_MaxLogFiles/WAU_MaxLogSize if not set + $MaxLogFiles = Get-ItemProperty $regPath -Name WAU_MaxLogFiles -ErrorAction SilentlyContinue + if (!$MaxLogFiles) { + New-ItemProperty $regPath -Name WAU_MaxLogFiles -Value 3 -PropertyType DWord -Force | Out-Null + New-ItemProperty $regPath -Name WAU_MaxLogSize -Value 1048576 -PropertyType DWord -Force | Out-Null + + #log + Write-Log "-> MaxLogFiles/MaxLogSize setting was missing. Fixed with 3/1048576 (in bytes, default is 1048576 = 1 MB)." + } + #Convert about.xml if exists (previous WAU versions) to reg $WAUAboutPath = "$WorkingDir\config\about.xml" if (test-path $WAUAboutPath) { diff --git a/Winget-AutoUpdate/functions/Start-Init.ps1 b/Winget-AutoUpdate/functions/Start-Init.ps1 index 5de8bfc6..6ea32720 100644 --- a/Winget-AutoUpdate/functions/Start-Init.ps1 +++ b/Winget-AutoUpdate/functions/Start-Init.ps1 @@ -6,10 +6,22 @@ function Start-Init { [Console]::OutputEncoding = [System.Text.Encoding]::UTF8 # Maximum number of log files to keep. Default is 3. Setting MaxLogFiles to 0 will keep all log files. - [int32] $MaxLogFiles = 3 + $MaxLogFiles = Get-ItemPropertyvalue -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate -Name "WAU_MaxLogFiles" -ErrorAction SilentlyContinue + if ($null = $MaxLogFiles) { + [int32] $MaxLogFiles = 3 + } + else { + [int32] $MaxLogFiles = $MaxLogFiles + } # Maximum size of log file. - [int64] $MaxLogSize = 1048576 # in bytes, default is 1048576 = 1 MB + $MaxLogSize = Get-ItemPropertyvalue -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate -Name "WAU_MaxLogSize" -ErrorAction SilentlyContinue + if (!$MaxLogSize) { + [int64] $MaxLogSize = 1048576 # in bytes, default is 1048576 = 1 MB + } + else { + [int64] $MaxLogSize = $MaxLogSize + } #Log Header $Log = "`n##################################################`n# CHECK FOR APP UPDATES - $(Get-Date -Format (Get-culture).DateTimeFormat.ShortDatePattern)`n##################################################" From 4d0fc6e445b27de0ba47f0560525f803624a8083 Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Fri, 13 Jan 2023 06:32:57 +0100 Subject: [PATCH 81/86] GPO and fixes for Max-Logfiles/LogSize --- Policies/WAU.admx | 14 ++++++++ Policies/en-US/WAU.adml | 23 ++++++++++++- Winget-AutoUpdate/Winget-Upgrade.ps1 | 34 ++++++++++++++++++- Winget-AutoUpdate/functions/Get-Policies.ps1 | 21 ++++++++++-- .../functions/Invoke-LogRotation.ps1 | 1 + Winget-AutoUpdate/functions/Start-Init.ps1 | 23 ------------- 6 files changed, 89 insertions(+), 27 deletions(-) diff --git a/Policies/WAU.admx b/Policies/WAU.admx index a5754b36..c4aa293c 100644 --- a/Policies/WAU.admx +++ b/Policies/WAU.admx @@ -319,5 +319,19 @@ + + + + + + + + + + + + + + diff --git a/Policies/en-US/WAU.adml b/Policies/en-US/WAU.adml index 4952d15e..f3a10c78 100644 --- a/Policies/en-US/WAU.adml +++ b/Policies/en-US/WAU.adml @@ -98,7 +98,7 @@ If this policy is not configured or disabled, Updates at Time: (06:00 AM).23:00 24:00 User context execution - This policy setting specifies whether to enable User context execution or not . + This policy setting specifies whether to enable User context execution or not. If this policy is disabled or not configured, the default is No. Enable Deskop Shortcut @@ -113,6 +113,17 @@ WAU - Open logs WAU - Web Help If this policy is disabled or not configured, the default is No. + Log: Number of allowed log files + If this policy is enabled, you can set a number of allowed log files: +Setting MaxLogFiles to 0 don't delete any old archived log files, 1 keeps the original one and just let it grow. +Default number is 3 (0-99) + +If this policy is disabled or not configured, the default number is used. + Log: Size of the log file in bytes before rotating + If this policy is enabled, you can set the size of the log file in bytes before rotating. +Default size is 1048576 = 1 MB + +If this policy is disabled or not configured, the default size is used. @@ -134,6 +145,16 @@ If this policy is disabled or not configured, the default is No. + + + + + + + + + + diff --git a/Winget-AutoUpdate/Winget-Upgrade.ps1 b/Winget-AutoUpdate/Winget-Upgrade.ps1 index c137ad6f..b3b01bc2 100644 --- a/Winget-AutoUpdate/Winget-Upgrade.ps1 +++ b/Winget-AutoUpdate/Winget-Upgrade.ps1 @@ -22,7 +22,39 @@ if ($IsSystem) { Write-Log "Running in System context" #Get and set Domain/Local Policies (GPO) - Get-Policies + $ChangedSettings = Get-Policies + + # Maximum number of log files to keep. Default is 3. Setting MaxLogFiles to 0 will keep all log files. + $MaxLogFiles = $WAUConfig.WAU_MaxLogFiles + if ($null -eq $MaxLogFiles) { + [int32] $MaxLogFiles = 3 + } + else { + [int32] $MaxLogFiles = $MaxLogFiles + } + + # Maximum size of log file. + $MaxLogSize = $WAUConfig.WAU_MaxLogSize + if (!$MaxLogSize) { + [int64] $MaxLogSize = 1048576 # in bytes, default is 1048576 = 1 MB + } + else { + [int64] $MaxLogSize = $MaxLogSize + } + + #LogRotation if System + $Rotate = Invoke-LogRotation $LogFile $MaxLogFiles $MaxLogSize + if ($Rotate) { + #Log Header + $Log = "`n##################################################`n# CHECK FOR APP UPDATES - $(Get-Date -Format (Get-culture).DateTimeFormat.ShortDatePattern)`n##################################################" + $Log | Write-host + $Log | out-file -filepath $LogFile -Append + Write-Log "Running in System context" + if ($null -ne $ChangedSettings) { + Write-Log "Activated WAU GPO Management detected, comparing..." + Write-Log "Changed settings: $ChangedSettings" "Yellow" + } + } #Run post update actions if necessary if run as System if (!($WAUConfig.WAU_PostUpdateActions -eq 0)) { diff --git a/Winget-AutoUpdate/functions/Get-Policies.ps1 b/Winget-AutoUpdate/functions/Get-Policies.ps1 index 258fb626..ff808f01 100644 --- a/Winget-AutoUpdate/functions/Get-Policies.ps1 +++ b/Winget-AutoUpdate/functions/Get-Policies.ps1 @@ -329,12 +329,29 @@ Function Get-Policies { $ChangedSettings++ } + if ($null -ne $($WAUPolicies.WAU_MaxLogFiles) -and ($($WAUPolicies.WAU_MaxLogFiles) -ne $($WAUConfig.WAU_MaxLogFiles))) { + New-ItemProperty $regPath -Name WAU_MaxLogFiles -Value $($WAUPolicies.WAU_MaxLogFiles.TrimEnd(" ", "\", "/")) -Force | Out-Null + $ChangedSettings++ + } + elseif ($null -eq $($WAUPolicies.WAU_MaxLogFiles) -and $($WAUConfig.WAU_MaxLogFiles) -ne 3) { + New-ItemProperty $regPath -Name WAU_MaxLogFiles -Value 3 -Force | Out-Null + $ChangedSettings++ + } + + if ($null -ne $($WAUPolicies.WAU_MaxLogSize) -and ($($WAUPolicies.WAU_MaxLogSize) -ne $($WAUConfig.WAU_MaxLogSize))) { + New-ItemProperty $regPath -Name WAU_MaxLogSize -Value $($WAUPolicies.WAU_MaxLogSize.TrimEnd(" ", "\", "/")) -Force | Out-Null + $ChangedSettings++ + } + elseif ($null -eq $($WAUPolicies.WAU_MaxLogSize) -and $($WAUConfig.WAU_MaxLogSize) -ne 1048576) { + New-ItemProperty $regPath -Name WAU_MaxLogSize -Value 1048576 -Force | Out-Null + $ChangedSettings++ + } + Write-Log "Changed settings: $ChangedSettings" "Yellow" #Get WAU Configurations after Policies change $Script:WAUConfig = Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate" } } - - Return + Return $ChangedSettings } diff --git a/Winget-AutoUpdate/functions/Invoke-LogRotation.ps1 b/Winget-AutoUpdate/functions/Invoke-LogRotation.ps1 index ca33fdf7..d63f8bba 100644 --- a/Winget-AutoUpdate/functions/Invoke-LogRotation.ps1 +++ b/Winget-AutoUpdate/functions/Invoke-LogRotation.ps1 @@ -69,6 +69,7 @@ function Invoke-LogRotation ($LogFile, $MaxLogFiles, $MaxLogSize) { } } } + Return $True } } } diff --git a/Winget-AutoUpdate/functions/Start-Init.ps1 b/Winget-AutoUpdate/functions/Start-Init.ps1 index 6ea32720..280ecbba 100644 --- a/Winget-AutoUpdate/functions/Start-Init.ps1 +++ b/Winget-AutoUpdate/functions/Start-Init.ps1 @@ -5,24 +5,6 @@ function Start-Init { #Config console output encoding [Console]::OutputEncoding = [System.Text.Encoding]::UTF8 - # Maximum number of log files to keep. Default is 3. Setting MaxLogFiles to 0 will keep all log files. - $MaxLogFiles = Get-ItemPropertyvalue -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate -Name "WAU_MaxLogFiles" -ErrorAction SilentlyContinue - if ($null = $MaxLogFiles) { - [int32] $MaxLogFiles = 3 - } - else { - [int32] $MaxLogFiles = $MaxLogFiles - } - - # Maximum size of log file. - $MaxLogSize = Get-ItemPropertyvalue -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate -Name "WAU_MaxLogSize" -ErrorAction SilentlyContinue - if (!$MaxLogSize) { - [int64] $MaxLogSize = 1048576 # in bytes, default is 1048576 = 1 MB - } - else { - [int64] $MaxLogSize = $MaxLogSize - } - #Log Header $Log = "`n##################################################`n# CHECK FOR APP UPDATES - $(Get-Date -Format (Get-culture).DateTimeFormat.ShortDatePattern)`n##################################################" $Log | Write-host @@ -45,11 +27,6 @@ function Start-Init { Set-Acl -Path $LogFile -AclObject $NewAcl } - #LogRotation if System - if ($IsSystem) { - Invoke-LogRotation $LogFile $MaxLogFiles $MaxLogSize - } - #Log file $Log | out-file -filepath $LogFile -Append From c4834c0053601bfee0890a18f948b3c764f66aff Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Fri, 13 Jan 2023 21:42:06 +0100 Subject: [PATCH 82/86] Optimized logging of Rotation/Policies --- Winget-AutoUpdate/Winget-Upgrade.ps1 | 17 ++++++++++++----- Winget-AutoUpdate/functions/Get-Policies.ps1 | 5 +---- .../functions/Invoke-LogRotation.ps1 | 7 +++---- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/Winget-AutoUpdate/Winget-Upgrade.ps1 b/Winget-AutoUpdate/Winget-Upgrade.ps1 index b3b01bc2..94f81241 100644 --- a/Winget-AutoUpdate/Winget-Upgrade.ps1 +++ b/Winget-AutoUpdate/Winget-Upgrade.ps1 @@ -22,7 +22,11 @@ if ($IsSystem) { Write-Log "Running in System context" #Get and set Domain/Local Policies (GPO) - $ChangedSettings = Get-Policies + $ActivateGPOManagement, $ChangedSettings = Get-Policies + if ($null -ne $ChangedSettings -and $ActivateGPOManagement) { + Write-Log "Activated WAU GPO Management detected, comparing..." + Write-Log "Changed settings: $ChangedSettings" "Yellow" + } # Maximum number of log files to keep. Default is 3. Setting MaxLogFiles to 0 will keep all log files. $MaxLogFiles = $WAUConfig.WAU_MaxLogFiles @@ -43,17 +47,20 @@ if ($IsSystem) { } #LogRotation if System - $Rotate = Invoke-LogRotation $LogFile $MaxLogFiles $MaxLogSize - if ($Rotate) { + $Exception, $Rotate = Invoke-LogRotation $LogFile $MaxLogFiles $MaxLogSize + if ($Exception -eq $True) { + Write-Log "An Exception occured during Log Rotation..." + } + if ($Rotate -eq $True) { #Log Header $Log = "`n##################################################`n# CHECK FOR APP UPDATES - $(Get-Date -Format (Get-culture).DateTimeFormat.ShortDatePattern)`n##################################################" - $Log | Write-host $Log | out-file -filepath $LogFile -Append Write-Log "Running in System context" - if ($null -ne $ChangedSettings) { + if ($null -ne $ChangedSettings -and $ActivateGPOManagement) { Write-Log "Activated WAU GPO Management detected, comparing..." Write-Log "Changed settings: $ChangedSettings" "Yellow" } + Write-Log "Max Log Size reached: $MaxLogSize bytes - Rotated Logs" } #Run post update actions if necessary if run as System diff --git a/Winget-AutoUpdate/functions/Get-Policies.ps1 b/Winget-AutoUpdate/functions/Get-Policies.ps1 index ff808f01..007593a5 100644 --- a/Winget-AutoUpdate/functions/Get-Policies.ps1 +++ b/Winget-AutoUpdate/functions/Get-Policies.ps1 @@ -6,7 +6,6 @@ Function Get-Policies { if ($WAUPolicies) { if ($($WAUPolicies.WAU_ActivateGPOManagement -eq 1)) { $ChangedSettings = 0 - Write-Log "Activated WAU GPO Management detected, comparing..." $regPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate" if ($null -ne $($WAUPolicies.WAU_BypassListForUsers) -and ($($WAUPolicies.WAU_BypassListForUsers) -ne $($WAUConfig.WAU_BypassListForUsers))) { New-ItemProperty $regPath -Name WAU_BypassListForUsers -Value $($WAUPolicies.WAU_BypassListForUsers) -PropertyType DWord -Force | Out-Null @@ -347,11 +346,9 @@ Function Get-Policies { $ChangedSettings++ } - Write-Log "Changed settings: $ChangedSettings" "Yellow" - #Get WAU Configurations after Policies change $Script:WAUConfig = Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate" } } - Return $ChangedSettings + Return $($WAUPolicies.WAU_ActivateGPOManagement), $ChangedSettings } diff --git a/Winget-AutoUpdate/functions/Invoke-LogRotation.ps1 b/Winget-AutoUpdate/functions/Invoke-LogRotation.ps1 index d63f8bba..66dd49e1 100644 --- a/Winget-AutoUpdate/functions/Invoke-LogRotation.ps1 +++ b/Winget-AutoUpdate/functions/Invoke-LogRotation.ps1 @@ -48,7 +48,7 @@ function Invoke-LogRotation ($LogFile, $MaxLogFiles, $MaxLogSize) { Set-Acl -Path $LogFile -AclObject $NewAcl } catch { - Write-Log $_.Exception.Message + Return $True, $False } # if MaxLogFiles is 0 don't delete any old archived log files @@ -69,12 +69,11 @@ function Invoke-LogRotation ($LogFile, $MaxLogFiles, $MaxLogSize) { } } } - Return $True + Return $False, $True } } } catch { - Write-Log "`n`n##################################################`n# CHECK FOR LOG ROTATION - $(Get-Date -Format (Get-culture).DateTimeFormat.ShortDatePattern)`n##################################################" - Write-Log $_.Exception.Message + Return $True, $False } } From 78a922a53842077acb61ebf482f19f57a9a77522 Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Fri, 13 Jan 2023 22:31:39 +0100 Subject: [PATCH 83/86] New GPO image (Log:) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 70fed0b7..5f8ac665 100644 --- a/README.md +++ b/README.md @@ -185,7 +185,7 @@ The **GPO ADMX/ADML** validated with: [Windows 10 - Validate ADMX for Ingestion](https://developer.vmware.com/samples/7115/windows-10---validate-admx-for-ingestion) Read more in the `README.md` under the directory **Policies**. -![image](https://user-images.githubusercontent.com/102996177/210157417-60e84023-088e-4299-9d76-b34bb0c5f088.png) +![image](https://user-images.githubusercontent.com/102996177/212422844-9366c6aa-ee7a-490f-97f0-bffb5ab146ab.png) ## Help In some cases, you need to "unblock" the `install.bat` file (Windows Defender SmartScreen). Right click, properties and unblock. Then, you'll be able to run it. From 328bf3e7561dc94f2f2b3ffc7e923454b64fede4 Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Sat, 14 Jan 2023 03:07:34 +0100 Subject: [PATCH 84/86] GPO log only if changed or not --- Winget-AutoUpdate/Winget-Upgrade.ps1 | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/Winget-AutoUpdate/Winget-Upgrade.ps1 b/Winget-AutoUpdate/Winget-Upgrade.ps1 index 94f81241..a201e0de 100644 --- a/Winget-AutoUpdate/Winget-Upgrade.ps1 +++ b/Winget-AutoUpdate/Winget-Upgrade.ps1 @@ -23,9 +23,14 @@ if ($IsSystem) { #Get and set Domain/Local Policies (GPO) $ActivateGPOManagement, $ChangedSettings = Get-Policies - if ($null -ne $ChangedSettings -and $ActivateGPOManagement) { + if ($ActivateGPOManagement) { Write-Log "Activated WAU GPO Management detected, comparing..." - Write-Log "Changed settings: $ChangedSettings" "Yellow" + if ($null -ne $ChangedSettings -and $ChangedSettings -ne 0) { + Write-Log "Changed settings detected and applied" "Yellow" + } + else { + Write-Log "No Changed settings detected" "Yellow" + } } # Maximum number of log files to keep. Default is 3. Setting MaxLogFiles to 0 will keep all log files. @@ -56,9 +61,14 @@ if ($IsSystem) { $Log = "`n##################################################`n# CHECK FOR APP UPDATES - $(Get-Date -Format (Get-culture).DateTimeFormat.ShortDatePattern)`n##################################################" $Log | out-file -filepath $LogFile -Append Write-Log "Running in System context" - if ($null -ne $ChangedSettings -and $ActivateGPOManagement) { + if ($ActivateGPOManagement) { Write-Log "Activated WAU GPO Management detected, comparing..." - Write-Log "Changed settings: $ChangedSettings" "Yellow" + if ($null -ne $ChangedSettings -and $ChangedSettings -ne 0) { + Write-Log "Changed settings detected and applied" "Yellow" + } + else { + Write-Log "No Changed settings detected" "Yellow" + } } Write-Log "Max Log Size reached: $MaxLogSize bytes - Rotated Logs" } From b37858f26b51562a951e7a3dd8082e21bb8d8179 Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Sun, 15 Jan 2023 14:52:30 +0100 Subject: [PATCH 85/86] No LB first in log if Log Rotating... --- Winget-AutoUpdate/Winget-Upgrade.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Winget-AutoUpdate/Winget-Upgrade.ps1 b/Winget-AutoUpdate/Winget-Upgrade.ps1 index a201e0de..a880d879 100644 --- a/Winget-AutoUpdate/Winget-Upgrade.ps1 +++ b/Winget-AutoUpdate/Winget-Upgrade.ps1 @@ -58,7 +58,7 @@ if ($IsSystem) { } if ($Rotate -eq $True) { #Log Header - $Log = "`n##################################################`n# CHECK FOR APP UPDATES - $(Get-Date -Format (Get-culture).DateTimeFormat.ShortDatePattern)`n##################################################" + $Log = "##################################################`n# CHECK FOR APP UPDATES - $(Get-Date -Format (Get-culture).DateTimeFormat.ShortDatePattern)`n##################################################" $Log | out-file -filepath $LogFile -Append Write-Log "Running in System context" if ($ActivateGPOManagement) { From 7dc71b5ea7d8436e2f537ef794f8c548d9997086 Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Mon, 16 Jan 2023 03:49:24 +0100 Subject: [PATCH 86/86] Sort winget_system_apps.txt --- Winget-AutoUpdate/functions/Get-WingetSystemApps.ps1 | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Winget-AutoUpdate/functions/Get-WingetSystemApps.ps1 b/Winget-AutoUpdate/functions/Get-WingetSystemApps.ps1 index 50aa6050..b682f62f 100644 --- a/Winget-AutoUpdate/functions/Get-WingetSystemApps.ps1 +++ b/Winget-AutoUpdate/functions/Get-WingetSystemApps.ps1 @@ -9,7 +9,10 @@ function Get-WingetSystemApps { #Convert json file to txt file with app ids $InstalledApps = get-content $jsonFile | ConvertFrom-Json - #Return app list + #Save app list Set-Content $InstalledApps.Sources.Packages.PackageIdentifier -Path $jsonFile + #Sort app list + Get-Content $jsonFile | Sort-Object | Set-Content $jsonFile + }