Table Of Content
SharePoint is emerging as the first preference for most of the organizations due to its amazing capabilities that allows you to efficiently share and manage content, knowledge and applications to search for information, empower teamwork and seamlessly collaborate across the organization. Its high precision in managing records can give your organization an edge with its scalable record management systems for business applications. Thus, migrating to SharePoint from either local sources or from older SharePoint versions turns out to be one of the best initiatives to utilize its core functionalities, such as security, data management and many more as well as to utilize it greatly to enhance business processes. The SharePoint migration tools come into play to accomplish this migration process in the most seamless way possible.
But most of the SharePoint migrators give you the option of just the automated or semi-automated selection of file systems to be migrated and seldom leaving any variation in the range of options for selective migration. As custom migration might be the specific need for some organizations either due to data limit on their part or due to time constraint, the option of manually migrating the files one by one in such cases is practically impossible for such a huge amount of data. This is where PowerShell migration comes into play.
Why PowerShell Scripting?
PowerShell is Microsoft’s cross platform open-source task automation and configuration management framework that consists of command line shell as well as associated scripting language. It provides an all-in-one efficient and streamlined solution to all the custom migration requirements that cannot be met by the predefined migration modules that the SharePoint Migration tools offer.
Third party migration tools provide either manual or pre-defined options for migrating the file systems from on premise or older versions of SharePoint to a newer one. Apart from that, PowerShell is based on .net framework where the administrative tasks are performed by cmdlets or commend-lets. It greatly improves the command-line and scripting environment by eliminating adding new features, enhancing the basic scripting efficiency and eliminating other long-standing problems. The user can write their own PowerShell commands to carry on the SharePoint migration the way they want.
Flow & Approach
Among the many paths to SharePoint migration, the common priority remains improving security, performance and velocity optimization. PowerShell migration is incredibly easy to plan and execute. While planning a PowerShell SharePoint Migration, one first needs to make a proper detailed plan about all the data that are to be migrated and their expected destination. Here are the steps to be followed:
Connecting Sources
Select the Source from where the data is to be migrated and the destination where it is to be migrated.
User Mapping
Mark all the missing users or those which need to be modified.
PowerShell Scripting
Write the PowerShell code according to your requirement.
Initiating the Migration
Just run the powershell code and let the migration happen.
Copy-Paste PowerShell Commands that you can readily use:

Connect Site
Connect-SKTSite
This command is used to connect SharePoint On-Premises and O365 sites, like central admin, site collection & sub site. There are various ways which are used to connect to SharePoint sites, which are explained below with syntax and example snippets. #Syntax
Connect-SKTSite [-Url] <String>
Connect-SKTSite [-Url] <String> [-Username] <String> [-SecurePassword] <SecureString>
Connect-SKTSite [-Url] <String> [-Username] <String> [-Password] <String>
Connect-SKTSite [-Url] <String> [-PSCredential] <PSCredential>
Connect-SKTSite [-Url] <String> [-CredentialsFrom] <Connection>
Connect-SKTSite [-Url] <String> [-Browser] <SwitchParameter> #Parameters
Url – The URL of the SharePoint OnPrem or SharePoint Online site to connect.
Username – A username/email/login name of the user used to connect to the SharePoint Site. If not specified, Default credentials will be used.
Password – Use this parameter to provide the password for the specified User to authenticate to the SharePoint.
Secure Password – Use this parameter to provide the password as a secure string for the specified User to authenticate to the SharePoint.
Browser – Use this parameter to authenticate to the SharePoint using Browser.
This is an optional parameter. When you use this parameter, it will open a browser window where it will load the site which is provided in the URL parameter. It will ask for credentials to log in to the site, after successful log in to the site, close the browser window and that should connect your site.
PSCredentials – The PSCredential object that contains the connection details of the SharePoint Site. It can be created using the inbuilt PowerShell cmdlet Get-Credential.
Credentials From – Use this parameter to reuse the credentials from the previously established connection object instead of manually providing them again. #Examples
Default Mode– Get the connection by providing the site URL. By default, the command will take the windows credentials to authenticate to the SharePoint site. This option is only applicable if the windows credentials are used to authenticate to the SharePoint site.
Connect-SKTSite -Url “https://sample.sharepoint.com“
Manual Mode (Secure Mode) –
Get the connection by providing the SharePoint site URL, username and password in secure string format. This can be used to secure your password so that it is not visible in the shell.
$SecurePass = “pass” | ConvertTo-SecureString -AsPlainText -Force
Connect-SKTSite -Url “https://sample.sharepoint.com” -Username “user” -SecurePassword $SecurePass
Manual Mode (Unsecure Mode) –
Get the connection by providing URL, username, and password in normal text, but this is unsecure as password will be visible in the shell.
Connect-SKTSite -Url “https://sample.sharepoint.com” -Username “user” -Password “pass”
Using Existing Connection Object –
Get the connection object for a site by using the previously established connection object. This is like reusing the credentials from the previously connected object to create a new connection instead of manually providing the credentials again.
$connection = Connect-SKTSite -Url “https://sample.sharepoint.com” -Username “user” -Password “pass”
Connect-SKTSite -Url “https://sample.sharepoint.com/sites/subsite” -CredentialsFrom $connection
Using PowerShell Credentials –
Get the connection by providing the SharePoint site URL and PSCredential object. This object can be created by using the built-in PowerShell cmdlet Get-Credential. Here connection dialog box appears where user can provide credentials to connect to the SharePoint Site.
$psCredential = Get-Credential
Connect-SKTSite “https://sample.sharepoint.com” -PSCredential $psCredential
Browser Mode: –
Get the connection object for the provided SharePoint URL via browser authentication. This command will open a browser window where it will ask for the credentials and after successful login close the browser window.
Connect-SKTSite -Url “https://sample.sharepoint.com” -Browser #Output
The connection object that contains the details of the connected Site.
SiteUrl – This property contains the connected site URL.
IsFBA – This property tells about the type of authentication for the site i.e. Form based authentication.
SiteName – This property contains the connected site name.
Environment – This property contains the information about the environment like On-Premises or Online.
RootSiteUrl – The root site URL of the connected site.
Credentials – The email/login name of the user used to authenticate the SharePoint Site.
SharePointVersion – The version of the SharePoint for which the connection is created.
AuthenticationType – The authentication type used for the connection.
IsCentralAdmin – True, If the connected site is a Central Admin or else False.
Get ListItems
Get-SKTListItem
This command is used to get the items from a SharePoint list. #Syntax
Get-SKTListItem [-ID] <int[]> [-List] <List> [-Connection] <Connection> #Parameters
ID – IDs of the items to get from SharePoint list. We can pass either single or array of IDs.
List – The list to get the items from. To get list from a SharePoint site, refer Get List.
Connection – The connection Object of the list. To get more information on establishing a connection to a site, refer Connect Site. #Examples
Get list items from a SharePoint list– Get the list items by providing the IDs, list and the connection object.
$connection = Connect-SKTSite -Url “https://sample.sharepoint.com” -Username “user” -Password “pass”
$list = Get-SKTList -Name “listName” -Connection $Connection
Get-SKTListItem -ID @(“5”, “8”, “18”) -List $list -Connection $connection
To get single list item: –
$connection = Connect-SKTSite -Url “https://sample.sharepoint.com” -Username “user” -Password “pass”
$list = Get-SKTList -Name “listName” -Connection $Connection
Get-SKTListItem -ID “5” -List $list -Connection $connection #Output
The details of the fetched folders.
Name – List item title.
Type – List item type.
Path – List item Path.
Created – List item created date.
Modified – List item last modified date.
Id – ID of the List item.
Get Folder
Get-SKTFolder
This command is used to get the folders from File System or SharePoint. #Syntax
Get-SKTFolder [-FolderPath] <string[]>
Get-SKTFolder [-FolderUrl] <string[]> [-Connection] <Connection>
Get-SKTFolder [-Library] <List> [-Connection] <Connection> #Parameters
FolderPath – Paths of the folders to get from File System. We can pass either path of the single folder or array of folder paths.
FolderUrl – URLs of the folders to get from SharePoint. You can pass single or array of URLs.
Library – Specify this parameter to get all the folders from a library. To get library from a SharePoint site, refer Get List.
Connection – The connection Object of the SharePoint folders to get. To get more information on establishing a connection to a site, refer Connect Site. #Examples
Get folders from File System– Get the folders by passing the file system folder path.
Get-SKTFolder -FolderPath @(“FileSystemFolderPath 1”, “FileSystemFolderPath 2”, “FileSystemFolderPath 3”)
To get single folder: –
Get-SKTFolder -FolderPath “FileSystemFolderPath”
Get folder info from SharePoint– Get the folders by passing the folder url and the connection object of the folders
$connection = Connect-SKTSite -Url “https://sample.sharepoint.com” -Username “user” -Password “pass”
Get-SKTFolder -FolderUrl @(“FolderFullUr 1”, “FolderFullUr 2”, “FolderFullUr 3”, “FolderFullUr 4”) -Connection $connection
To get single folder: –
$connection = Connect-SKTSite -Url “https://sample.sharepoint.com” -Username “user” -Password “pass”
Get-SKTFolder -FolderUrl “FolderFullUrl” -Connection $connection
Get all the folders from a SharePoint Library– Get the folders by providing the library and the connection object of the library.
$connection = Connect-SKTSite -Url “https://sample.sharepoint.com” -Username “user” -Password “pass”
$library = Get-SKTList -Name “documents” -Connection $connection
Get-SKTFolder -Library $library -Connection $connection #Output
The details of the fetched folders.
Name – Folder name.
Type – Folder type.
Path – Folder Path.
Created – Folder created date.
Modified – Folder last modified date.
Id – ID of the Folder.
FolderItemCount – Specifies the number of files present in the folder.
Get File
Get-SKTFile
This command is used to get the files from File System or SharePoint. #Syntax
Get-SKTFile [-FilePath] <string[]>
Get-SKTFile [-FileUrl] <string[]> [-Connection] <Connection>
Get-SKTFile [-Library] <List> [-Connection] <Connection> #Parameters
FilePath – Paths of the files to get from File System. We can pass either path of the single file or array of file paths.
FileUrl – Urls of the files to get from SharePoint. You can pass single or array of URLs.
Library – Specify this parameter to get all the files from a library. To get library from a SharePoint site, refer Get List.
Connection – The connection Object of the SharePoint files to get. To get more information on establishing a connection to a site, refer Connect Site. #Examples
Get file info from file system– Get the file by providing the file system path of the files.
Get-SKTFile -FilePath @(“FileSystemFilePath 1”, “FileSystemFilePath 2”, “FileSystemFilePath 3”)
To get single file: –
Get-SKTFile -FilePath “FileSystemFilePath”
Get file info from SharePoint– Get the files by providing the URL of the file and the connection object of the file.
$connection = Connect-SKTSite -Url “https://sample.sharepoint.com” -Username “user” -Password “pass”
Get-SKTFile -FileUrl @(“FileFullUrl 1”, “FileFullUrl 2”, “FileFullUrl 3”) -Connection $connection
To get single file: –
$connection = Connect-SKTSite -Url “https://sample.sharepoint.com” -Username “user” -Password “pass”
Get-SKTFile -FileUrl “FileFullUrl 1” -Connection $connection
Get all the files from a SharePoint Library– Get the files by providing the library and the connection object of the library.
$connection = Connect-SKTSite -Url “https://sample.sharepoint.com” -Username “user” -Password “pass”
$library = Get-SKTList -Name “documents” -Connection $connection
Get-SKTFile -Library $library -Connection $connection #Output
The details of the fetched files.
Name – File name.
Type – File type.
Path – File Path.
Created – File created date.
Modified – File last modified date.
Id – ID of the file.
Size – File size.
Delete Site
Remove-SKTSite
This command is used to delete webs from a SharePoint site. #Syntax
Remove-SKTSite [-Url] <String[]> [-Connection] <Connection>
Remove-SKTSite [-Site] <Site[]> [-Connection] <Connection> #Parameters
Url – Use this parameter to specify URLs of the webs to delete. You can pass either a single URL or multiple URLs.
Site – Use this parameter to specify the webs to delete. You can pass single or array of webs. To get web from a SharePoint site, refer Get Site.
Connection – Use this parameter to specify the connection Object of the SharePoint site to delete webs from. To get more information on establishing a connection to a site, refer Connect Site. #Examples
Delete webs by URLs– Delete the webs by providing their URLs and the connection object of the site.
$connection = Connect-SKTSite -Url “https://sample.sharepoint.com” -Username “user” -Password “pass”
Remove-SKTSite -Url @(“https://sample.sharepoint.com/sites/subsite1”, “https://sample.sharepoint.com/sites/subsite2”) -Connection $connection
To delete single site by Url: –
$connection = Connect-SKTSite -Url “https://sample.sharepoint.com” -Username “user” -Password “pass”
Remove-SKTSite -Url “https://sample.sharepoint.com/sites/subsite” -Connection $connection
Delete webs– Delete the webs by passing the webs and the connection object of the site.
$connection = Connect-SKTSite -Url “https://sample.sharepoint.com” -Username “user” -Password “pass”
$sites = Get-SKTSite -Connection $connection
Remove-SKTSite -Site $sites -Connection $connection #Output
The details specifying whether each web is deleted successfully.
Delete Permission
Remove-SKTPermission
This command is used to get content types from a SharePoint site. #Syntax
Remove-SKTPermission [-ID] <String[]> [-Connection] <Connection>
Remove-SKTPermission [-Permission] <Permission[]> [-Connection] <Connection>
Remove-SKTPermission [-Name] <String[]> [-Connection] <Connection> #Parameters
ID – IDs of the permission levels to delete. You can pass single id or array of IDs of Permission levels.
Name – Names of the permission levels to delete. You can pass single name or array of names of Permission levels.
Permission – Permissions to delete. You can pass single or array of Permission levels. To get permissions, refer Get Permission.
Connection – The connection object to delete permission levels from. To get more information on establishing a connection refer, Connect Site. #Examples
Delete permissions– Delete the permission levels of a site by providing the connection of the site.
$connection = Connect-SKTSite -Url “https://sample.sharepoint.com” -Username “user” -Password “pass”
$permissions = Get-SKTPermission -Connection $connection
Remove-SKTPermission -Permission $permissions -Connection $connection
Delete permissions by name– Delete the permission levels by providing their names and the connection of the site.
$connection = Connect-SKTSite -Url “https://sample.sharepoint.com” -Username “user” -Password “pass”
Remove-SKTPermission -Name @(“perm 1”, “perm 2”, “perm 3”) -Connection $connection
To delete single permission level by name: –
$connection = Connect-SKTSite -Url “https://sample.sharepoint.com” -Username “user” -Password “pass”
Remove-SKTPermission -Name “perm 1” -Connection $connection
Delete permissions by ID– Delete the permission levels by providing their IDs and the connection of the site.
$connection = Connect-SKTSite -Url “https://sample.sharepoint.com” -Username “user” -Password “pass”
Remove-SKTPermission -ID @(“ 1073741825”, “1073741827”, “1073741828”) -Connection $connection
To delete single permission level by ID: –
$connection = Connect-SKTSite -Url “https://sample.sharepoint.com” -Username “user” -Password “pass”
Remove-SKTPermission -ID “1073741828” -Connection $connection #Output
The details specifying whether each permission level is deleted successfully.
Delete Content
Remove-SKTContent
This command is used to delete the content (list items/files/folders) of a SharePoint list or library. #Syntax
Remove-SKTContent [-ID] <int[]> [-List] <List> [-Connection] <Connection>
Remove-SKTContent [-File] <PSFile[]> [-List] <List> [-Connection] <Connection>
Remove-SKTContent [-Folder] <PSFolder[]> [-List] <List> [-Connection] <Connection>
Remove-SKTContent [-ListItem] <ListItem[]> [-List] <List> [-Connection] <Connection> #Parameters
ID – IDs of the list items/files/folders to delete. You can pass single ID or array of IDs.
File – SharePoint files to delete. You can pass single file or array of files. To get files, refer Get File.
Folder – SharePoint folders to delete. You can pass single folder or array of folders to delete. To get folders, refer Get Folder.
ListItem – The list items to delete. You can pass single or multiple list items to delete. To get list items from a SharePoint list, refer Get List Item.
Connection – The connection object of the source content to delete. To get more information to connect to a site, refer Connect Site. #Examples
Delete the content of list or library by IDs– Delete the content by passing the item/file/folder IDs, list or library to delete items from and the connection object of the items.
$connection = Connect-SKTSite -Url “https://sample.sharepoint.com” -Username “user” -Password “pass”
$list = Get-SKTList -Name “documents” -Connection $ connection
Remove-SKTContent -ID @(1,21,3,4,10) -List $list -Connection $connection
Delete the files from a SharePoint Library– Delete the files by passing the files, library and the connection object.
$connection = Connect-SKTSite -Url “https://sample.sharepoint.com” -Username “user” -Password “pass”
$library = Get-SKTList -Name “documents” -Connection $ connection
$files = Get-SKTFile -FileUrl @(“site/documents/file1”,”site/documents/file5”) -Connection $connection
Remove-SKTContent -File $files -List $library -Connection $connection
Delete the folders from a SharePoint Library– Delete the folders by passing the folders, library and the connection object.
$connection = Connect-SKTSite -Url “https://sample.sharepoint.com” -Username “user” -Password “pass”
$library = Get-SKTList -Name “documents” -Connection $ connection
$folders = Get-SKTFile -FileUrl @(“site/documents/folder1”,”site/documents/folder5”) -Connection $connection
Remove-SKTContent -Folder $folders -List $library -Connection $connection
Delete the list items from a SharePoint List– Delete the items by passing the list items, list and the connection object.
$connection = Connect-SKTSite -Url “https://sample.sharepoint.com” -Username “user” -Password “pass”
$list = Get-SKTList -Name “list1” -Connection $ connection
$listItems = Get-SKTListItem -ID @(1,11,111) -Connection $connection
Remove-SKTContent -ListItem $ listItems -List $list -Connection $connection #Output
The details specifying whether each item/file/folder is deleted successfully.
For more such sample codes, refer to our knowledge bank or try it yourself on the Saketa SharePoint Migrator.