Ever wish you could have a SharePoint migration automatically run when needed? Sharegate makes this possible with its newly integrated PowerShell commands. Now it’s simpler than ever to schedule your SharePoint migration with a little help from PowerShell. In this article we will demonstrate how quick and easy it is to have your scheduled PowerShell task up and running in no time!
For more information on the available commands, check out our detailed documentation with all the commands and how to use them.
Steps to Scheduling your SharePoint Migration with Sharegate
Write your PowerShell script in a text file using the Sharegate commands. Refer to the link above for the available commands.
Save the text file with the extension .ps1. Don’t forget where you save it.
Create a new task in Windows Task Scheduler and apply the PowerShell script.
Run your script and BOOM… you’ve setup your new automated SharePoint migration task!
Creating the PowerShell script in a text file
In our example we want to schedule a SharePoint list to be migrated after company hours. This will minimize the amount of traffic created during hours. First we will create our PowerShell script in a text file.
The script will first contain the Sharegate module we must import.
Next we will create variables for both the source ($srcSite) and the destination ($dstSite). This will create the connection to the Sharegate SharePoint migration tool.
Now that the source and the destination sites are connected, we will create a variable called $toCopy that will copy the source list.
Last piece of the script consists of copying the list over to the destination site which in our case is the variable $dstSite.
Saving the Script for our SharePoint migration
When saving the script we want to make sure we give the file an identifiable File Name ending with .ps1. The .ps1 extension will allow the file to run when called by PowerShell. In our example we will be saving the script on the C:.
Scheduling the SharePoint PowerShell script with Task Scheduler
To recap we have created the PowerShell script that will connect to both the source and destination sites, copy the source list and then place into the destination site. We then saved the file with the extension (.ps1) for it to run in the PowerShell console.
Windows Task Scheduler has many functions including the ability to automate scripts based on the information provided. Let’s check it out…
We will begin by launching Task Scheduler located in the Administrator Tools on the SharePoint server. We then will select “Create Task…” located on the right-side actions panel.
Let’s give the task a name, in our example we went with “Sharegate List Migration” and then type a description accurately labeling the task.
Next we will set up the triggers by selecting the Triggers tab.
The trigger section tells the task when to run by frequency, date, and time. Although we did not select the advanced settings, you will notice there are a few selections that can be checked if needed.
In our example we will only set the task to run once at a certain time and day. We must make sure we check Enabled before clicking OK.
Moving on to the Action tab, we will now tell the task what script to run. The Action will be to “Start a program”. In the Program/script field we want to enter in PowerShell.exe as the program of choice. Lastly we need to enter in the location of the script under the Add arguments field.
The last tab we will modify is the Conditions tab. The only change we want to make here is to uncheck “Start the task only if the computer is on AC power” and check “Wake the computer to run this task”. Click Ok in the New Action box and then again click Ok in the Task Properties box.
We did it! Once you have modified all the tabs, you should see your newly created task in the Task Scheduler’s list of tasks. You should also notice the status is labeled Ready along with a few other items such as the triggers, next run time, and last run time.
There you have it! A quick and easy way to automate your SharePoint migration by scheduling a task through a few PowerShell commands and the Windows Task Scheduler!