Posted On February 7, 2020

PowerShell: Add Accounts into Local Administrators Group

kimconnect 0 comments
blog.KimConnect.com >> Codes , Windows >> PowerShell: Add Accounts into Local Administrators Group
# addAccountToLocalAdmins.ps1
# Requires: PowerShell Version 4.0+

$accountToAdd='ServerAdmins'
$groupName="Administrators"
$servers=@(
"CONCU1",
'CONCU2',
'CONCU100',
'CONCU80665',
'CONCU6547354',
'CONWHAT989',
'CONCU3'
)

$servers|%{
$session=new-pssession $_
invoke-command -session $session -scriptblock{
param($principleName,$groupName)
write-host "Adding $principleName into $groupName";
Add-LocalGroupMember -Group $groupName -Member $principleName;
write-host "$env:computername group $groupName now has these members:`r`n";
get-localgroupmember $groupName|ft -autosize
} -args $accountToAdd,$groupName
remove-pssession $session
}

sample output

ObjectClass Name                          PrincipalSource
----------- ---- ---------------
User SERVERX\ServerAdmins Local
User SERVERX\Johnito Local

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Post

PowerShell: Remove an A-Host Record within Active Directory Integrated DNS Domain

Warning: this code is NOT 'production ready'. Please review and test on DEV environments carefully…

WordPress NextGen Gallery Plugin Error

Error Message: Failed to load plugin url: /bitnami/wordpress/wp-content/plugins/nextgen-gallery/products/photocrati_nextgen/modules/attach_to_post/static/ngg_attach_to_post_tinymce_plugin.js?ver=3.17 Resolution: Although the root cause hasn't been…

PowerShell: Update Local Windows Machine

This script is meant to be ran on a local computer. To update remote machines,…
Other project: DragonCoin.com