Skip to content

Instantly share code, notes, and snippets.

@toddb
Created August 10, 2011 20:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save toddb/1138113 to your computer and use it in GitHub Desktop.
Save toddb/1138113 to your computer and use it in GitHub Desktop.
Admin user setup in Sharepoint power psake
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