Sunday, 6 December 2020

Change SharePoint Online list or library Internal name

 Change SharePoint Online list or library Internal name 

Issue:

Recently we have provided a build and guideline document to our client and by mistake they have set up a library with wrong internal name. In starting it worked well but as the additional functionality added, it broke. As the users have started working on that, we needed to fix the internal name anyway. 

Our library internal name is “TrainingDocuments” and display name is “Training Documents”. While Client has set up “Training Documents”.



Solution

Initially we thought it might be not possible. But then we found 2 ways to do it:

Approach 1: Using SharePoint Designer 2013

Follow below steps to fix this using SharePoint Designer 2013:

  1. In SharePoint Designer, Open your site.
  2. Navigate to All Files navigation node (not List and Libraries node),
    Note – you will need “Site Collection Administrator” permission in the site collection to see “All Files” option.
  3. Find your list there
  4. Right-click list
  5. Rename.



Approach 2 : Using PNP PowerShell

In case you are not able to connect the site in the SharePoint designer or you do not have installed in your machine, you can do this using PNP PowerShell as well. 


PowerShell to change Library Name:

 #Set Parameters  
 $SiteURL = "Site URL"  
 $ListName = "Library Internal Name"  
 $NewListURL = "New Library Name"  
 #Connect to PNP Online  
 Connect-PnPOnline -Url $SiteURL -Credentials (Get-Credential)  
  #this will change URL  
 #Get the List  
 $List= Get-PnPList -Identity $ListName -Includes RootFolder  
 #sharepoint online powershell change list url  
 $List.Rootfolder.MoveTo($NewListURL)  
 Invoke-PnPQuery  
 #this will change library title  
 Set-PnPList -Identity $ListName -Title $NewListURL  


PowerShell to change List Name:

 #Set Parameters  
 $SiteURL = "Site URL"  
 $ListName = "Library Internal Name"  
 $NewListURL = "New Library Name"  
 #Connect to PNP Online  
 Connect-PnPOnline -Url $SiteURL -Credentials (Get-Credential)  
 Set-PnPList -Identity $ListName -Title $NewListURL  

File server migration to SharePoint online using SPMT PowerShell Part 2

In previous blog we have go through the csv creation part. You can find it on below link:

In this blog, we are going to use that file and SPMT migration PowerShell commands to migrate file server to SharePoint online.

Prerequisite

SharePoint Migration Tool needs to be installed in the machine

Solution

First, we are going to get credentials for

 Import-Module Microsoft.SharePoint.MigrationTool.PowerShell  
 $Global:SPOUrl = "SharePoint site collection url"  
 $Global:UserName = "username"  
 $Global:PassWord = ConvertTo-SecureString -String "Password" -AsPlainText -Force  
 $Global:SPOCredential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $Global:UserName, $Global:PassWord  

 

After this we will read csv file

 #Load CSV  
 $csvItems = import-csv "C:\Migration\migrationscript.csv" -Header c1,c2,c3,c4,c5,c6  

 

Now we will register migration task. This needs to be done once for all migration task. So we will keep this out of for loop

 Register-SPMTMigration -SPOCredential $Global:SPOCredential -Force -MigrateWithoutRootFolder -PreserveUserPermissionsForFileShare $true  

 

We are passing below two parameters

  1. MigrateWithoutRootFolder – This will not migrate parent folder. Only items withing the given path directory will be migrated. This is not mentioned in the MSDN link, but it is mentioned in the build changes document. This was included in build –  3.4.119.7

  2. PreserveUserPermissionsForFileShare – This parameter is used if you want to migrate file server permission to SharePoint online

 

Now we will loop through csv file and add migration task.

 ForEach ($item in $csvItems)  
 {       
   Write-Host $item.c1  
   Add-SPMTTask -FileShareSource $item.c1 -TargetSiteUrl $item.c4 -TargetList $item.c5 -TargetListRelativePath "/"  
 }  

 

After this we will start migration

 Start-SPMTMigration  

 

The full PowerShell will look like below:

 Import-Module Microsoft.SharePoint.MigrationTool.PowerShell  
 $Global:SPOUrl = "SharePoint site collection url"  
 $Global:UserName = "username"  
 $Global:PassWord = ConvertTo-SecureString -String "Password" -AsPlainText -Force  
 $Global:SPOCredential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $Global:UserName, $Global:PassWord  
 #Load CSV  
 $csvItems = import-csv "C:\Migration\migrationscript.csv" -Header c1,c2,c3,c4,c5,c6  
 Register-SPMTMigration -SPOCredential $Global:SPOCredential -Force -MigrateWithoutRootFolder -PreserveUserPermissionsForFileShare $true  
 ForEach ($item in $csvItems)  
 {  
   Write-Host $item.c1  
   Add-SPMTTask -FileShareSource $item.c1 -TargetSiteUrl $item.c4 -TargetList $item.c5 -TargetListRelativePath "/"  
 }  
 Start-SPMTMigration  

 

Reference

File server migration to SharePoint online using SPMT PowerShell Part 1

Recently we have a project where we need to migrate file server to SharePoint Online. So, we decided to go with SharePoint Migration Tool (SPMT). But we had 50 plus folders and all were needed to migrate to different sites documents library. As it takes long time to migrate using tool due to creating connection, we decided to use PowerShell version.

 

Issue

We faced below issues in this requirement:

  1. The documentation for this is not that accurate or in single place. We need to search here and there for things.
  2. SPMT tool migrates file server child items directly but when you use PowerShell, it migrates parent folder. Due to curse of first point, it took some time for us to find the hidden solution. Go through this post to see that hidden gem.
  3. The last but no least is permission migration. SPMT has all this functionality but as I said earlier it is not documented well.

So, we will try to explain all our knowledge in detail here.

 

Solution -

 

First, we need to prepare a csv which will be read by PowerShell and It will have connection details of source and migration.

important notes for preparing csv:

  1. Do not include a header row in your CSV file.
  2. Remember to account for all six columns in the file, even if you are not needing a value for a given field.
  3. If you use the standard out-of-the-box Document library ("Shared Documents"), you must use the Display name "Documents" as the placeholder value for the Target Document Library in your CSV file. If you enter "Shared Documents" in that column, you will receive an "invalid document library" error.

Note - If the language of the destination SharePoint site is other than English, check the Display name of the "Shared Documents" Document library by browsing to Documents library.

The format of csv is as below:

Source,SourceDocLib,SourceSubFolder,TargetWeb,TargetDocLib,TargetSubFolder


As we are migrating from file server, we will not pass the “SourceDocLib” & “SourceSubFolder” details. So, our csv detail will look like below:

File server path,,, TargetWeb,TargetDocLib,TargetSubFolder

For example,

C:\MigrationTests\testfiles,,,https://contoso.sharepoint.com/sites/Sample/,DocLibraryName,DocLibraryName_subfolder

 

In case, you don’t want to migrate it to sub folder, the subfolder part will be blank

File server path,,, TargetWeb,TargetDocLib,

For example,

C:\MigrationTests\testfiles,,,https://contoso.sharepoint.com/sites/Sample/,DocLibraryName,

In next blog we will use this csv in the PowerShell.

Reference:
  1. https://docs.microsoft.com/en-us/sharepointmigration/how-to-format-your-csv-file-for-data-content-migration#:~:text=number%20of%20tasks.-,Using%20a%20comma%20separated%20value%20(CSV)%20file%20for%20data%20content,to%20create%20the%20CSV%20file