*servers.txt is all your servers name going to add in.
$serverList = 'C:\servers.txt'
$names = get-content $serverList
$Admins = [ADSI] 'WinNT://
foreach ($name in $names)
{
Write-Host 'Adding Admins to' $name
#get the local group
$localAdminGroup = [ADSI]("WinNT://$name/Administrators")
#add the global group to the local group
$localAdminGroup.Add($Admins.PSBase.Path)
}
This script have a bug , that is once the group is available at the target server then will stop and give error :). ha ha , either u write the if statement to catch it or just make sure all your server is not exist the name you want to add . ha ha..is simple, but is very fun for me to find out it.
No comments:
Post a Comment