Bulk ADD Remove from Local Admin

Hi Readers,

Just sharing a quickly written script to add or remove user account or group from Local admin of servers.

Extract the script from below link, change the domain variable.

https://gallery.technet.microsoft.com/scriptcenter/Bulk-ADD-Remove-from-Local-c86f4f76

$domain = “domain”

Update the CSV file

Now you can use the

addtoLocaladmin.ps1 or removeLocaladmin.ps1 as per your requirement.

ADD Local ADmin

############################################################################## 
##                                                                                             
##           Author: Vikas Sukhija                                                         
##           Date: 03/03/2015                                                        
##           Description:- Add particular user/group to Localadmin of multiple servers   
##                                                                                         
############################################################################## 
 
$servers = import-csv .\localadmin.csv 
 
$domain = "domain" 
foreach($i in $servers){ 
 
$server$i.server 
$usgroup = $i.usgroup 
 
Write-host "Adding $usgroup to server $server" -foregroundcolor green 
 
$User = [ADSI]("WinNT://$domain/$usgroup"$Group = [ADSI]("WinNT://$server/Administrators"$Group.PSBase.Invoke("Add",$User.PSBase.Path) 
 
} 
##############################################################################
 Remove Local Admin
############################################################################## 
##                                                                                             
##           Author: Vikas Sukhija                                                         
##           Date: 03/03/2015                                                        
##           Description:- Remove particular user/group from Localadmin of multiple servers   
##                                                                                         
############################################################################## 
 
$servers = import-csv .\localadmin.csv 
 
$domain = "domain" 
foreach($i in $servers){ 
 
$server$i.server 
$usgroup = $i.usgroup 
 
Write-host "Removing $usgroup to server $server" -foregroundcolor green 
 
$User = [ADSI]("WinNT://$domain/$usgroup"$Group = [ADSI]("WinNT://$server/Administrators"$Group.PSBase.Invoke("Remove",$User.PSBase.Path) 
 
} 
##############################################################################

Regards

Sukhija Vikas

http://msexchange.me

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s