How To Activate The Boldon James SharePoint Classifier Feature For The Site Collection

Well, in the previous post, 

We learned how to install, configure and enable Boldon James Classifier for SharePoint.

In that Post, we had a section, which was about how to activate the Boldon James SharePoint Classifier feature for the site collection and apply endpoint. If we have a few sites, we can do it manually. However, think about a big farm, which has multiple Web Applications and each Web Application has thousands of site collections, the task becomes very tedious and challenging.

Therefore, we need some sort of script or code, which can do this for us without having us put in more effort. For that, the first thing came to my mind is PowerShell script. Well, I went ahead and prepared the script, which makes our task much easier. All we need to do is, just place the script in SharePoint Server and provide a few inputs at run time. That’s it, the script will take over from there and do our task.

Script

Save the script given below to SharePoint Server.

  1. <#  
  2. .SYNOPSIS  
  3. Sets the SharePoint Classifier Service EndPoint URL for a Site Collection  
  4. .DESCRIPTION  
  5. Sets the SharePoint Classifier Service EndPoint URL for a Site Collection  
  6. #>  
  7.   
  8. Function PromptForServiceEndPointURL  
  9. {  
  10.     $ServiceEndPointAccpeted = $false  
  11.     While($ServiceEndPointAccpeted -ne $true)  
  12.     {  
  13.         $EndPointInput = Read-Host -Prompt "Please provide Boldon James Classifier Service Endpoint URL"  
  14.         if($EndPointInput -ne $null -and $EndPointInput -ne "")  
  15.         {  
  16.             try  
  17.             {  
  18.                 $xHTTP = new-object -com msxml2.xmlhttp;  
  19.                 $xHTTP.open("GET",$EndPointInput,$false);  
  20.                 $xHTTP.send();  
  21.                 $xHTTP.status # returns the status code   
  22.                 if ($xHTTP.status -eq "200")  
  23.                 {  
  24.                     Write-Host -ForegroundColor Green "Endpoint URL has been accepted..."  
  25.                     $ServiceEndPointAccpeted = $true  
  26.                 }  
  27.                 else  
  28.                 {  
  29.                     Write-Host -ForegroundColor Red "Endpoint URL is not valid, please provide valid input..."  
  30.                 }  
  31.             }  
  32.             catch  
  33.             {  
  34.                 Write-Host -ForegroundColor Red "Endpoint URL validation failed..."  
  35.             }  
  36.         }  
  37.         else  
  38.         {  
  39.             Write-Host -ForegroundColor Red "Invalid URL, please enter correct URL..."  
  40.         }  
  41.     }  
  42.     Return $EndPointInput  
  43. }  
  44. Function ApplyBoldonJamesServiceEndPoint($SiteCollectionUrl, $SCServiceEndpointUrl)  
  45. {  
  46.     try  
  47.     {  
  48.         $FeatureActivated = $false   
  49.         $ActivationResults = @()  
  50.         $ValueAccepted = $false   
  51.         $site = New-Object Microsoft.SharePoint.SPSite($SiteCollectionUrl)  
  52.         if((Get-SPFeature "SharePointClassifier_Classifier" -Site $Site -ErrorAction SilentlyContinue) -eq $null)  
  53.         {  
  54.             Write-Host "Feature is not enabled, enabling it now..."  
  55.             $Feature = Enable-SPFeature "SharePointClassifier_Classifier" -Url $Site.URL -ErrorAction SilentlyContinue   
  56.             Write-Host "Enabled Feature"  
  57.             if((Get-SPFeature "SharePointClassifier_Classifier" -Site $Site -ErrorAction SilentlyContinue) -eq $null)  
  58.             {  
  59.                 $FeatureActivated = $False  
  60.                 $ActivationResults += $false   
  61.             }  
  62.         }  
  63.         else  
  64.         {  
  65.             $FeatureActivated = $true  
  66.             $ActivationResults += $true  
  67.         }  
  68.         if($FeatureActivated -eq $true)  
  69.         {  
  70.             Write-Host Now adding the property  
  71.             $rootWeb = $site.RootWeb  
  72.   
  73.             Write-Host -foregroundcolor Green "The Site Collection Root Site is" $rootWeb  
  74.   
  75.             $EndPointProperty = "bjEndpointAddress"  
  76.   
  77.             $rootWeb.AllowUnsafeUpdates = $true;  
  78.             $Currentvalue = $rootWeb.AllProperties[$EndPointProperty]  
  79.             Write-Host -foregroundcolor Green "The current value is "$Currentvalue  
  80.   
  81.             if (!$rootWeb.AllProperties.ContainsKey($EndPointProperty))  
  82.             {   
  83.                      $rootWeb.AllProperties.Add($EndPointProperty, $SCServiceEndpointurl);  
  84.             }  
  85.             else  
  86.             {  
  87.                      $rootWeb.AllProperties[$EndPointProperty] = $SCServiceEndpointurl;  
  88.             }              
  89.                           
  90.             $rootWeb.Update();  
  91.   
  92.             $rootWeb.AllowUnsafeUpdates = $false;  
  93.   
  94.             $UpdatedValue =  $rootWeb.AllProperties[$EndPointProperty]  
  95.             Write-Host -foregroundcolor Green "Value is updated with " $UpdatedValue  
  96.   
  97.             if($UpdatedValue -eq $SCServiceEndpointUrl)  
  98.             {  
  99.                 $ValueAccepted = $true   
  100.             }  
  101.             else  
  102.             {  
  103.                 $ValueAccepted = $false   
  104.             }  
  105.             if ($rootWeb -ne $null)  
  106.             {  
  107.                 $rootWeb.Dispose()  
  108.   
  109.             }  
  110.             If ($site -ne $null)  
  111.             {  
  112.                 $site.Dispose();  
  113.             }  
  114.             $ActivationResults += $ValueAccepted  
  115.         }  
  116.         else  
  117.         {  
  118.             $ActivationResults += $false   
  119.         }  
  120.         Return $ActivationResults  
  121.     }  
  122.     catch  
  123.     {  
  124.         $ActivationResults += $FeatureActivated   
  125.         $ActivationResults += $ValueAccepted  
  126.         Return $ActivationResults  
  127.     }  
  128.       
  129. }  
  130. Function ApplyEndPointUsingIE($EPURL, $SCURL)  
  131. {  
  132.     Try  
  133.     {  
  134.         $addedToLocalIntranetZone = $false   
  135.         $SiteName = "*"  
  136.         $myDomain = "yourdomain.com"  
  137.         #Write-Host -F Yellow "Verifying existence of "$SiteName"."$myDomain" in Local Intranet Zone"  
  138.         $RegItem_Path = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains\" + $myDomain + "\" + $SiteName  
  139.         If((Test-Path $RegItem_Path -ErrorAction SilentlyContinue) -eq $True)  
  140.         {  
  141.             #Write-Host -F Cyan $SiteName"."$myDomain already exists in Local Intranet Zone  
  142.             $addedToLocalIntranetZone = $true  
  143.                 #Exit 1001  
  144.         }  
  145.         Else  
  146.         {  
  147.             #Write-Host -F Blue $SiteName"."$myDomain not found in Local Intranet Zone, adding it now  
  148.             New-Item $RegItem_Path -Force | Out-Null  
  149.             New-ItemProperty -Path $RegItem_Path -Name https -Value 1 -PropertyType DWord | Out-Null  
  150.             New-ItemProperty -Path $RegItem_Path -Name http -Value 1 -PropertyType DWord | Out-Null  
  151.             If((Test-Path $RegItem_Path -ErrorAction SilentlyContinue) -eq $True)  
  152.             {  
  153.                 #Write-Host -F Green $SiteName"."$mydomain has been added to Local Intranet Zone  
  154.                 $addedToLocalIntranetZone = $true  
  155.             }  
  156.             else  
  157.             {  
  158.                 #Write-Host -F Red $SiteName"."$mydomain could not be added to Local Intranet Zone  
  159.             }  
  160.         }   
  161.   
  162.     }  
  163.     Catch  
  164.     {  
  165.         #Write-Host -F Red "An error occurred while verifying "$SiteName"."$myDomain" in Local Intranet Zone"  
  166.         #Exit 1001  
  167.     }  
  168.     if($addedToLocalIntranetZone -ne $false)  
  169.     {  
  170.         $SiteCollectionURL = $SCURL  
  171.         $ActivationResults = @()  
  172.         $FeatureActivated = $false  
  173.         if((Get-SPFeature "SharePointClassifier_Classifier" -Site $SiteCollectionURL -ErrorAction SilentlyContinue) -eq $null)  
  174.         {  
  175.             #Write-Host "Feature is not enabled, enabling it now..."  
  176.             $Feature = Enable-SPFeature "SharePointClassifier_Classifier" -Url $SiteCollectionURL -ErrorAction SilentlyContinue   
  177.             #Write-Host "Enabled Feature"  
  178.             if((Get-SPFeature "SharePointClassifier_Classifier" -Site $SiteCollectionURL -ErrorAction SilentlyContinue) -eq $null)  
  179.             {  
  180.                 #Write-Host -F Red "Feature could not be activated on the site"  
  181.                 $ActivationResults += $False  
  182.             }  
  183.             else  
  184.             {  
  185.                 #Write-Host -F Green "Feature has been activated on the site"  
  186.                 $ActivationResults += $true   
  187.                 $FeatureActivated = $true  
  188.             }  
  189.         }  
  190.         else  
  191.         {  
  192.             #Write-Host -F Cyan "Feature is already activated on the site"  
  193.             $ActivationResults += $true  
  194.             $FeatureActivated = $true  
  195.         }  
  196.           
  197.         if($FeatureActivated -eq $true)  
  198.         {  
  199.             $URI = $SiteCollectionURL + "/_layouts/15/SharePointClassifier/SharePointClassifierSiteSettings.aspx"  
  200.             $ieObject = new-object -com "InternetExplorer.Application"  
  201.             $ieObject.navigate($URI)  
  202.             for($i = 10; $i -gt 0; $i--)  
  203.             {  
  204.                 #Write-Host -F Yellow "Authenticating, please wait for $i second(s)...`r" -NoNewLine  
  205.                 Sleep -s 1  
  206.             }  
  207.             #Write-Host -F Green "Internet Explorer has been opened successfully..."  
  208.             $ieObject.visible = $true  
  209.  
  210.             #Retrieve the HTML document returned by search page to an object  
  211.             $doc = $ieObject.Document  
  212.  
  213.             #Write-Host -F Yellow "Please wait while the service endpoint is being applied..."  
  214.             #Enter value to be searched in the search text box  
  215.             $doc.getElementByID("ctl00_PlaceHolderMain_TextBoxServiceEndPointAddress").Value = $EPURL  
  216.  
  217.             #Click on Search button  
  218.             $doc.GetElementByID("ctl00_PlaceHolderMain_LinkButtonServiceSettings").Click()  
  219.   
  220.             do  
  221.             {  
  222.                 sleep 1  
  223.                 #Write-Host "Please wait while the operation is being processed...`r" -NoNewLine  
  224.             }  
  225.             until(-not ($ieObject.Busy))  
  226.             #Write-Host   
  227.             #Write-Host -F Green "Operation has been processed by the browser..."  
  228.   
  229.             $EndPointResultErrorElementFound = $False  
  230.             $EndPointResultSuccessElementFound  = $False  
  231.             $EndPointResultErrorText = "NA"  
  232.             $EndPointResultSuccessText = "NA"  
  233.             While($EndPointResultErrorElementFound -ne $True -or $EndPointResultErrorElementFound -ne $True)  
  234.             {  
  235.                 #Write-Host -F Yellow "Loading page contents, please wait... `r" -NoNewLine  
  236.                 $EndPointResultDoc = $ieObject.Document  
  237.                 $EndPointResultErrorElement = $EndPointResultDoc.GetElementByID("ctl00_PlaceHolderMain_ServiceSettingsError")  
  238.                 if($EndPointResultErrorElement -ne $null)  
  239.                 {  
  240.                     $EndPointResultErrorElementFound = $true  
  241.                     $EndPointResultErrorText = $EndPointResultErrorElement.OuterText  
  242.                     #Write-Host -F Red Error Element Found, Error Is: $EndPointResultErrorText  
  243.                 }  
  244.                 $EndPointResultSuccessElement = $EndPointResultDoc.GetElementByID("ctl00_PlaceHolderMain_ServiceSettingsSuccess")  
  245.                 if($EndPointResultSuccessElement -ne $null)  
  246.                 {  
  247.                     $EndPointResultSuccessElementFound = $true  
  248.                     $EndPointResultSuccessText = $EndPointResultSuccessElement.OuterText  
  249.                     #Write-Host -F Green Success Element Found, Message: $EndPointResultSuccessText  
  250.                 }  
  251.   
  252.                 Sleep -s 1  
  253.             }  
  254.             #Write-Host   
  255.             #Write-Host -F Green "Boldon James Classifier service page has been loaded..."  
  256.  
  257.             #Check whether the search operation succeeded or not  
  258.             if($EndPointResultSuccessText -ne "" -and $EndPointResultSuccessText -ne $null)  
  259.             {  
  260.                 #Write-Host -F Green "Operation successful..."  
  261.                 #Write-Host -F Magenta Result: $EndPointResultSuccessText  
  262.                 $ErrorOccurred = "No"  
  263.             }  
  264.             elseif($EndPointResultErrorText -ne "" -and $EndPointResultErrorText -ne $null)  
  265.             {  
  266.                 #Write-Host -F Red "Operation failed..."  
  267.                 #Write-Host -F Magenta Result: $EndPointResultErrorText  
  268.                 $ErrorOccurred = "Yes"  
  269.             }  
  270.             $ieObject.Quit()  
  271.             if($ErrorOccurred -eq "No")  
  272.             {  
  273.                 $ActivationResults += $true   
  274.             }  
  275.             elseif($ErrorOccurred -eq "Yes")  
  276.             {  
  277.                 $ActivationResults += $false   
  278.             }  
  279.         }  
  280.         else  
  281.         {  
  282.             $ActivationResults += $false   
  283.         }  
  284.         Return $ActivationResults   
  285.     }  
  286.     else  
  287.     {  
  288.         #Write-Host "Terminating the execution as the domain could not be added to Local Intranet Zone..."  
  289.         $ActivationResults += $false  
  290.         $ActivationResults += $false   
  291.         Return $ActivationResults   
  292.     }  
  293. }  
  294. Clear-Host  
  295. Add-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue  
  296. if((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -ne $null)  
  297. {  
  298.     Write-Host -ForegroundColor Cyan "============================================================="  
  299.     Write-Host -ForegroundColor Magenta "              Boldon James Service Activation               "  
  300.     Write-Host -ForegroundColor Cyan "============================================================="  
  301.     Function PromptForScopeSelections  
  302.     {  
  303.         $promptTitle = "Scope selection"  
  304.         $promptMessage = "Please select the option to set scope for applying Boldon James Classifier EndPoint"  
  305.   
  306.         $optionSite = New-Object System.Management.Automation.Host.ChoiceDescription "&Site Collection", `  
  307.         "Apply for one site collection"  
  308.         $optionSite.HelpMessage = "This option will apply Boldon James Classifier Service EndPoint for one site collection"  
  309.   
  310.         $optionWebApp = New-Object System.Management.Automation.Host.ChoiceDescription "&Web Application", `  
  311.         "Apply for all site collections in a web application"  
  312.         $optionWebApp.HelpMessage = "This option will apply Boldon James Classifier Service EndPoint for all site collections in one web application"  
  313.           
  314.         $optionFarm = New-Object System.Management.Automation.Host.ChoiceDescription "&Farm", `  
  315.         "Apply for all site collections in all web applications"  
  316.         $optionFarm.HelpMessage = "This option will apply Boldon James Classifier Service EndPoint for all site collections in all web applications"  
  317.   
  318.         $promptOptions = [System.Management.Automation.Host.ChoiceDescription[]]($optionSite, $optionWebApp, $optionFarm)  
  319.   
  320.         $promptResult = $host.ui.PromptForChoice($promptTitle, $promptMessage, $promptOptions, 0)  
  321.         Return $promptResult  
  322.     }  
  323.       
  324.     Write-Host -ForegroundColor Green "SharePoint snap-in has been loaded successfully..."  
  325.  
  326.     #Call the function to prompt for scope selection.  
  327.     $UserOption = 3  
  328.     $UserOptionAccepted = $false  
  329.     While($UserOptionAccepted -ne $true)  
  330.     {  
  331.         $UserOption = PromptForScopeSelections  
  332.         if($UserOption -ge 0 -and $UserOption -le 3)  
  333.         {  
  334.             Write-Host -ForegroundColor Green "Input has been accepted."  
  335.             switch ($UserOption)  
  336.             {  
  337.                 2 {Write-Host -ForegroundColor DarkCyan "You selected farm."}  
  338.                 1 {Write-Host -ForegroundColor DarkCyan "You selected web application."}  
  339.                 0 {Write-Host -ForegroundColor DarkCyan "You selected site collection."}  
  340.             }  
  341.             $UserOptionAccepted = $true  
  342.         }  
  343.         elseif($UserOption -lt 0 -or $UserOption -ge 3 -or $UserOption -eq "" -or $UserOption -eq $null)  
  344.         {  
  345.             Write-Host -ForegroundColor Red "Invalid input..."  
  346.         }  
  347.     }  
  348.     if($UserOptionAccepted -eq $true)  
  349.     {  
  350.         $ScriptPath = Split-Path $MyInvocation.MyCommand.Path  
  351.         $ScriptDate = Get-Date -Format "dd-MMM-yyyy"  
  352.         $ScriptTime = Get-Date -Format "hh-mm-ss"  
  353.         $SiteCounter = 0  
  354.         $SuccessCount = 0  
  355.         $FailedCount = 0  
  356.         $WebAppCounter = 0  
  357.         [string]$EndPointURLDummy = PromptForServiceEndpointURL  
  358.         $EndPointURLTemp = $EndPointURLDummy + "/soap/"  
  359.         $EndPointURL = $EndPointURLTemp.ToString().Replace("200 ","")  
  360.         if($EndPointURL -eq $null -or $EndPointURL -eq "")  
  361.         {  
  362.             Write-Host -ForegroundColor Red "EndPoint URL is not valid, terminating the execution..."  
  363.             Return  
  364.         }  
  365.         if($UserOption -eq 2)  
  366.         {  
  367.             $BJReportPath = $ScriptPath + "\" + "SharePointFarm_BoldonJamesActivation_" + $ScriptDate + "_" + $ScriptTime + ".csv"  
  368.             "Site URL`tBJ EndPoint Applied?" | Out-File $BJReportPath  
  369.             $WebApplications = Get-SPWebAppllication -ErrorAction SilentlyContinue  
  370.             if($WebApplications.Count -ge 1)  
  371.             {  
  372.                 $WebAppsCount = $WebApplications.Count  
  373.                 ForEach($WebApplication in $WebApplications)  
  374.                 {  
  375.                     $WebAppCounter++  
  376.                     $SiteCollections = Get-SPSite -Limit All -WebApplication $WebApplication -ErrorAction SilentlyContinue  
  377.                     $SiteCollectionsCount = ($SiteCollections | Measure).Count  
  378.                     if($SiteCollectionsCount -ge 1)  
  379.                     {  
  380.                         ForEach($RootSite in $SiteCollections)  
  381.                         {  
  382.                             $SiteCounter++  
  383.                             Write-Host -ForegroundColor DarkMagenta "Processing site no. " -NoNewline  
  384.                             Write-Host -ForegroundColor Cyan "$siteCounter out of $SiteCollectionsCount " -NoNewline  
  385.                             Write-Host -ForegroundColor Magenta " in Web App $WebAppCounter out of $WebAppsCount `r"  
  386.                             #$ApplyResult = ApplyBoldonJamesServiceEndPoint $RootSite.URL $EndPointURL   
  387.                             $ApplyResult = ApplyEndPointUsingIE $EndPointURL $RootSite.URL  
  388.                             if($ApplyResult[0] -eq $true -and $ApplyResult[1] -eq $True)  
  389.                             {  
  390.                                 $SuccessCount++  
  391.                                 $RootSite.URL + "`tTrue`tTrue" | Out-File $BJReportPath -Append  
  392.                             }  
  393.                             elseif($ApplyResult[0] -eq $true -and $ApplyResult[1] -eq $false)  
  394.                             {  
  395.                                 $FailedCount++  
  396.                                 $RootSite.URL + "`tTrue`tFalse" | Out-File $BJReportPath -Append  
  397.                             }  
  398.                             elseif($ApplyResult[0] -eq $false -and $ApplyResult[1] -eq $true)  
  399.                             {  
  400.                                 $FailedCount++  
  401.                                 $RootSite.URL + "`tFalse`tTrue" | Out-File $BJReportPath -Append                          
  402.                             }  
  403.                             elseif($ApplyResult[0] -eq $false -and $ApplyResult[1] -eq $false)  
  404.                             {  
  405.                                 $FailedCount++  
  406.                                 $RootSite.URL + "`tFalse`tFalse" | Out-File $BJReportPath -Append                             
  407.                             }  
  408.                         }  
  409.                           
  410.                     }  
  411.                     else  
  412.                     {  
  413.                         Write-Host -ForegroundColor Red "No site collection found in the web application...."  
  414.                     }  
  415.                 }  
  416.             }  
  417.             else  
  418.             {  
  419.                 Write-Host -ForegroundColor Red "No web application found in the farm, terminating the execution.."  
  420.             }     
  421.         }  
  422.         elseif($UserOption -eq 1)  
  423.         {  
  424.             $WebAppAccepted = $false  
  425.             while($WebAppAccepted -ne $true)  
  426.             {  
  427.                 $WebAppURL = Read-Host -Prompt "Please Enter Web Application URL"  
  428.                 if(($WebApplication = Get-SPWebApplication $WebAppURL -ErrorAction SilentlyContinue) -ne $null)  
  429.                 {  
  430.                     Write-Host -ForegroundColor Green "Web Application URL has been accepted..."  
  431.                     $WebAppTitle = $WebApplication.Name.ToString().Replace(" ","_")  
  432.                     $WebAppAccepted = $true  
  433.                 }  
  434.                 else  
  435.                 {  
  436.                     Write-Host -ForegroundColor Red "Invalid input, please provide valid Web Application URL"  
  437.                 }  
  438.             }  
  439.             if($WebAppAccepted -eq $true)  
  440.             {  
  441.                 $BJReportPath = $ScriptPath + "\" + "WebApplication_" + $WebAppTitle + "_BoldonJamesActivation_" + $ScriptDate + "_" + $ScriptTime + ".csv"  
  442.                 "Site URL`tFeature Activated?`tEndPoint Applied?" | Out-File $BJReportPath  
  443.                 $SiteCollections = Get-SPSite -Limit All -WebApplication $WebApplication -ErrorAction SilentlyContinue  
  444.                 $SiteCollectionsCount = ($SiteCollections | Measure).Count  
  445.                 if($SiteCollectionsCount -ge 1)  
  446.                 {  
  447.                     ForEach($RootSite in $SiteCollections)  
  448.                     {  
  449.                         $SiteCounter++  
  450.                         Write-Host -ForegroundColor DarkMagenta "Processing site no. " -NoNewline  
  451.                         Write-Host -ForegroundColor Cyan "$siteCounter out of $SiteCollectionsCount "  
  452.                         #$ApplyResult = ApplyBoldonJamesServiceEndPoint $RootSite.URL $EndPointURL   
  453.                         $ApplyResult = ApplyEndPointUsingIE $EndPointURL $RootSite.URL  
  454.                         if($ApplyResult[0] -eq $true -and $ApplyResult[1] -eq $True)  
  455.                         {  
  456.                             $SuccessCount++  
  457.                             $RootSite.URL + "`tTrue`tTrue" | Out-File $BJReportPath -Append  
  458.                         }  
  459.                         elseif($ApplyResult[0] -eq $true -and $ApplyResult[1] -eq $false)  
  460.                         {  
  461.                             $FailedCount++  
  462.                             $RootSite.URL + "`tTrue`tFalse" | Out-File $BJReportPath -Append  
  463.                         }  
  464.                         elseif($ApplyResult[0] -eq $false -and $ApplyResult[1] -eq $true)  
  465.                         {  
  466.                             $FailedCount++  
  467.                             $RootSite.URL + "`tFalse`tTrue" | Out-File $BJReportPath -Append                          
  468.                         }  
  469.                         elseif($ApplyResult[0] -eq $false -and $ApplyResult[1] -eq $false)  
  470.                         {  
  471.                             $FailedCount++  
  472.                             $RootSite.URL + "`tFalse`tFalse" | Out-File $BJReportPath -Append                             
  473.                         }                         
  474.                     }  
  475.                       
  476.                 }  
  477.                 else  
  478.                 {  
  479.                     Write-Host -ForegroundColor Red "No site collection found in the web application...."  
  480.                 }  
  481.             }  
  482.         }  
  483.         elseif($UserOption -eq 0)  
  484.         {  
  485.             $SiteAccepted = $false  
  486.             while($SiteAccepted -ne $true)  
  487.             {  
  488.                 $SiteCollURL = Read-Host -Prompt "Please Enter Site Collection URL"  
  489.                 if(($SiteCollection = Get-SPSite $SiteCollURL -ErrorAction SilentlyContinue) -ne $null)  
  490.                 {  
  491.                     Write-Host -ForegroundColor Green "Site Collection URL has been accepted..."  
  492.                     $SiteTitle = $SiteCollection.RootWeb.Name.ToString().Replace(" ","_")  
  493.                     $SiteAccepted = $true  
  494.                 }  
  495.                 else  
  496.                 {  
  497.                     Write-Host -ForegroundColor Red "Invalid input, please provide valid Site Collection URL"  
  498.                 }  
  499.             }  
  500.             if($SiteAccepted -eq $true)  
  501.             {  
  502.                 $SiteCounter++  
  503.                 #Write-Host "Calling function to activate Boldon James"  
  504.                 #$ApplyResult = ApplyBoldonJamesServiceEndPoint $SiteCollURL $EndPointURL   
  505.                 $ApplyResult = ApplyEndPointUsingIE $EndPointURL $SiteCollection.URL  
  506.                 if($ApplyResult[0] -eq $true -and $ApplyResult[1] -eq $True)  
  507.                 {  
  508.                     $SuccessCount++  
  509.                     Write-Host -ForegroundColor Magenta "Feature Activation: " -NoNewline  
  510.                     Write-Host -ForegroundColor Green "Passed"  
  511.                     Write-Host -ForegroundColor Magenta "Applying EndPoint: " -NoNewline  
  512.                     Write-Host -ForegroundColor Green "Passed"  
  513.                 }  
  514.                 elseif($ApplyResult[0] -eq $true -and $ApplyResult[1] -eq $false)  
  515.                 {  
  516.                     $FailedCount++  
  517.                     Write-Host -ForegroundColor Magenta "Feature Activation: " -NoNewline  
  518.                     Write-Host -ForegroundColor Green "Passed"  
  519.                     Write-Host -ForegroundColor Magenta "Applying EndPoint: " -NoNewline  
  520.                     Write-Host -ForegroundColor Red "Failed"  
  521.                 }  
  522.                 elseif($ApplyResult[0] -eq $false -and $ApplyResult[1] -eq $true)  
  523.                 {  
  524.                     $FailedCount++  
  525.                     Write-Host -ForegroundColor Magenta "Feature Activation: " -NoNewline  
  526.                     Write-Host -ForegroundColor Red "Failed"  
  527.                     Write-Host -ForegroundColor Magenta "Applying EndPoint: " -NoNewline  
  528.                     Write-Host -ForegroundColor Green "Passed"                        
  529.                 }  
  530.                 elseif($ApplyResult[0] -eq $false -and $ApplyResult[1] -eq $false)  
  531.                 {  
  532.                     $FailedCount++  
  533.                     Write-Host -ForegroundColor Magenta "Feature Activation: " -NoNewline  
  534.                     Write-Host -ForegroundColor Red "Failed"  
  535.                     Write-Host -ForegroundColor Magenta "Applying EndPoint: " -NoNewline  
  536.                     Write-Host -ForegroundColor Red "Failed"                              
  537.                 }  
  538.             }  
  539.             #$BJReportPath = $ScriptPath + "\" + "SiteCollection_" + $SiteTitle + "_BoldonJamesActivation_" + $ScriptDate + "_" + $ScriptTime + ".csv"  
  540.         }  
  541.         Write-Host -ForegroundColor Green "Script execution completed..."  
  542.         Write-Host -ForegroundColor Magenta "Please find below summary:"  
  543.         Write-Host -ForegroundColor Cyan "Total no. of sites processed: $siteCounter"  
  544.         Write-Host -ForegroundColor Green "No. of sites successful: $successCount"  
  545.         Write-Host -ForegroundColor Yellow "No of sites failed: $failedCount"  
  546.         if($UserOption -eq 1 -or $UserOption -eq 2)  
  547.         {  
  548.             Write-Host -ForegroundColor DarkCyan "Find the detailed report at $BJReportPath ..."  
  549.         }  
  550.         Write-Host -ForegroundColor Cyan "=================================================="  
  551.           
  552.     }  
  553.     else  
  554.     {  
  555.         Write-Host -ForegroundColor Red "Scope selection was not valid, terminating the exectuion..."  
  556.         Return  
  557.     }  
  558. }  
  559. else  
  560. {  
  561.     Write-Host -ForegroundColor Red "SharePoint Snapin could not be loaded, terminating the execution..."  
  562. }  
  563.  
  564.  
  565. #$url= Read-Host 'Enter the Site Collection URL'  
  566. #$SCServiceEndpointurl= Read-Host 'Enter the SharePoint Classifier Service Endpoint URL'  

 

Note

Before running the script, change the domain at line 136 in the script [shown below].

$myDomain = “yourdomain.com”

Inputs

  1. The script prompts for the first input, which is selecting scope. It provides us 3 options, namely Site, Web Application and Farm. Based on the need, we can select the appropriate option.

  2. Next input required is Boldon James Classifier Web Service URL. We need to provide URL till .svc. For example - http://bj-classifier.domain.com:8080/ClassifierWCFService/ClassifierWCFService.svc

  3. Third input will be asked, if we select an option “Site” or “Web Application” for the first input. If the option selected was “Site”, it will ask for the site collection URL and if “Web Application” was selected, it will ask for Web Application URL.

If we provide any invalid input, the script will prompt again, until it receives a valid input. Once it receives all the valid inputs, it will take care of remaining task and upon the completion of execution, it will show us the summary. For more detailed reports [if we selected “Site” or “Web Application” option], it will generate a CSV file in the same directory, where the script is placed and display the path of the output CSV in PowerShell Window.

That’s it. We can just go to site collection and verify whether it did the job or not. 

I’m currently working on preparing the script for applying the endpoint on the document libraries and shall be posting, once it’s ready.

Thanks for reading and using the script.

Ebook Download
View all
Learn
View all