Script to add users to local server administrator group. This script requires "AddUsers.csv" input file which has the list of users that needs to be added to the local server admin group.
- if ( (Get-PSSnapin -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null ) {
- Add-PSSnapin Microsoft.SharePoint.Powershell
- }
- $scriptBase = split-path $SCRIPT:MyInvocation.MyCommand.Path -parent
- Set-Location $scriptBase
-
- Function AddUserToServerAdminGroup([String]$AdminMember, [String]$ServerName)
- {
-
- $ans = read-host "Do you want to add user $AdminMember to server $ServerName (y/n)? "
- if($ans -eq 'y')
- {
- write-host "Adding user " $AdminMember " to administrator group on server " $ServerName -fore yellow
-
- $AdminMember1 = $AdminMember.split("\")
- $AdminMember2 = $AdminMember1[0] + "/" + $AdminMember1[1]
-
- $GroupObj = [ADSI]"WinNT://$ServerName/Administrators"
- $GroupObj.Add("WinNT://$AdminMember2")
- write-host $AdminMember " added to the local administrator group on the server " $ServerName -fore green
- }
- else
- {
- write-host "User choose not to add user " $AdminMember " to the server " $ServerName " administrator group" -fore cyan
- }
-
- }
-
- write-host "Preparing to add users to the server administrator group" -fore magenta
- $csvfile = $scriptbase + "\" + "AddUsers.csv"
- import-csv $csvfile | where {
- AddUserToServerAdminGroup $_.AdminMember $_.ServerName
- }
- write-host "Users has been added to local administrators group" -fore green
-
- AddUserToServerAdminGroup