Tuesday, 25 March 2014

Add/Update Site Collection Administrator using PowerShell



  
Add-PSSnapin "Microsoft.SharePoint.PowerShell" 

 $collabWebs =  Get-SPWebApplication "http://localdevrtm" | Get-

SPSite -Limit All | where 

{$_.Url like "http://test.dev.local/sites/qw*"}
  
 $collabWebs | % { $web = $_
    
  if($web.IsRootWeb)

  {

   $NewAdmin = $web.EnsureUser("devuser\manju")

   $NewAdmin .IsSiteAdmin = $true

   $NewAdmin .Update()
  
  }

    }





# collabwebs object contains list of Site urls from WebApp http://localdevrtm which starts with  http://..../sites/qw*

#$_ is the Current object

# Url is property which has list of Sitecollections

# % is for looping through list of urls which we got from $collabwebs
   
# check if $web is a root web if so go ahead and add the SiteCollection Admininstrator


PowerShell script to Update SiteCollection Admin  for Single SiteCollection



cls
  
Add-PSSnapin "Microsoft.SharePoint.PowerShell" 

 $site =  Get-SPSite -Identity "http://test.dev.local/sites/qw"
  
 $web=$site.RootWeb;

  if($web.IsRootWeb)

  {

   $NewAdmin = $web.EnsureUser("devuser\manju")

   $NewAdmin .IsSiteAdmin = $true

   $NewAdmin .Update()
    
   Write-Host " Site Collection Admin Successfully Added"
  
  }

 else
{
 Write-Host " Site Collection Admin is not updated "
}
    


OutPut:


No comments:

Post a Comment