Onlangs kwamen we in een situatie waarbij bepaalde gebruikers buiten kantoortijden software moesten kunnen installeren vanwege werkzaamheden in het buitenland. Deze medewerkers hadden daarvoor tijdelijk administratorrechten nodig, maar mochten om veiligheidsredenen geen permanente local admin-rechten hebben op hun eigen endpoint.
Omdat LAPS in deze situatie geen werkbare oplossing bood, zijn we op zoek gegaan naar een alternatief dat zowel veilig als gebruiksvriendelijk is – zonder dat wij midden in de nacht gebeld hoeven te worden.
Onze oplossing: we genereren een tijdelijk local admin-account met een wachtwoord dat veilig wordt opgeslagen in het Windows-register. Zo kan de gebruiker zelfstandig aan de slag op het juiste moment, zonder permanente rechten, en zonder extra belasting voor IT.
Onderstaand script wordt ingezet voor het creëren van een tijdelijk local admin-account. Dit account wordt automatisch aangemaakt op basis van het serienummer van het device in combinatie met de klantnaam.
Het wachtwoord is een combinatie van deze elementen, aangevuld met een automatisch gegenereerd gedeelte voor extra complexiteit. Voor noodgevallen wordt het wachtwoord versleuteld opgeslagen in het Windows-register, zodat het op verzoek kan worden opgevraagd – zonder dat hiervoor handmatige tussenkomst van IT nodig is.
Deze aanpak zorgt voor:
Snelle ondersteuning, zonder dat we ’s nachts uit bed gebeld worden.
Tijdelijke beheertoegang, alleen wanneer nodig;
Minimale risico’s, doordat het account niet standaard actief is;
param ([switch]$Silent) <# .NOTES =========================================================================== Created on: 2025-07-10 Created by: Vincent van Unen Organization: Xiphos SCALE IT Filename: SCA-CreateLocalAdminAccount.ps1 Version: 0.1 =========================================================================== .DESCRIPTION Crete a local admin account on the device with a secure password. – The password is stored in the registry under HKLM:\SOFTWARE\CustomerName – The password is generated with a combination of uppercase, lowercase, digits, and special characters #> #region Changelog ################################################################################# # Version History $ScriptAuthor = “Vincent van Unen” $ScripVersion = “0.1” $ScriptChangeDate = “2025-07-10” $ScriptCurrentUser = $env:UserName $ScriptRunningDevice = $env:computername $Getcurrentdate = get-date -Format yyyy-MM-dd $GetpublicIP = (Invoke-WebRequest -uri “http://ifconfig.me/ip”).Content $GetprivateIP = (Get-NetIPAddress | Where-Object {$_.AddressState -eq “Preferred” -and $_.ValidLifetime -lt “24:00:00”}).IPAddress $logname = “SCA-CreateLocalAdminAccount” # Naam van het logbestand $customername = “Customername” # Naam van de klant of organisatie <# Change Log [0.1] 2025-07-10 – First Setup of script #> #endregion Changelog #Script functions [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 # Set Security protocol naar TLS12 #Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope LocalMachine -Force -WarningAction Ignore -ErrorAction Ignore Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope Process -Force -WarningAction Ignore -ErrorAction Ignore Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope CurrentUser -Force -WarningAction Ignore -ErrorAction Ignore $MaximumFunctionCount = 16384 # deze setting wordt gezet voor MS Graph $MaximumVariableCount = 16384 # deze setting wordt gezet voor MS Graph # Checking & Creatiglog en temp directory $XIPMyModuleDir1 = “C:\temp” # Check of c:\temp dir bestaat mocht deze niet bestaan dan word deze aangemaakt if(!(Test-Path -Path $XIPMyModuleDir1 )){ New-Item -ItemType directory -Path $XIPMyModuleDir1 } $XIPMyModuleDir2 = “C:\tmp” # Check of c:\tmp dir bestaat mocht deze niet bestaan dan word deze aangemaakt if(!(Test-Path -Path $XIPMyModuleDir2 )){ New-Item -ItemType directory -Path $XIPMyModuleDir2 } $XIPMyModuleDir3 = “C:\log” # Check of c:\log dir bestaat mocht deze niet bestaan dan word deze aangemaakt if(!(Test-Path -Path $XIPMyModuleDir3 )){ New-Item -ItemType directory -Path $XIPMyModuleDir3 } cls Function WriteToLogFile{ [CmdletBinding()] Param( [Parameter(Mandatory=$False)] [ValidateSet(“INFO”,”WARN”,”ERROR”,”FATAL”,”DEBUG”)] [String] $Level = “INFO”, [Parameter(Mandatory=$True)] [string] $Message, [Parameter(Mandatory=$False)] [string] $logfile = “$XIPMyModuleDir3\$logname $Getcurrentdate.log” ) if ($Message -eq ” “){ Add-Content $logfile -Value ” ” -ErrorAction SilentlyContinue }else{ $Date = (Get-Date).ToUniversalTime().ToString(‘yyyy-MM-dd HH:mm:ss.fff’) Add-Content $logfile -Value “[$date] [$Level] $Message” -ErrorAction SilentlyContinue } } WriteToLogFile -Message “Curent Date = $Getcurrentdate” WriteToLogFile -Message “Script Autor = $ScriptAuthor” WriteToLogFile -Message “Script Version = $ScripVersion” WriteToLogFile -Message “Script ChangeDate = $ScriptChangeDate” WriteToLogFile -Message “Current User Running this script = $ScriptCurrentUser” WriteToLogFile -Message “Current Device Running this script = $ScriptRunningDevice” WriteToLogFile -Message “Current Public ip = $GetpublicIP” WriteToLogFile -Message “Current Private IP = $GetprivateIP” $TranscriptFile = “$XIPMyModuleDir3\$Getcurrentdate _$logname _Transcript.log” Start-Transcript -Path $TranscriptFile # Logbestand pad instellen $LogDir = $XIPMyModuleDir3 $LogFile = $logname + ” ” + $Getcurrentdate + “.log” # Controleer of logmap bestaat, zo niet maak deze aan $LogPath = Join-Path -Path $LogDir -ChildPath $LogFile if (-not (Test-Path -Path $LogDir)) { New-Item -Path $LogDir -ItemType Directory -Force | Out-Null } function Write-Log { param ( [string]$Message ) $timestamp = Get-Date -Format “yyyy-MM-dd HH:mm:ss” Add-Content -Path $LogPath -Value “$timestamp – $Message” } Write-Log “=== Script gestart ===” try { # Serienummer ophalen $SerialNumber = (Get-WmiObject -Class Win32_BIOS).SerialNumber.Trim() Write-Log “Serienummer opgehaald: $SerialNumber” # Gebruikersnaam en wachtwoord genereren #$InstallDate = Get-Date -Format “yyyyMM” $Username = “$customername$SerialNumber” $AVT=”$customername” # Genereer veilig wachtwoord van minimaal 14 tekens en 3 soorten tekens $Upper = Get-Random -InputObject ([char[]]”ABCDEFGHIJKLMNOPQRSTUVWXYZ”) $Lower = Get-Random -InputObject ([char[]]”abcdefghijklmnopqrstuvwxyz”) $Digit = Get-Random -InputObject ([char[]]”0123456789″) $Special = Get-Random -InputObject @(‘!’, ‘@’, ‘#’, ‘$’, ‘%’, ‘^’, ‘&’, ‘*’, ‘(‘, ‘)’, ‘_’, ‘+’) $Rest = -join ((1..10) | ForEach-Object { Get-Random -InputObject ([char[]]”abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()_+”) }) $PasswordPlain = “$AVT$Upper$Lower$Digit$Special$Rest” $SecurePassword = ConvertTo-SecureString $PasswordPlain -AsPlainText -Force Write-Log “Wachtwoord gegenereerd.” # Wachtwoord opslaan in register $RegPath = “HKLM:\SOFTWARE\$customername” # Controleer of gebruiker al bestaat if (-not (Get-LocalUser -Name $Username -ErrorAction SilentlyContinue)) { New-LocalUser -Name $Username -Password $SecurePassword -FullName $Username -Description “Local Admin created via Intune” Write-Log “Gebruiker $Username aangemaakt.” Add-LocalGroupMember -Group “Administrators” -Member $Username Write-Log “Gebruiker $Username toegevoegd aan Administrators groep.” try { if (-not (Test-Path $RegPath)) { New-Item -Path $RegPath -Force | Out-Null Write-Log “Registerpad $RegPath aangemaakt.” } Set-ItemProperty -Path $RegPath -Name “localpw” -Value $PasswordPlain Write-Log “Wachtwoord opgeslagen in register.” } catch { Write-Log “Fout bij registerbewerking: $_” throw } } else { Write-Log “Gebruiker $Username bestaat al.” } Write-Log “Script succesvol afgerond.” Write-Output “Script succesvol uitgevoerd. Zie logbestand op $LogPath voor details.” } catch { Write-Log “FOUT: $_” Write-Error “Er is een fout opgetreden. Zie logbestand op $LogPath voor details.” } finally { Write-Log “=== Script beëindigd ===” } Stop-Transcript Copy-Item -Path $TranscriptFile -Destination “C:\ProgramData\Microsoft\IntuneManagementExtension\Logs” remove-item -Path $TranscriptFile -Force -ErrorAction SilentlyContinue remove-item -Path $LogPath -Force -ErrorAction SilentlyContinue |
Dit scipt is in Intune gekoppeld onder Scirpt en Remediations – Platform scripts

