Showing posts with label Site owner change using Powershell. Show all posts
Showing posts with label Site owner change using Powershell. Show all posts

Wednesday, 29 January 2014

Change Site Author /Site Owner using PowerShell


PowerShell Script to change SiteOwner


Cls

# Add the PowerShell Snapin
      
       if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null)
       {
           Add-PSSnapin "Microsoft.SharePoint.PowerShell"
       }

#Get the url of the website to change the Site Owner

$Url = "https://abc.com/sites/release/"

# New Author Name to be Changed

$Author= "Local\Soreddy" 

 # Note : Get the Userlogin name from UserProfile in Central Admin

try{

    $Web = Get-SPWeb $Url

    $Web.AllowUnsafeUpdates=$true

    Write-Host "Current Author of site $Url" $Web.Author.DisplayName

    $NewAuthor = $Web.EnsureUser($Author);

    $Web.Author = $NewAuthor;

    $Web.Update();

    $Web.AllowUnsafeUpdates=$false

    Write-Host "New Author of site $Url" $Web.Author.DisplayName

}

catch{

    $ErrorMessage =$_.Excepction.Message

}