Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 9th, 2012  |  syntax: None  |  size: 0.95 KB  |  hits: 11  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Properties {
  2.   $site_owner = "domain\serviceaccount"
  3.   $ca_port = 3456
  4. }
  5.  
  6. Task AdminUser-Setup -Depends Solution-Setup -Description "Sets the current user as a farm admin on current computer" {
  7.    Add-PsSnapin Microsoft.SharePoint.PowerShell -ErrorAction "SilentlyContinue"
  8.    $whoami = [Security.Principal.WindowsIdentity]::GetCurrent().Name
  9.    Write-Host "You are logged in as $whoami"
  10.    
  11.    if ($whoami -ne $site_owner)
  12.    {
  13.      throw "Error: you must be logged in as $site_owner - please restart this console using this account."
  14.    }
  15.    $userToAdd =  Read-Host -Prompt 'User to add to Farm Admin group <DOMAIN>\<USERNAME>'
  16.  
  17.    $ca = "http://"+$env:COMPUTERNAME+":$ca_port"
  18.    Write-Host "Adding $userToAdd as farm admin to $ca"
  19.    $site = new-Object Microsoft.SharePoint.SPSite($ca)
  20.    $web = $site.RootWeb    
  21.    $farmadmins = $web.SiteGroups["Farm Administrators"]
  22.    $farmadmins.AddUser($userToAdd,"",$userToAdd,"")
  23.    $web.Dispose()
  24.    $site.Dispose()
  25. }