Use Windows PowerShell
- Last UpdatedSep 09, 2025
- 1 minute read
- PI System
- PI Server 2024 R2
- PI Server
You can migrate a PI AF database to Azure SQL Database or Azure Managed Instance using Windows PowerShell.
-
Run PowerShell in Administrative mode.
-
At the command prompt, enter the following parameters:
Connect-AzAccount -Subscription <Subscription-id>
-
Enter the following commands to set the subscription ID:
Set-AzContext -Subscription <Subscription-id>
-
Optional: If you do not have a pre-configured database migration service set up and a self-hosted Integration Runtime agent, enter the following commands to configure the service and agent:
New-AzDataMigrationSqlService -ResourceGroupName "MyResourceGroup" -Name "MySqlMigrationService" -Location "EastUS2"
$authKeys = Get-AzDataMigrationSqlServiceAuthKey -ResourceGroupName "MyResourceGroup" -SqlMigrationServiceName "MySqlMigrationService"
Register-AzDataMigrationIntegrationRuntime -AuthKey $authKeys.AuthKey1 -IntegrationRuntimePath "C:\Users\user\Downloads\IntegrationRuntime.msi"
Register-AzDataMigrationIntegrationRuntime -AuthKey $authKeys.AuthKey1
-
To initiate the database migration, run the following command:
New-AzDataMigrationToSqlDb
Code example for PowerShell
New-AzDataMigrationToSqlDb `
-ResourceGroupName MyGroup `
-SqlDbInstanceName labserver `
-Kind "SqlDb" `
-TargetDbName AdventureWorksTarget `
-SourceDatabaseName AdventureWorks `
-SourceSqlConnectionAuthentication SQLAuthentication `
-SourceSqlConnectionDataSource LABSERVER.MICROSOFT.COM `
-SourceSqlConnectionUserName user `
-SourceSqlConnectionPassword $sourcePass `
-Scope "/subscriptions/MySubscriptionID/resourceGroups/MyGroup/providers/Microsoft.Sql/servers/labserver" `
-TargetSqlConnectionAuthentication SQLAuthentication `