From 4f2781b15406001465ba8cd5644ac0773f554d13 Mon Sep 17 00:00:00 2001
From: Manuel Thalmann <m@nuth.ch>
Date: Sat, 10 Aug 2024 15:21:13 +0200
Subject: [PATCH] Configure MS accounts properly

---
 scripts/Windows/OS/Install.ps1 | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/scripts/Windows/OS/Install.ps1 b/scripts/Windows/OS/Install.ps1
index 181130c8..7de42953 100644
--- a/scripts/Windows/OS/Install.ps1
+++ b/scripts/Windows/OS/Install.ps1
@@ -502,8 +502,12 @@ $null = New-Module {
                                 $user = Get-LocalUser $users[$currentUser];
                                 $msAccount = Get-UserConfig -UserName "$user" -Name "microsoftAccount";
 
+                                $adminGroup = @{
+                                    SID = [SecurityIdentifier]::new([WellKnownSidType]::BuiltinAdministratorsSid, $null);
+                                };
+
                                 Add-LocalGroupMember `
-                                    -SID ([SecurityIdentifier]::new([WellKnownSidType]::BuiltinAdministratorsSid, $null))`
+                                    @adminGroup `
                                     $user `
                                     -ErrorAction SilentlyContinue;
 
@@ -523,12 +527,23 @@ $null = New-Module {
                                     Restart-Intermediate -DefaultUser;
                                     return;
                                 } else {
+                                    $configure = {
+                                        Deploy-SoftwareAction -Action ([InstallerAction]::ConfigureUser);
+                                        Remove-LocalGroupMember -Member "$user" @adminGroup -ErrorAction SilentlyContinue;
+                                    }
+
                                     if ($msAccount) {
                                         if (-not (Test-Admin)) {
                                             Invoke-OneShot DisableUAC;
                                             Restart-Computer;
                                             return;
+                                        } else {
+                                            & $configure;
+                                            Clear-SetupRegistration;
+                                            Disable-OneShotListener;
                                         }
+                                    } else {
+                                        & $configure;
                                     }
                                 }