Vinodsharepoint.files.wordpress.com



<#.SYNOPSISSets the SharePoint Classifier Service EndPoint URL for a Site Collection.DESCRIPTIONSets the SharePoint Classifier Service EndPoint URL for a Site Collection#>Function PromptForServiceEndPointURL{$ServiceEndPointAccpeted = $falseWhile($ServiceEndPointAccpeted -ne $true){$EndPointInput = Read-Host -Prompt "Please provide Boldon James Classifier Service Endpoint URL"if($EndPointInput -ne $null -and $EndPointInput -ne ""){try{$xHTTP = new-object -com msxml2.xmlhttp;$xHTTP.open("GET",$EndPointInput,$false);$xHTTP.send();$xHTTP.status # returns the status code if ($xHTTP.status -eq "200"){Write-Host -ForegroundColor Green "Endpoint URL has been accepted..."$ServiceEndPointAccpeted = $true}else{Write-Host -ForegroundColor Red "Endpoint URL is not valid, please provide valid input..."}}catch{Write-Host -ForegroundColor Red "Endpoint URL validation failed..."}}else{Write-Host -ForegroundColor Red "Invalid URL, please enter correct URL..."}}Return $EndPointInput}Function ApplyBoldonJamesServiceEndPoint($SiteCollectionUrl, $SCServiceEndpointUrl){try{$FeatureActivated = $false $ActivationResults = @()$ValueAccepted = $false $site = New-Object Microsoft.SharePoint.SPSite($SiteCollectionUrl)if((Get-SPFeature "SharePointClassifier_Classifier" -Site $Site -ErrorAction SilentlyContinue) -eq $null){Write-Host "Feature is not enabled, enabling it now..."$Feature = Enable-SPFeature "SharePointClassifier_Classifier" -Url $Site.URL -ErrorAction SilentlyContinue Write-Host "Enabled Feature"if((Get-SPFeature "SharePointClassifier_Classifier" -Site $Site -ErrorAction SilentlyContinue) -eq $null){$FeatureActivated = $False$ActivationResults += $false }}else{$FeatureActivated = $true$ActivationResults += $true}if($FeatureActivated -eq $true){Write-Host Now adding the property$rootWeb = $site.RootWebWrite-Host -foregroundcolor Green "The Site Collection Root Site is" $rootWeb$EndPointProperty = "bjEndpointAddress"$rootWeb.AllowUnsafeUpdates = $true;$Currentvalue = $rootWeb.AllProperties[$EndPointProperty]Write-Host -foregroundcolor Green "The current value is "$Currentvalueif (!$rootWeb.AllProperties.ContainsKey($EndPointProperty)){ $rootWeb.AllProperties.Add($EndPointProperty, $SCServiceEndpointurl);}else{ $rootWeb.AllProperties[$EndPointProperty] = $SCServiceEndpointurl;} $rootWeb.Update();$rootWeb.AllowUnsafeUpdates = $false;$UpdatedValue = $rootWeb.AllProperties[$EndPointProperty]Write-Host -foregroundcolor Green "Value is updated with " $UpdatedValueif($UpdatedValue -eq $SCServiceEndpointUrl){$ValueAccepted = $true }else{$ValueAccepted = $false }if ($rootWeb -ne $null){ $rootWeb.Dispose()}If ($site -ne $null){ $site.Dispose();}$ActivationResults += $ValueAccepted}else{$ActivationResults += $false }Return $ActivationResults}catch{$ActivationResults += $FeatureActivated $ActivationResults += $ValueAcceptedReturn $ActivationResults}}Function ApplyEndPointUsingIE($EPURL, $SCURL){Try{$addedToLocalIntranetZone = $false $SiteName = "*"$myDomain = ""#Write-Host -F Yellow "Verifying existence of "$SiteName"."$myDomain" in Local Intranet Zone"$RegItem_Path = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains\" + $myDomain + "\" + $SiteNameIf((Test-Path $RegItem_Path -ErrorAction SilentlyContinue) -eq $True){#Write-Host -F Cyan $SiteName"."$myDomain already exists in Local Intranet Zone$addedToLocalIntranetZone = $true #Exit 1001}Else{#Write-Host -F Blue $SiteName"."$myDomain not found in Local Intranet Zone, adding it nowNew-Item $RegItem_Path -Force | Out-NullNew-ItemProperty -Path $RegItem_Path -Name https -Value 1 -PropertyType DWord | Out-NullNew-ItemProperty -Path $RegItem_Path -Name http -Value 1 -PropertyType DWord | Out-NullIf((Test-Path $RegItem_Path -ErrorAction SilentlyContinue) -eq $True){#Write-Host -F Green $SiteName"."$mydomain has been added to Local Intranet Zone$addedToLocalIntranetZone = $true}else{#Write-Host -F Red $SiteName"."$mydomain could not be added to Local Intranet Zone}} }Catch{#Write-Host -F Red "An error occurred while verifying "$SiteName"."$myDomain" in Local Intranet Zone"#Exit 1001}if($addedToLocalIntranetZone -ne $false){$SiteCollectionURL = $SCURL$ActivationResults = @()$FeatureActivated = $falseif((Get-SPFeature "SharePointClassifier_Classifier" -Site $SiteCollectionURL -ErrorAction SilentlyContinue) -eq $null){#Write-Host "Feature is not enabled, enabling it now..."$Feature = Enable-SPFeature "SharePointClassifier_Classifier" -Url $SiteCollectionURL -ErrorAction SilentlyContinue #Write-Host "Enabled Feature"if((Get-SPFeature "SharePointClassifier_Classifier" -Site $SiteCollectionURL -ErrorAction SilentlyContinue) -eq $null){#Write-Host -F Red "Feature could not be activated on the site"$ActivationResults += $False}else{#Write-Host -F Green "Feature has been activated on the site"$ActivationResults += $true $FeatureActivated = $true}}else{#Write-Host -F Cyan "Feature is already activated on the site"$ActivationResults += $true$FeatureActivated = $true}if($FeatureActivated -eq $true){$URI = $SiteCollectionURL + "/_layouts/15/SharePointClassifier/SharePointClassifierSiteSettings.aspx"$ieObject = new-object -com "InternetExplorer.Application"$ieObject.navigate($URI)for($i = 10; $i -gt 0; $i--){#Write-Host -F Yellow "Authenticating, please wait for $i second(s)...`r" -NoNewLineSleep -s 1}#Write-Host -F Green "Internet Explorer has been opened successfully..."$ieObject.visible = $true#Retrieve the HTML document returned by search page to an object$doc = $ieObject.Document#Write-Host -F Yellow "Please wait while the service endpoint is being applied..."#Enter value to be searched in the search text box$doc.getElementByID("ctl00_PlaceHolderMain_TextBoxServiceEndPointAddress").Value = $EPURL#Click on Search button$doc.GetElementByID("ctl00_PlaceHolderMain_LinkButtonServiceSettings").Click()do{sleep 1#Write-Host "Please wait while the operation is being processed...`r" -NoNewLine}until(-not ($ieObject.Busy))#Write-Host #Write-Host -F Green "Operation has been processed by the browser..."$EndPointResultErrorElementFound = $False$EndPointResultSuccessElementFound = $False$EndPointResultErrorText = "NA"$EndPointResultSuccessText = "NA"While($EndPointResultErrorElementFound -ne $True -or $EndPointResultErrorElementFound -ne $True){#Write-Host -F Yellow "Loading page contents, please wait... `r" -NoNewLine$EndPointResultDoc = $ieObject.Document$EndPointResultErrorElement = $EndPointResultDoc.GetElementByID("ctl00_PlaceHolderMain_ServiceSettingsError")if($EndPointResultErrorElement -ne $null){$EndPointResultErrorElementFound = $true$EndPointResultErrorText = $EndPointResultErrorElement.OuterText#Write-Host -F Red Error Element Found, Error Is: $EndPointResultErrorText}$EndPointResultSuccessElement = $EndPointResultDoc.GetElementByID("ctl00_PlaceHolderMain_ServiceSettingsSuccess")if($EndPointResultSuccessElement -ne $null){$EndPointResultSuccessElementFound = $true$EndPointResultSuccessText = $EndPointResultSuccessElement.OuterText#Write-Host -F Green Success Element Found, Message: $EndPointResultSuccessText}Sleep -s 1}#Write-Host #Write-Host -F Green "Boldon James Classifier service page has been loaded..."#Check whether the search operation succeeded or notif($EndPointResultSuccessText -ne "" -and $EndPointResultSuccessText -ne $null){#Write-Host -F Green "Operation successful..."#Write-Host -F Magenta Result: $EndPointResultSuccessText$ErrorOccurred = "No"}elseif($EndPointResultErrorText -ne "" -and $EndPointResultErrorText -ne $null){#Write-Host -F Red "Operation failed..."#Write-Host -F Magenta Result: $EndPointResultErrorText$ErrorOccurred = "Yes"}$ieObject.Quit()if($ErrorOccurred -eq "No"){$ActivationResults += $true }elseif($ErrorOccurred -eq "Yes"){$ActivationResults += $false }}else{$ActivationResults += $false }Return $ActivationResults }else{#Write-Host "Terminating the execution as the domain could not be added to Local Intranet Zone..."$ActivationResults += $false$ActivationResults += $false Return $ActivationResults }}Clear-HostAdd-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinueif((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -ne $null){Write-Host -ForegroundColor Cyan "============================================================="Write-Host -ForegroundColor Magenta " Boldon James Service Activation "Write-Host -ForegroundColor Cyan "============================================================="Function PromptForScopeSelections{$promptTitle = "Scope selection"$promptMessage = "Please select the option to set scope for applying Boldon James Classifier EndPoint"$optionSite = New-Object System.Management.Automation.Host.ChoiceDescription "&Site Collection", ` "Apply for one site collection"$optionSite.HelpMessage = "This option will apply Boldon James Classifier Service EndPoint for one site collection"$optionWebApp = New-Object System.Management.Automation.Host.ChoiceDescription "&Web Application", ` "Apply for all site collections in a web application"$optionWebApp.HelpMessage = "This option will apply Boldon James Classifier Service EndPoint for all site collections in one web application"$optionFarm = New-Object System.Management.Automation.Host.ChoiceDescription "&Farm", ` "Apply for all site collections in all web applications"$optionFarm.HelpMessage = "This option will apply Boldon James Classifier Service EndPoint for all site collections in all web applications"$promptOptions = [System.Management.Automation.Host.ChoiceDescription[]]($optionSite, $optionWebApp, $optionFarm)$promptResult = $host.ui.PromptForChoice($promptTitle, $promptMessage, $promptOptions, 0)Return $promptResult}Write-Host -ForegroundColor Green "SharePoint snap-in has been loaded successfully..."#Call the function to prompt for scope selection.$UserOption = 3$UserOptionAccepted = $falseWhile($UserOptionAccepted -ne $true){$UserOption = PromptForScopeSelectionsif($UserOption -ge 0 -and $UserOption -le 3){Write-Host -ForegroundColor Green "Input has been accepted."switch ($UserOption) { 2 {Write-Host -ForegroundColor DarkCyan "You selected farm."} 1 {Write-Host -ForegroundColor DarkCyan "You selected web application."}0 {Write-Host -ForegroundColor DarkCyan "You selected site collection."} }$UserOptionAccepted = $true}elseif($UserOption -lt 0 -or $UserOption -ge 3 -or $UserOption -eq "" -or $UserOption -eq $null){Write-Host -ForegroundColor Red "Invalid input..."}}if($UserOptionAccepted -eq $true){$ScriptPath = Split-Path $MyInvocation.MyCommand.Path$ScriptDate = Get-Date -Format "dd-MMM-yyyy"$ScriptTime = Get-Date -Format "hh-mm-ss"$SiteCounter = 0$SuccessCount = 0$FailedCount = 0$WebAppCounter = 0[string]$EndPointURLDummy = PromptForServiceEndpointURL$EndPointURLTemp = $EndPointURLDummy + "/soap/" $EndPointURL = $EndPointURLTemp.ToString().Replace("200 ","")if($EndPointURL -eq $null -or $EndPointURL -eq ""){Write-Host -ForegroundColor Red "EndPoint URL is not valid, terminating the execution..."Return}if($UserOption -eq 2){$BJReportPath = $ScriptPath + "\" + "SharePointFarm_BoldonJamesActivation_" + $ScriptDate + "_" + $ScriptTime + ".csv""Site URL`tBJ EndPoint Applied?" | Out-File $BJReportPath$WebApplications = Get-SPWebAppllication -ErrorAction SilentlyContinueif($WebApplications.Count -ge 1){$WebAppsCount = $WebApplications.CountForEach($WebApplication in $WebApplications){$WebAppCounter++$SiteCollections = Get-SPSite -Limit All -WebApplication $WebApplication -ErrorAction SilentlyContinue$SiteCollectionsCount = ($SiteCollections | Measure).Countif($SiteCollectionsCount -ge 1){ForEach($RootSite in $SiteCollections){$SiteCounter++Write-Host -ForegroundColor DarkMagenta "Processing site no. " -NoNewlineWrite-Host -ForegroundColor Cyan "$siteCounter out of $SiteCollectionsCount " -NoNewlineWrite-Host -ForegroundColor Magenta " in Web App $WebAppCounter out of $WebAppsCount `r"#$ApplyResult = ApplyBoldonJamesServiceEndPoint $RootSite.URL $EndPointURL $ApplyResult = ApplyEndPointUsingIE $EndPointURL $RootSite.URLif($ApplyResult[0] -eq $true -and $ApplyResult[1] -eq $True){$SuccessCount++$RootSite.URL + "`tTrue`tTrue" | Out-File $BJReportPath -Append}elseif($ApplyResult[0] -eq $true -and $ApplyResult[1] -eq $false){$FailedCount++$RootSite.URL + "`tTrue`tFalse" | Out-File $BJReportPath -Append}elseif($ApplyResult[0] -eq $false -and $ApplyResult[1] -eq $true){$FailedCount++$RootSite.URL + "`tFalse`tTrue" | Out-File $BJReportPath -Append}elseif($ApplyResult[0] -eq $false -and $ApplyResult[1] -eq $false){$FailedCount++$RootSite.URL + "`tFalse`tFalse" | Out-File $BJReportPath -Append}}}else{Write-Host -ForegroundColor Red "No site collection found in the web application...."}}}else{Write-Host -ForegroundColor Red "No web application found in the farm, terminating the execution.."}}elseif($UserOption -eq 1){$WebAppAccepted = $falsewhile($WebAppAccepted -ne $true){$WebAppURL = Read-Host -Prompt "Please Enter Web Application URL"if(($WebApplication = Get-SPWebApplication $WebAppURL -ErrorAction SilentlyContinue) -ne $null){Write-Host -ForegroundColor Green "Web Application URL has been accepted..."$WebAppTitle = $WebApplication.Name.ToString().Replace(" ","_")$WebAppAccepted = $true}else{Write-Host -ForegroundColor Red "Invalid input, please provide valid Web Application URL"}}if($WebAppAccepted -eq $true){$BJReportPath = $ScriptPath + "\" + "WebApplication_" + $WebAppTitle + "_BoldonJamesActivation_" + $ScriptDate + "_" + $ScriptTime + ".csv""Site URL`tFeature Activated?`tEndPoint Applied?" | Out-File $BJReportPath$SiteCollections = Get-SPSite -Limit All -WebApplication $WebApplication -ErrorAction SilentlyContinue$SiteCollectionsCount = ($SiteCollections | Measure).Countif($SiteCollectionsCount -ge 1){ForEach($RootSite in $SiteCollections){$SiteCounter++Write-Host -ForegroundColor DarkMagenta "Processing site no. " -NoNewlineWrite-Host -ForegroundColor Cyan "$siteCounter out of $SiteCollectionsCount "#$ApplyResult = ApplyBoldonJamesServiceEndPoint $RootSite.URL $EndPointURL $ApplyResult = ApplyEndPointUsingIE $EndPointURL $RootSite.URLif($ApplyResult[0] -eq $true -and $ApplyResult[1] -eq $True){$SuccessCount++$RootSite.URL + "`tTrue`tTrue" | Out-File $BJReportPath -Append}elseif($ApplyResult[0] -eq $true -and $ApplyResult[1] -eq $false){$FailedCount++$RootSite.URL + "`tTrue`tFalse" | Out-File $BJReportPath -Append}elseif($ApplyResult[0] -eq $false -and $ApplyResult[1] -eq $true){$FailedCount++$RootSite.URL + "`tFalse`tTrue" | Out-File $BJReportPath -Append}elseif($ApplyResult[0] -eq $false -and $ApplyResult[1] -eq $false){$FailedCount++$RootSite.URL + "`tFalse`tFalse" | Out-File $BJReportPath -Append}}}else{Write-Host -ForegroundColor Red "No site collection found in the web application...."}}}elseif($UserOption -eq 0){$SiteAccepted = $falsewhile($SiteAccepted -ne $true){$SiteCollURL = Read-Host -Prompt "Please Enter Site Collection URL"if(($SiteCollection = Get-SPSite $SiteCollURL -ErrorAction SilentlyContinue) -ne $null){Write-Host -ForegroundColor Green "Site Collection URL has been accepted..."$SiteTitle = $SiteCollection.RootWeb.Name.ToString().Replace(" ","_")$SiteAccepted = $true}else{Write-Host -ForegroundColor Red "Invalid input, please provide valid Site Collection URL"}}if($SiteAccepted -eq $true){$SiteCounter++#Write-Host "Calling function to activate Boldon James"#$ApplyResult = ApplyBoldonJamesServiceEndPoint $SiteCollURL $EndPointURL $ApplyResult = ApplyEndPointUsingIE $EndPointURL $SiteCollection.URLif($ApplyResult[0] -eq $true -and $ApplyResult[1] -eq $True){$SuccessCount++Write-Host -ForegroundColor Magenta "Feature Activation: " -NoNewlineWrite-Host -ForegroundColor Green "Passed"Write-Host -ForegroundColor Magenta "Applying EndPoint: " -NoNewlineWrite-Host -ForegroundColor Green "Passed"}elseif($ApplyResult[0] -eq $true -and $ApplyResult[1] -eq $false){$FailedCount++Write-Host -ForegroundColor Magenta "Feature Activation: " -NoNewlineWrite-Host -ForegroundColor Green "Passed"Write-Host -ForegroundColor Magenta "Applying EndPoint: " -NoNewlineWrite-Host -ForegroundColor Red "Failed"}elseif($ApplyResult[0] -eq $false -and $ApplyResult[1] -eq $true){$FailedCount++Write-Host -ForegroundColor Magenta "Feature Activation: " -NoNewlineWrite-Host -ForegroundColor Red "Failed"Write-Host -ForegroundColor Magenta "Applying EndPoint: " -NoNewlineWrite-Host -ForegroundColor Green "Passed"}elseif($ApplyResult[0] -eq $false -and $ApplyResult[1] -eq $false){$FailedCount++Write-Host -ForegroundColor Magenta "Feature Activation: " -NoNewlineWrite-Host -ForegroundColor Red "Failed"Write-Host -ForegroundColor Magenta "Applying EndPoint: " -NoNewlineWrite-Host -ForegroundColor Red "Failed"}}#$BJReportPath = $ScriptPath + "\" + "SiteCollection_" + $SiteTitle + "_BoldonJamesActivation_" + $ScriptDate + "_" + $ScriptTime + ".csv"}Write-Host -ForegroundColor Green "Script execution completed..."Write-Host -ForegroundColor Magenta "Please find below summary:"Write-Host -ForegroundColor Cyan "Total no. of sites processed: $siteCounter"Write-Host -ForegroundColor Green "No. of sites successful: $successCount"Write-Host -ForegroundColor Yellow "No of sites failed: $failedCount"if($UserOption -eq 1 -or $UserOption -eq 2){Write-Host -ForegroundColor DarkCyan "Find the detailed report at $BJReportPath ..."}Write-Host -ForegroundColor Cyan "=================================================="}else{Write-Host -ForegroundColor Red "Scope selection was not valid, terminating the exectuion..."Return}}else{Write-Host -ForegroundColor Red "SharePoint Snapin could not be loaded, terminating the execution..."} ................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download