Win32App deploy not working

Copper Contributor

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

3 Replies
Thank you very much for the answer, the challenge for me here is to do the work using win32app in intune. Sadly in your blog is only the script version, which I should not use.
Any particular reason for doing it through a Win32 app? You can use the CSP to configure it as well. Sure it will report a remediation error, but it works nonetheless.