Created
August 10, 2011 20:21
-
-
Save toddb/1138113 to your computer and use it in GitHub Desktop.
Admin user setup in Sharepoint power psake
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Properties { | |
$site_owner = "domain\serviceaccount" | |
$ca_port = 3456 | |
} | |
Task AdminUser-Setup -Depends Solution-Setup -Description "Sets the current user as a farm admin on current computer" { | |
Add-PsSnapin Microsoft.SharePoint.PowerShell -ErrorAction "SilentlyContinue" | |
$whoami = [Security.Principal.WindowsIdentity]::GetCurrent().Name | |
Write-Host "You are logged in as $whoami" | |
if ($whoami -ne $site_owner) | |
{ | |
throw "Error: you must be logged in as $site_owner - please restart this console using this account." | |
} | |
$userToAdd = Read-Host -Prompt 'User to add to Farm Admin group <DOMAIN>\<USERNAME>' | |
$ca = "http://"+$env:COMPUTERNAME+":$ca_port" | |
Write-Host "Adding $userToAdd as farm admin to $ca" | |
$site = new-Object Microsoft.SharePoint.SPSite($ca) | |
$web = $site.RootWeb | |
$farmadmins = $web.SiteGroups["Farm Administrators"] | |
$farmadmins.AddUser($userToAdd,"",$userToAdd,"") | |
$web.Dispose() | |
$site.Dispose() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment