Skip to main content

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 HH🇲🇲ss")


 # Append content to log file

 Add-Content -Path $logFile -Value "$timestamp l$level] - $message"

}


Function Create-LocalAdmin {

   process {

     try {

       New-LocalUser "$username" -Password $password -FullName "$username" -Description "local admin" -ErrorAction stop -PasswordNeverExpires

       Write-Log -message "$username local user crated"


       # Add new user to administrator group

       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 "#########"

Write-Log -message "$env:COMPUTERNAME - Create local admin account"


Create-LocalAdmin


Write-Log -message "#########"

Hello!

 

While I can’t speak to the exact content of your script, I do want to point out that the latest Automox Agent version (version 1.0.40) has changed it’s install directory, which may impact how your antivirus or endpoint protection software monitors script executions.

 

Please follow our guide linked below to whitelist/allowlist the appropriate filepath for Automox to execute scripts.
https://help.automox.com/hc/en-us/articles/5352205452948-Change-Automox-Script-Execution-Location

It may also help to follow this guide to ensure the scripts aren’t being blocked by other means:
https://help.automox.com/hc/en-us/articles/5352186671252-Globally-Trust-listing-Automox-Through-EPP-Application-Control

Cheers,
Brandon


Hi @spragya this occurs because the cmdlet you are using, New-LocalUser, is not supported in 32-bit PowerShell on a 64-bit system 

 

A neat work-around you could use

$scriptblock = {
New-LocalUser "$username" -Password $password -FullName "$username" -Description "local admin" -ErrorAction stop -PasswordNeverExpires
}
$64bit = & "$env:SystemRoot\sysnative\WindowsPowerShell\v1.0\powershell.exe" -ExecutionPolicy Bypass -WindowStyle Hidden -NoProfile -NonInteractive -Command $scriptblock

 


Thank you Jack


Reply