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

Basic JavaScript: Manipulate Arrays With unshift()

// Setupvar myArray = [["John", 23], ["dog", 3]];myArray.shift();// Only change code below this line.myArray.unshift( ["Paul",35]);

PowerShell: File Copying Operation

2/11/20 Update: Version 0.1.8 is available here: https://blog.kimconnect.com/powershell-file-copy-script-using-emcopy-vss-legacy/ Version 0.1.6 <#.Description File_Copy_Script Version: 0.16Purpose: this…

Using Telnet and PowerShell to Test SMTP Relay

PowerShell Method: Example of Failure: PS C:\> sendTestEmail '[email protected]' 'password' '[email protected]'Detected MX Record : ywpjf4z5siycosmh7uqymtuygcjehuc67wa6o4rq4k2a3g2aodma.mx-verification.google.comKnown…