Forum Discussion

PhillipeCDL's avatar
PhillipeCDL
Copper Contributor
Aug 11, 2023

Win32App deploy not working

Hey everyone, 

 

I am trying to create an Admin user with a powershell script using win32app, but it keeps failing.

 

this is my code:

 

# LocalUser Name
$Name = "Admin"

# Import System.Web assembly
Add-Type -AssemblyName System.Web

# Generate random password. Initial parameters: the password length (20) and the minimum number of special characters(5).
$UserPassword = [System.Web.Security.Membership]::GeneratePassword(20,5)

# Convert the plain text password to a SecureString
$SecurePassword = ConvertTo-SecureString $UserPassword -AsPlainText -Force

# Create the new local user with the SecureString password
New-LocalUser -Name $Name -Password $SecurePassword -Description "Local User" -FullName $Name

# Get the Administrators group
$AdminGroup = Get-LocalGroup | Where-Object {$_.SID -like 'S-1-5-32-544'}

# Add the new local user to the Administrators group
Add-LocalGroupMember -Group $AdminGroup.Name -Member $Name

Resources