Jump to content
andy0609

Create a local admin account

Recommended Posts

I use this when I am onboarding a new client. Computers have been there and most people don't know/have their own admin password

Quote

 

$Username = "ADMIN-USERNAME-HERE"
$Password = "ADMIN-PASSWORD-HERE"

$group = "Administrators"

$adsi = [ADSI]"WinNT://$env:COMPUTERNAME"
$existing = $adsi.Children | where {$_.SchemaClassName -eq 'user' -and $_.Name -eq $Username }

if ($existing -eq $null) {

    Write-Host "Creating new local user $Username."
    & NET USER $Username $Password /add /y /expires:never
    
    Write-Host "Adding local user $Username to $group."
    & NET LOCALGROUP $group $Username /add

}
else {
    Write-Host "Setting password for existing local user $Username."
    $existing.SetPassword($Password)
}

Write-Host "Ensuring password for $Username never expires."
& WMIC USERACCOUNT WHERE "Name='$Username'" SET PasswordExpires=FALSE

 

 

Share this post


Link to post
Share on other sites

Thanks for sharing this, this would be even more awesome when we will support script variables to be entered at runtime.

-Paul

Share this post


Link to post
Share on other sites
On 5.4.2017 at 6:11 AM, andy0609 said:

I use this when I am onboarding a new client. Computers have been there and most people don't know/have their own admin password

 

Very handy - thanks for sharing!

Share this post


Link to post
Share on other sites
On 4/5/2017 at 3:33 AM, Paul said:

Thanks for sharing this, this would be even more awesome when we will support script variables to be entered at runtime.

-Paul

Is this available yet?

Share this post


Link to post
Share on other sites
On 4/5/2017 at 12:11 AM, andy0609 said:

I use this when I am onboarding a new client. Computers have been there and most people don't know/have their own admin password

 

Thanks for this. I can see it coming in handy. I'll definitely be bookmarking this page. 

Share this post


Link to post
Share on other sites
On 4/4/2017 at 9:11 PM, andy0609 said:

I use this when I am onboarding a new client. Computers have been there and most people don't know/have their own admin password

 

I am trying to use this script, but I keep getting the error

"Where-Object : Cannot process command because of one or more missing mandatory parameters: FilterScript. At C:\Program Files\Pulseway\automation_dc45fa75_cbe2_4a45_bfb5_18a9f9945795.ps 1:16 char:4 + } ? <<<< + CategoryInfo : InvalidArgument: (:) [Where-Object], ParameterBi ndingException + FullyQualifiedErrorId : MissingMandatoryParameter,Microsoft.PowerShell.C ommands.WhereObjectCommand"

 

Ideas?

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...