Wednesday, March 4, 2015

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

No comments:

Post a Comment