locked
Create Local admin account remotly for list of machines RRS feed

  • Question

  • Dears

    how can i use ADSI function command to create local account then add it to administrators group

    for the list of machines remotely, i used the below script to delete local account is it possible to modify it

    to create then add to administrators group.

    Function Delete-User { #Deletes a local user account on target computer Param ( [string]$computer, [string]$user ) [ADSI]$server = "WinNT://$computer" $server.delete("user",$user) } Import-Csv -path C:\temp\Accounts.csv | %{ Delete-User -computer $_.server -user $_.user }


    Mohamed Soliman System Administrator +971552997724

    Thursday, December 27, 2018 10:46 AM

All replies

  • Find-Module localaccount | Install-Module

    This module provides all commands needed to remotely manage local accounts and groups.


    \_(ツ)_/

    Thursday, December 27, 2018 11:04 AM
  • Hi,

    Thanks for your question.

    Import-Csv -path C:\temp\Accounts.csv |%{New-LocalUser -Name $_.user -password -Computername $_.server| Add-LocalGroupMember -GroupName "Administrators" -Computername $_.server}

    Also, you can use the module in the link below with invoke-command cmdlet.

    https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.localaccounts/?view=powershell-5.1

    Best Regards,

    Lee


    Just do it.

    Friday, December 28, 2018 7:12 AM
  • Thanks Lee,

    your suggested command above means to merge to my first command? if yes where i have to write the password.


    Mohamed Soliman System Administrator +971552997724

    Sunday, December 30, 2018 7:39 AM
  • Hi,

    Thanks for your reply.

    You can write the password in the CSV file or behind the "-password" parameter.

    -password $_.password

    or

    -password "123"

    Best Regards,

    Lee


    Just do it.

    Monday, December 31, 2018 8:53 AM