1

I am using SharePoint 2013 On Premises. I am trying modify the values Exclude from Internet Search Engines( Present in Edit SEO Properties of a page, RobotsNoIndex field) with respect to Include/Exclude internal Search ( Present in Edit Properties, TSExternalSearch field), such that when Internal Search is marked as "Hide", "Exclude from sitemap and hide from Search Engines" is selected for Internet Search Engines. I am trying to achieve this feat for a single page in document library as of now.

Here is the partial code:

Add-Type -Path 'C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll'
Add-Type -Path 'C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Runtime.dll'
Add-Type -Path 'C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Publishing.dll'
Add-Type -Path 'C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Taxonomy.dll'

$siteURL = "http://dvsandboxv2-07:46000/"
$spSite = [Microsoft.SharePoint.SPSite] ($siteURL)

if($spSite -ne $null)
{
   "Site Collection : " + $spSite.Url 
   foreach($subWeb in $spSite.AllWebs)
   {
      if($subWeb -ne $null)
      {

         $spListColl = $subweb.Lists
         foreach($eachList in $spListColl)
         {
            if($eachList.Title -eq "Pages")
            {
               $PagesUrl = $subweb.Url + "/"
               foreach($eachPage in $eachList.Items)
               {

                     $eachPage.CheckOut()
                    if($eachPage['TSExternalSearch'] -eq "Hide")
                    {

                        $eachPage['RobotsNoIndex'] = 0    
                        $eachPage.Update()

                    } 
                    else
                    {
                        $eachPage['RobotsNoIndex'] = 1    
                        $eachPage.Update()
                    }
                     $eachPage.File.CheckIn("check in comment", [Microsoft.SharePoint.Client.CheckinType]::MajorCheckIn)
                     $eachPage.File.Publish(" ")
               }
            }
         }
         $subWeb.Dispose()
      }
      else
      {
         Echo $subWeb "does not exist"
      }
   }
   $spSite.Dispose()
}
else
{
   Echo $siteURL "does not exist, check the site collection url"
}
Echo Finish

Syncing these fields

Can you help me with some hints or directions on how should I move ahead with this problem. Any help would be appreciated!

Thanks

0

I have tried the script below, the logic works fine, but I have faced some issue while checkin/checkout certain files. I hope, this will help other users. Also You are welcomed to suggest improvements.

Try{
    Add-Type -Path 'C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll'
    Add-Type -Path 'C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Runtime.dll'
    Add-Type -Path 'C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Publishing.dll'
    Add-Type -Path 'C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Taxonomy.dll'
}

catch {
    Throw "Unable to load SharePoint Client runtime"
} 
$siteURL = "http://dvsandboxv2-07:46000/"
$spSite = [Microsoft.SharePoint.SPSite] $siteURL
$web = Get-SPWeb -Identity $siteURL


if($spSite -ne $null)
{
   "Site Collection : " + $spSite.Url 
   foreach($subWeb in $spSite.AllWebs)
   {
      if($subWeb -ne $null)
        {

         $spListColl = $subweb.Lists
         foreach($eachList in $spListColl)
         {

            if($eachList.Title -eq "Pages")
            {
               $PagesUrl = $subweb.Url + "/"
                foreach($eachPage in $eachList.Items)
                {

                    $spFile = $web.GetFile($eachPage.Url)

                    try{

                        if($spFile.CheckOutType -ne "None")
                        {
                            $spFile.UndoCheckOut()  
                            $spFile.Update()                     
                        }
                    }
                    catch{


                    #Get-PSCallStack

                    write-host -f Red "Error in UndoCheckOut" $_.Exception.Message
                    }


                   try{

                    $spFile.CheckOut()
                    $spFile.Update()
                    }

                    catch{
                        write-host -f Red "Error in CheckOut" $_.Exception.Message
                        }

                        if($spFile.GetProperty("TSExternalSearch") -eq "Hide")
                        {
                            $spFile.SetProperty("RobotsNoIndex",1)    
                            $spFile.Update()
                        } 
                        else
                        {
                            $spFile.SetProperty("RobotsNoIndex",0)    
                            $spFile.Update()
                        }

                    try{
                    $spFile.CheckIn("CheckIn by Admin")
                    $spFile.Update()
                    $spFile.Publish(" ")
                    }
                    catch{
                    write-host -f Red "Error in CheckIn" $_.Exception.Message
                        }
                }
            }

         $subWeb.Dispose()
         }
        }
      else
        {
         Echo $subWeb "does not exist"
        }
    }
   $spSite.Dispose()
}
else
{
   Echo $siteURL "does not exist, check the site collection url"
}

Echo Finish
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.