Hi Team ,
Â
We have below script which we are using to create LOcal admin account in windows:
It is working fine manually, but not through AUTOMOX Worklets.
Â
Kindly suggest.
Â
$username = "username" Â # Administrator is built-in name
$password = ConvertTo-SecureString "Password here" -AsPlainText -Force
Function Write-Log {
 param(
   ÂParameter(Mandatory = $true)] string] $message,
      /ValidateSet("INFO","WARN","ERROR")]    )string] $level = "INFO"  )  # Create timestamp  $timestamp = (Get-Date).toString("yyyy/MM/dd HHss")  Add-Content -Path $logFile -Value "$timestamp l$level] - $message" }   process {    try {     New-LocalUser "$username" -Password $password -FullName "$username" -Description "local admin" -ErrorAction stop -PasswordNeverExpires     Write-Log -message "$username local user crated"     Add-LocalGroupMember -Group "Administrators" -Member "$username" -ErrorAction stop     Write-Log -message "$username added to the local administrator group"    }catch{     Write-log -message "Creating local account failed" -level "ERROR"    }   }   } Write-Log -message "$env:COMPUTERNAME - Create local admin account"
 # Append content to log file
Function Create-LocalAdmin {
    # Add new user to administrator group
Write-Log -message "#########"
Create-LocalAdmin
Write-Log -message "#########"