Script to list out the SharePoint local server administrators
- 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
- $global:timerServiceName = "SharePoint 2010 Timer"
- $global:timerServiceInstanceName = "Microsoft SharePoint Foundation Timer"
- # Get the local farm instance
- [Microsoft.SharePoint.Administration.SPFarm]$farm = [Microsoft.SharePoint.Administration.SPFarm]::get_Local()
-
- Function GetServerAdministrators([Microsoft.SharePoint.Administration.SPFarm]$farm)
- {
-
- write-host ""
- write-host "Preparing to collect SP server administrator details" -fore magenta
-
- $output = $scriptbase + "\" + "ServerAdminDetails.csv"
- "ServerName" + "," + "AdminMember" | Out-File -Encoding Default -FilePath $Output;
-
- foreach($server in $farm.Servers)
- {
- foreach($instance in $server.ServiceInstances)
- {
-
- if($instance.TypeName -eq $timerServiceInstanceName)
- {
- [string]$serverName = $server.Name
- write-host "Collecting administrator details for the server " $servername -fore yellow
- $admins = invoke-command {net localgroup administrators | where {$_ -AND $_ -notmatch "command completed successfully"} | select -skip 4} -computer $serverName
- foreach($admin in $admins)
- {
- write-host $admin " is member of administrator group in server " $serverName -fore cyan
- $serverName + "," + $admin | Out-File -Encoding Default -Append -FilePath $Output;
- }
- write-host "Administrator details for the server " $serverName " has been collected" -fore green
- }
- }
- }
- Write-host "Administrator details collected for all the SP servers in the farm" -fore green
-
- }
-
- GetServerAdministrators