Wednesday, 29 January 2014

Change Site Author /Site Owner using PowerShell

PowerShell Script to change SiteOwner


# 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 = ""

# New Author Name to be Changed

$Author= "Local\Soreddy" 

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


    $Web = Get-SPWeb $Url


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

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

    $Web.Author = $NewAuthor;



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



    $ErrorMessage =$_.Excepction.Message


Sunday, 19 January 2014

“Sorry, something went wrong” error message when users try to Upload document to the Document Library.

This Error message occurs in a document library while uploading the document beacouse,

the document could have associated with custom properites,

Click on Properties of document for which u want to upload the document library.

If you are able to see any custom tab , remove all the custom properties and try to upload again ,

Hope it should fix the issue.

Tuesday, 7 January 2014

Delete Custom Master Page using PowerShell


 # Add the Powershell snapin,
       if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null)
           Add-PSSnapin "Microsoft.SharePoint.PowerShell"

# Get the Name of the Website where we need to delete the Custom Master Page from Master Page Library.

        $web=Get-SPWeb "http://sedwdevrtm:22222/sites/Learning/"

 # Note assumption that seatle_manju.master is not a default master page , if its a default master then we can't delete it


        Write-Host "Current library is " $lib



Add Existing List webpart to a Page using PowerShell

# Clear the Screen


  # Add the Powershell Ps Snap-in
       if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null)
           Add-PSSnapin "Microsoft.SharePoint.PowerShell"

   # Create  variable to check for existance of same list webpart in the page , if i=0  means webpart is not existing

    # Get the website url

              $web= Get-SPWeb -Identity "http://sedwdevrtm:22222/sites/demo1/"
    # Mention the List name that needs to be added in the page

              $listName = "Test2"
    # Specify the page url webpart that needs to be added

              $pageUrl= "http://sedwdevrtm:22222/sites/demo1/SitePages/Home.aspx"


    # Create  New object of type XsltListViewWebPart

        $webpart = New-Object Microsoft.SharePoint.WebPartPages.XsltListViewWebPart
        #Assign the Webart Listid with Current List Id i.e.. "list id that needs to be added in the page"

         $webpart.ListId = $list.ID

        $webpartmanager=  $web.GetLimitedWebPartManager($pageurl,[System.Web.UI.WebControls.WebParts.PersonalizationScope]::Shared)

         # Loop through all the webparts in the page and , Check if the List  is already Exisiting if i = 1 means list with that id is already exisiting.

        foreach($wpt in $webpartmanager.WebParts)

         # Webpart List id is compared with List id to check for existance of webpart.

                if($wpt.ListId -eq $list.ID)
                 $i=$i + 1

         if($i -ne "0")


         Write-Host "List is already existing" $list.Title


        write-host "Library is not existing hence Added"

      catch [Exception]

       Write-Host $_.Exception.Message

Read the Page url's in the PageLibrary using Powershell SharePoint 2013

Read Pages from Page Library using Powershell SharePoint 2013


 $web= Get-SPWeb -Identity http://sedwdevrtm:22222/sites/abcd/

# Site Pages is the Name of Library for Pages in SP2013

 $lists=$web.Lists.TryGetList("Site Pages")

# Displays the list of Pages with Name from Page Library

 Write-Host $lists.Items.Name 

# Read Site Pages with URL's Library Pages 

 Write-Host $lists.Items.URLS

# Count of Pages in the Library Pages in SP2013

 Write-Host  $lists.Items.Count

Wednesday, 1 January 2014

MultiChoice CheckBox field using PowerShell

Create SPField Multichoice checkbox field using Powershell

  # Read the Site Url from User

 $url = Read-host " Enter Name of the Site to Add Document Library"

   # get Website name

$OpenWeb = Get-SPWeb $url -ErrorVariable err -ErrorAction SilentlyContinue -AssignmentCollection $assignmentCollection

       # Get the Document Library Name              

       # Create and xml field element to add multichoice values

$fldXml = "<Field Type='MultiChoice' DisplayName='Document Status' Name='DocumentStatus' >
                            <CHOICE>Review Required</CHOICE>
                            <CHOICE>Review in Progress</CHOICE>
                            <CHOICE>Review Completed</CHOICE>



that's set ........