A service that simplifies device provisioning and setup for end users, enabling zero-touch deployment
I think, you need to restart the host to release the user account for deletion. If the account is locked, it cannot be deleted.
I have set InactiveThreshold to 7 days, but the Shared PC maintenance Schedules Task has deleted my Admin user folder on Windows 11 even though, the account was active within that 7 days. Strange. Will try the below PS script now:
$adminName = "LocalAdmin"
$adminPass = 'Pa$$word123'
invoke-expression "net user /add $adminName $adminPass"
$user = New-Object System.Security.Principal.NTAccount($adminName)
$sid = $user.Translate([System.Security.Principal.SecurityIdentifier])
$sid = $sid.Value;
New-Item -Path "HKLM:\Software\Microsoft\Windows\CurrentVersion\SharedPC\Exemptions\$sid" -Force
As per: https://learn.microsoft.com/en-us/windows/configuration/set-up-shared-or-guest-pc?tabs=intune