How to do a full site collecion level re-index in sharepoint online? - sharepoint

After adding a new managed property I need to do a full site collection level or tenant level re-indexing to get the search crawler run. But I could not find a way to do this in SharePoint online.Is there a way to do this?

There is a script to re-index a SharePoint online site collection via CSOM. I think this will help you to re-index your 100+ subsites.
#Grab the tenant information
$username = Read-Host "Enter the tenant admin account login"
$password = Read-host -AsSecureString "Enter the admin account password"
$siteUrl = Read-Host "Please enter the site collection URL to re-index"
Write-Host "Would you like to populate the managed properties on all lists post re-crawl (ex. Cross Site Publishing)?" -ForegroundColor Green
Write-Host "1. Yes - enable managed properties on all lists in this site!" -ForegroundColor Cyan
Write-Host "2. No - Turn off managed properties in all lists in the site!" -ForegroundColor Blue
Write-Host "3. No - Just re-index the site!" -ForegroundColor Red
$enableAllManagedProperties = Read-Host "Choice [1-3]?"
$date = (Get-Date).ToString("yyyyMMdd")
#Load the assemblies
$load1 = [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client")
$load2 = [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.Runtime")
$load3 = [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.UserProfiles")
if (!$load1) {
$script_folder = (Split-Path -Parent $MyInvocation.MyCommand.Path)
$load1 = [System.Reflection.Assembly]::LoadFile($script_folder + "\Microsoft.SharePoint.Client.dll")
if (!$load1) {
Write-Host "Failed to load Microsoft.SharePoint.Client.dll - please ensure it is in the same location as the PS1." -ForegroundColor Red
write-host "Alternatively, install the SPO Client Components SDK from http://www.microsoft.com/en-us/download/details.aspx?id=42038" -ForegroundColor Red
exit;
}
}
if (!$load2) {
$script_folder = (Split-Path -Parent $MyInvocation.MyCommand.Path)
$load2 = [System.Reflection.Assembly]::LoadFile($script_folder + "\Microsoft.SharePoint.Client.Runtime.dll")
if (!$load2) {
Write-Host "Failed to load Microsoft.SharePoint.Client.Runtime.dll - please ensure it is in the same location as the PS1." -ForegroundColor Red
write-host "Alternatively, install the SPO Client Components SDK from http://www.microsoft.com/en-us/download/details.aspx?id=42038" -ForegroundColor Red
exit;
}
}
if (!$load3) {
$script_folder = (Split-Path -Parent $MyInvocation.MyCommand.Path)
$load3 = [System.Reflection.Assembly]::LoadFile($script_folder + "\Microsoft.SharePoint.Client.UserProfiles.dll")
if (!$load3) {
Write-Host "Failed to load Microsoft.SharePoint.Client.UserProfiles.dll - please ensure it is in the same location as the PS1." -ForegroundColor Red
write-host "Alternatively, install the SPO Client Components SDK from http://www.microsoft.com/en-us/download/details.aspx?id=42038" -ForegroundColor Red
exit;
}
}
function Connect-SPO($siteUrl) {
$clientContext = New-Object Microsoft.SharePoint.Client.ClientContext($siteUrl)
$clientContext.Credentials = $credentials
if (!$clientContext.ServerObjectIsNull.Value) {
Write-Host "Connected to SharePoint Online site: '$siteUrl'" -ForegroundColor Green
}
$rootWeb = $clientContext.Web
processWeb($rootweb)
}
function processWeb($web) {
$subWebs = $web.Webs
$clientContext.Load($web)
$clientContext.Load($web.AllProperties)
$clientContext.Load($subWebs)
try
{
$clientContext.ExecuteQuery()
}
catch
{
write-host "Error on $($clientContext) - $($_)" -ForegroundColor Red
Write-Host "It's possible you are not an administrator on the site collection - Exiting the script" -ForegroundColor Red
Sleep 10
Exit
}
Write-Host "Web URL:" $web.Url -ForegroundColor White
if ( $enableAllManagedProperties -ne "3" ) {
Set-AllManagedProperties -web $web -clientContext $clientContext -enableAllManagedProps $enableAllManagedProperties
}
[int]$version = 0
$allProperties = $web.AllProperties
if ( $allProperties.FieldValues.ContainsKey("vti_searchversion") -eq $true ) {
$version = $allProperties["vti_searchversion"]
}
$version++
$allProperties["vti_searchversion"] = $version
Write-Host "-- Updated search version: " $version -ForegroundColor Green
$web.Update()
$clientContext.ExecuteQuery()
# No need to process subwebs if we only mark site collection for indexing
if ($enableAllManagedProperties -ne "3") {
foreach ($subWeb in $subWebs) {
processWeb($subWeb)
}
}
}
function Set-AllManagedProperties( $web, $clientContext, $enableAllManagedProps ) {
$lists = $web.Lists
$clientContext.Load($lists)
$clientContext.ExecuteQuery()
foreach ($list in $lists) {
Write-Host "--" $list.Title
if ( $list.NoCrawl ) {
Write-Host "-- Skipping list due to not being crawled" -ForegroundColor Yellow
continue
}
$skip = $false;
$eventReceivers = $list.EventReceivers
$clientContext.Load($eventReceivers)
$clientContext.ExecuteQuery()
foreach ( $eventReceiver in $eventReceivers ) {
if ( $eventReceiver.ReceiverClass -eq "Microsoft.SharePoint.Publishing.CatalogEventReceiver" ) {
$skip = $true
Write-Host "-- Skipping list as it's published as a catalog" -ForegroundColor Yellow
break
}
}
if ( $skip ) {continue}
$folder = $list.RootFolder
$props = $folder.Properties
$clientContext.Load($folder)
$clientContext.Load($props)
$clientContext.ExecuteQuery()
if ( $enableAllManagedProps -eq "1" ) {
Write-Host "-- Enabling all managed properties" -ForegroundColor Green
$props["vti_indexedpropertykeys"] = "UAB1AGIAbABpAHMAaABpAG4AZwBDAGEAdABhAGwAbwBnAFMAZQB0AHQAaQBuAGcAcwA=|SQBzAFAAdQBiAGwAaQBzAGgAaQBuAGcAQwBhAHQAYQBsAG8AZwA=|"
$props["IsPublishingCatalog"] = "True"
}
if ( $enableAllManagedProps -eq "2" ) {
Write-Host "-- Disabling all managed properties" -ForegroundColor Green
$props["vti_indexedpropertykeys"] = $null
$props["IsPublishingCatalog"] = $null
}
$folder.Update()
$clientContext.ExecuteQuery()
}
}
#SPO Credentials
$credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $Password)
Connect-SPO -siteUrl $siteurl
if ($version -ne "$null" ) {
Write-Host "Re-index has should now have been succesfully triggered for $siteurl - Please remember that this can take some time before the crawl picks up the index." -ForegroundColor Cyan
}
https://gallery.technet.microsoft.com/office/Re-index-a-Sharepoint-e70d285b
Note: This will not improve crawl time, merely ensure items are re-indexed.

You need to go to the Site Settings > Search and Offline Availability link and then press the reindex option as in below image.
You need to be site collection admin or owner to view these settings:
Updated as per comments:
To trigger a full site collections reindex, you need to make use of PS script as in this link.

Related

how to view ssas analysis services roles using nodejs

how to view SSAS analysis services roles and assign that roles to related users
using programming languages like nodejs
I have tried PowerShell code but i dont know how to assign roles;just i saw roles
$SourceInstance = "SERVER\Node"
$RoleName = "BUSINESSROLE"
$Username = "DOMAIN\USERNAME" [System.reflection.Assembly]::LoadWithPartialName("Microsoft.AnalysisServices") | Out-Null
$mySourceServer = new-Object Microsoft.AnalysisServices.Server
$mySourceServer.Connect($SourceInstance)
[Microsoft.AnalysisServices.Database[]] $mySourceDatabases = #()
$mySourceDatabases = $mySourceServer.Databases
foreach ($mySourceDB in $mySourceDatabases)
{
[Microsoft.AnalysisServices.Role]$myRole = $null
$myRole = $mySourceDB.Roles.FindByName($RoleName)
if($myRole -ne $null)
{
Write-Host " $mySourceDB : " -ForegroundColor Green
foreach ($myMember in $myRole.Members)
{
if( $myMember.Name -contains $Username)
{
Write-Host " " $myMember.Name -ForegroundColor yellow
}
}
}
}
$mySourceServer.Disconnect()

Error: Cannot find an overload for "restore" and the argument count: "1"

I am getting this error from the following code. It's coming from $Context.Load($RecycleBinItems). Any idea what's wrong with the code? I am attempting to restore all recyclebin items.
Add-Type -Path "C:\Program Files\WindowsPowerShell\Modules\SharePointPnPPowerShellOnline\3.17.2001.2\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\WindowsPowerShell\Modules\SharePointPnPPowerShellOnline\3.17.2001.2\Microsoft.SharePoint.Client.Runtime.dll"
Import-Module 'Microsoft.PowerShell.Security'
#Get the Site Owners Credentials to connect the SharePoint
$SiteUrl = "https://phaselinknet.sharepoint.com"
$UserName = Read-host "Enter the Email ID"
$Password = Read-host - assecurestring "Enter Password for $AdminUserName"
$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($UserName, $Password)
# Once Connected, get the Site information using current Context objects
Try {
$Context = New-Object Microsoft.SharePoint.Client.ClientContext($SiteUrl)
$Context.Credentials = $Credentials
$Site = $Context.Site
$RecycleBinItems = $Site.RecycleBin
$Context.Load($Site)
$Context.Load($RecycleBinItems)
$Context.ExecuteQuery()
Write-Host "Total Number of Files found in Recycle Bin:" $RecycleBinItems.Count
}
catch {
write - host "Error: $($_.Exception.Message)" - foregroundcolor Red
}
# using for loop to restore the item one by one
Try {
if($RecycleBinItems)
{
foreach($Item in $RecycleBinItems)
{
$Site.RecycleBin.restore($Item.ID)
#Write-Host "Item restored:"$Item.Title
}
}
}
catch {
write-host "Error: $($_.Exception.Message)" -foregroundcolor Red
}
The error message is giving you you answer. There is not a version of the method Restore that takes 1 parameter.
You need to load up a list of items simular to this
$Item = $RecycleBin | Where{$_.Title -eq $ItemName}
Then call restore for the items.
if($Item -ne $null)
{
$Item.Restore()
}
Thanks for the tip. So I load up the first 10 items in the recyclebin, and Write-Host does write out the correct files, but the $Item.Restore() does noting as the files are still not restored:
$itemsToRestore = #()
for ($i = 0; $i -lt 10; $i++)
{
$Item = $RecycleBinItems[$i]
$itemsToRestore += $Item
}
Write-Host "Total Number of Files to Restore:" $itemsToRestore.Count
foreach($item in $itemsToRestore)
{
Write-Host "Item:" $Item.Title
$item.Restore()
}
I found the problem. I missed $Context.ExecuteQuery() after $Item.Restore(). It works now.

Get programmatically User Roles and Permissions in SSRS 2008

I use SSRS 2008 on Windows 2008 R2.
How can I get the user list of roles and permissions (Reports Manager Roles such as Browser, Content Manager, etc) using Powershell or C# (programmatically)?
Any suggestions ?
Notes:
"Folder Settings" area where you can specify roles for a user - "Content Manager," "Publisher," "Browser," "Report Builder," and "My Reports"
SSRS has 2 security/role sections available in the web GUI: Folder Settings and Site Settings.
I try with my script powershell.
References: http://www.bi-rootdata.com/2015/03/list-ssrs-items-permissions-using.html by Anup Agrawal comment
Usage:
$ScriptDirectory = Split-Path $MyInvocation.MyCommand.Path
Clear-Host
Write-Host $ScriptDirectory
Write-Host $env:COMPUTERNAME -ForegroundColor Yellow
Write-Host $env:USERNAME -ForegroundColor Yellow
$ReportServerUri = 'http://localhost/ReportServer/ReportService2005.asmx'
$InheritParent = $true
$SourceFolderPath = '/'
$outSSRSSecurity=#()
$Proxy = New-WebServiceProxy -Uri $ReportServerUri -Namespace SSRS.ReportingService2005 -UseDefaultCredential
$items = $Proxy.ListChildren($sourceFolderPath, $true)|Select-Object Type, Path, Name|Where-Object {$_.type -eq "Folder"};
foreach($item in $items)
{
#Write-Host $item
if ($item.Name -ne "TestsCustomCDR")
{
#continue;
}
Write-Host $item.Path -ForegroundColor Yellow
Write-Host $item.Name -ForegroundColor Green
Add-Member -InputObject $item -MemberType NoteProperty -Name PolicyGroupUserName -Value '';
foreach($policy in $Proxy.GetPolicies($item.path, [ref]$InheritParent))
{
Write-Host $policy.GroupUserName
$objtemp=$item.PsObject.Copy();
$objtemp.PolicyGroupUserName=$policy.GroupUserName;
$outSSRSSecurity += $objtemp;
$objtemp.reset;
}
}
$outSSRSSecurity|Export-csv SSRSSecurityOutput.csv -NoTypeInformation;

Change multiple files content type programatically using CSOM for SharePoint Online

I am attempting to change all the files in a library from one content type to another. This is in SharePoint Online so I'm using the CSOM. I am new to this so I'm stuck at where to go from what I have below.
I think my biggest issue is getting the values of the content types. That and I'm so used to SP On Premise I'm having trouble grasping this CSOM stuff. Much thanks to anyone that can help point me in the right direction!
#Load necessary module to connect to SPOService
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client") | Out-Null
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.Runtime") | Out-Null
#Login Information for script
$User = "user"
$Pass = "password"
$WebUrl = "SiteURL"
#Connect to SharePoint Online service
Write-Host "Logging into SharePoint online service." -ForegroundColor Green
$Context = New-Object Microsoft.SharePoint.Client.ClientContext($WebUrl)
$Context.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($User, (ConvertTo-SecureString $Pass -AsPlainText -Force))
#Get the Necessary List
Write-Host "Getting the required list." -ForegroundColor Green
$List = $Context.Web.Lists.GetByTitle("TestLibrary")
Write-Host "Getting the Content Types." -ForegroundColor Green
$oldCT = $list.ContentTypes("OldCTName")
$newCT = $list.ContentTypes("NewCTName")
$newCTID = $newCT.ID
$Query = [Microsoft.SharePoint.Client.CamlQuery]::CreateAllItemsQuery(1000);
$Items = $List.GetItems($Query);
$Context.Load($Items);
$Context.ExecuteQuery();
#Check if the values specified for the content types actually exist on the list
if (($oldCT -ne $null) -and ($newCT -ne $null))
{
#Go through each item in the list
#Edit existing list items
foreach($item in $Items)
{
#Check if the item content type currently equals the old content type specified
if ($_.ContentType.Name -eq $oldCT.Name)
{
#Check the check out status of the file
if ($_.File.CheckOutType -eq "None")
{
#Change the content type association for the item
$_.File.CheckOut()
write-host "Resetting content type for file" $_.Name "from" $oldCT.Name "to" $newCT.Name
$_["ContentTypeId"] = $newCTID
$_.Update()
$_.File.CheckIn("Content type changed to " + $newCT.Name, 1)
}
else
{
write-host "File" $_.Name "is checked out to" $_.File.CheckedOutByUser.ToString() "and cannot be modified"
}
}
else
{
write-host "File" $_.Name "is associated with the content type" $_.ContentType.Name "and shall not be modified"
}
}
}
else
{
write-host "One of the content types specified has not been attached to the list"$list.Title
}
$Context.ExecuteQuery();
}

Enabling Sharepoint Features With Powershell

I am new to PowerShell and have been asked to modify a script that is used to activate features on a site. The script has some latency issues between the two feature activations, so I decided to make a new function that will enable the feature and sleep or delay until the feature is finished enabling. Will this work? And if so, how can I tell that the feature is finished activating?
# This is a function that enable's a Sharepoint Feature and Sleeps Until Its Finished Enabling
function Feature-Enable
{param ([string]$ID, [string]$URL)
#Enable Feature
Enable-SPFeature -Identity $ID -url $URL -Confirm:$false
#Sleep Until Feature is Done Enabling
}
#Set parameters/variables for script
$serverName = "someServerName"
$rootwebUrl = "someRootUrl"
$currentpath=Split-Path -Path $MyInvocation.MyCommand.Path -Parent
$siteURL = "http://" + $servername + $rootwebURL
$start = Get-Date -DisplayHint Time
# check to ensure Microsoft.SharePoint.PowerShell is loaded
$snapin = Get-PSSnapin | Where-Object {$_.Name -eq 'Microsoft.SharePoint.Powershell'}
if ($snapin -eq $null) {
Write-Host "Loading SharePoint Powershell Snapin"
Add-PSSnapin "Microsoft.SharePoint.Powershell"
}
# Active Site Collection Features (in order)
write-host ""
write-host "----------------------------------------"
write-host "Begin activation of site collection features"
write-host "----------------------------------------"
write-host ""
Feature-Enable –identity "3cbf5d1e-ff2e-48d2-82a4-99b060381268" -URL $siteUrl
#NOTE: POTENTIAL LATENCY ISSUES. MAY NEED TO INSERT DELAY TIMER!
Feature-Enable –identity "bbde524e-9293-468e-84f7-fdb763ffa309" -URL $siteUrl
write-host ""
write-host "----------------------------------------"
write-host "Activation of site collection features - DONE!"
write-host "----------------------------------------"
write-host ""
$end= Get-Date -DisplayHint Time
Write-Host "Started at: " $start " Ended at: " $end;
function WaitForJobToFinish([string]$SolutionFileName)
{
$JobName = "*solution-deployment*$SolutionFileName*"
$job = Get-SPTimerJob | ?{ $_.Name -like $JobName }
if ($job -eq $null)
{
Write-Host 'Timer job not found'
}
else
{
$JobFullName = $job.Name
Write-Host -NoNewLine "Waiting to finish job $JobFullName"
while ((Get-SPTimerJob $JobFullName) -ne $null)
{
Write-Host -NoNewLine .
Start-Sleep -Seconds 2
}
Write-Host "Finished waiting for job.."
}
}

Resources