In order to create a PowerShell (PS) script for Content Matrix, a job list (or batch file) must first exist in the Job List section of the SharePoint Edition client application. Once created, it can be run from the PowerShell console or scheduled to run as a Windows Scheduled task.
NOTE: It is recommended that the connections to the source and target environments have the Remember my password check-box selected. This is to ensure that the PowerShell scripts will be able to establish a connection to both the source and target environments when they are being run. If a password is required and this check-box is not set, the migration will fail. However, users can manually enter this value into the PowerShell script itself if the option was not checked when the script was first generated.
To create a PowerShell script:
1.In Job List, and select the job (or jobs) that you want to run in PowerShell.
2.Click the Generate PowerShell Script button in the Job List tool bar, or right-click on one of the items and select Generate PowerShell Script from the context menu.
3.From the drop-down, choose the appropriate option. Use the information in the following table for guidance.
If you want to generate a PowerShell script for scheduling
that can be used only by the currently logged in User Account on the machine it is generated on
For Current User and Machine.
NOTE: Any PowerShell scripts that are generated for scheduling through this option can only be run by the logged in user on the machine they were generated on.
that can be used by any User account on the machine it is generated on
For Local Machine.
that can be used by any User account on any machine that has the certificate that is specified when the script is created
When you save the PowerShell script using this method you will be prompted to select a security certificate that exist on that machine. The selected certificate will be required on any system that attempts to run the script at a later date.
Once the PS script generation type is selected, Content Matrix Console will generate a PS script for the select Job, which will be written to a Microsoft Notepad file. If multiple jobs are selected they will all be written to the same file.
4.Choose File > Save As... and select any desired save location for the PowerShell script. Give the file any name you want, but change the file type to .PS1.
The PowerShell (PS) script itself contains five sections. They are:
·Section 1 - This first section at the top (starting with an "if" statement) runs a check in the PowerShell console to make sure that the Metalogix snap-pins have been added. If they are not found then it will add them to that instance of the PS console.
·Section 2 - Load Configuration settings - This section will find and load all of the Metalogix Content Matrix client application configuration settings into the PowerShell script. These are the client application's environmental settings and not the migration/action settings.
·Section 3 - Load source - This section will load all of the data for the source environment connection.
·Section 4 - Load target - Similar to the previous section, this will load target environment's connection information.
·Section 5 - Run the action - Last is the "Run the action" section. This last section will contain all of the other data for the migration, such as the type of migration (i.e. a site migration, list migration, item migration, etc.) and all of the settings and configurations for the migration/action that is being run. This includes things like settings for versions, content types, permissions, etc.
Once a PowerShell script has been created, you can run it from the PowerShell console.
To run the PowerShell script:
1.On your desktop open the Metalogix Content Matrix Console - SharePoint Edition PowerShell Console shortcut, for the PowerShell window with the Metalogix plug-ins and snap-ins already installed.
In the PowerShell window you can set yourself to act from any desired directory. In some cases users will set themselves to the same directory that contains their PowerShell scripts.
2.Enter the name and extension of the PowerShell Script (at its specified location), and the script will run.
In the case that you are running a script from the same directory you would use the format: .\[ScriptName].ps1. So if your PowerShell scrip was named "ResourceScript.ps1" then you would enter: .\ResourceScript.ps1 into the window, and the script would run.
If the script is in a different directory, you would enter the location of that directory relative to your current location, followed by the script name. For example, if your prompt is at the "C:\" drive and your PowerShell script, named "ResourceScript.ps1" is on the desktop you would enter: C:\Users\[User]\Desktop\ResourceScript.ps1, and the script would run.
NOTE: In some cases the Execution Policy may prevent you from running a PowerShell script. In this case you will likely see the message: [Script].ps1 cannot be loaded because the execution of scripts is disabled on this system. Please see "get-help about_signing" for more details. In this case, running the command: set-executionpolicy RemoteSigned should change the existing script policy to allow you to run these scripts for your location. It is advised that you check with your System Administrators before doing this to ensure that no Company Policies are being broken by this action. If this is an action you need to take, you should only need to run this command once.
The migration will begin, and any warnings and/or errors that are encountered in running the script will be displayed in the PowerShell window.
Once a PowerShell script has been created, you can run any migration job as a scheduled task on the system that the client application is installed on. This can be any migration action that exists in the Job List section, whether it's a migration job that was saved or a job that was previously run.
The Generate PowerShell Script option saves configurations for the selected job(s) as a PowerShell script. After the script has been saved, you must create a Windows Scheduled task directly in the Windows Task Scheduler.
Once these jobs have been created as scheduled tasks they can no longer be viewed (as scheduled tasks) in Metalogix Content Matrix. If you want to make any other modifications or remove the task you can do so directly in the Windows Task Scheduler. If a task has been scheduled, the system will be able to run the task at the appointed time(s), regardless of whether Metalogix Content Matrix client application is open.
To schedule a PowerShell script to run via the Windows Task Scheduler:
1.On the system where the scheduled task will run, open the Windows Task Scheduler.
2.Choose Actions > Create Task.
3.Enter a task Name and Description.
4.In the General tab, go to Security options and specify the user account that the task should be run under. Change the settings so the task will run regardless of whether the user is logged in.
5.Select the Triggers tab, and click [New] to add a new trigger for the scheduled task. This new task should use the On a schedule option. The start date can be set to a desired time, and the frequency and duration of the task can be set based on your specific needs. Click [OK] when your desired settings are entered.
6.Select the Actions tab and click [New] to set the action for this task to run. Set the Action to Start a program.
7.In the Program/script box enter "PowerShell."
8.In the Add arguments (optional) box enter the value ".\[Your PowerShell Script Name]." For example, if your PowerShell Script is named "Migration1.ps1" then you would enter ".\Migration1.ps1" as the value.
9.In the Start in (optional) box, add the location of the folder that contains your PowerShell script.
NOTE: The location used in the Start in box will also be used for storing the scheduled task run times, the job history for the copies, and any additional logging that may occur.
10.When all the desired settings are made, click [OK].
11.Set any other desired settings in the Conditions and Settings tabs.
12.Once all the desired actions have been made (or added), click [OK].
The task will be immediately set, and is ready to run.
After the scheduled task has run, a new entry will be added to Metalogix Content Matrix's Job List section.
Metalogix Content Matrix can generate PowerShell script for you, for any migration action that is available through it. The below cmdlets are used in the generated PowerShell script, but can also be used to write your own script, should you desire to do so. For more information on each cmdlet, simply type get-help [cmdlet]. For example, if you want more information on Copy-MLSharePointList cmdlet you would enter get-help Copy-MLSharePointList, followed by the Enter (return) key.
Below is a list of the available cmdlets (and their parameters), broken up into the available commands for each snap-in.