SMA - PowerShell Script to Create Local User Account
Hello. I am needing assistance. I have a PowerShell script that creates a local Windows user account. It works great if run on the local Windows machine. But I try to push it out through our SMA as a Online KScript, it says it ran but the receiving windows device does not create the account. Event Viewer does not give a failure error that I can find and the SMA says everything ran successfully.
I have tried:
1) "Windows Run As" with both Local System and a Domain Admin credential.
2) Tried running the PowerShell script as an Online Shell Script, putting the script contents in and made sure to name it create.ps1
3) Tried running a batch file that runs the commandline to run the powershell script (Both are attached as dependancies). Batch file command line is: powershell -nologo -executionpolicy bypass -noprofile -file create.ps1
The following is the credential gutted version of the PowerShell script.
$username = "username"
$password = ConvertTo-SecureString "password" -AsPlainText -Force
New-LocalUser -Name "$username" -Password $password -FullName "$username" -Description ""
Any suggestions would be greatly appreciated on being able to get this script to push to remote machines via the SMA.
Thank you.
Answers (2)
Try running an online KScript using a .bat file with "net user username password /add".
I ran in to an issue trying to enable the local administrator account using a PowerShell script as well and i switched to .bat file that just run the following command and it worked right away "net user administrator /active:yes".
CategoryInfo : ObjectNotFound: (New-LocalUser:String) [], CommandNotFoundException+ FullyQualifiedErrorId : CommandNotFoundException - ryanreb 1 year ago
net user username password /add
net localgroup administrators username
NET USER username /COMMENT:"Comment Here" - ryanreb 1 year ago