Skip to content

Save-MigrationReport

DBSystems: Generates a SQL Server In-Memory OLTP Migration Checklist

#Requires -Version 5.0
#Requires -Modules SQLServer

[CmdLetBinding()]
Param(
    [Parameter(Mandatory = $true)]   
    [string]$ServerInstance,    
    [Parameter(Mandatory = $true)]   
    [string]$DatabaseName,    
    [pscredential]$ServerCredential,
    [string]$FolderPath,
    [ValidateSet('OLTP')]
    [string]$MigrationType = 'OLTP',
    [int]$ConnectionTimeout = 30
)

function Get-SqlServerInstanceInternal {
    [CmdLetBinding()]
    Param(
        [Parameter(Mandatory = $true)]   
        [string]$ServerInstance,    
        [pscredential]$ServerCredential,
        [int]$ConnectionTimeout = 30
    )
    try {
        [hashtable]$cmdArgs = @{
            'ErrorAction' = 'Stop'
            'Confirm' = $false
            'ServerInstance' = $ServerInstance
            'ConnectionTimeout' = $ConnectionTimeout
        }
        if ($null -ne $ServerCredential) {
            $cmdArgs.Add('Credential', $ServerCredential)
        }
        return Get-SqlInstance @cmdArgs
    } catch {
        throw
    }
}

function Get-SqlDatabaseInternal {
    [CmdLetBinding()]
    Param(
        [Parameter(Mandatory = $true)]   
        [object]$ServerInstance,    
        [Parameter(Mandatory = $true)]   
        [string]$DatabaseName
    )
    try {
        [hashtable]$cmdArgs = @{
            'ErrorAction' = 'Stop'
            'InputObject' = $ServerInstance
            'Name' = $DatabaseName
            'Confirm' = $false
        }
        return Get-SqlDatabase @cmdArgs
    } catch {
        throw
    }
}

Import-Module SQLServer

try {
    $instance = Get-SqlServerInstanceInternal -ServerInstance $ServerInstance -ServerCredential $ServerCredential -ConnectionTimeout $ConnectionTimeout
    $db = Get-SqlDatabaseInternal -DatabaseName $DatabaseName -ServerInstance $instance
    
    [hashtable]$cmdArgs = @{
        'ErrorAction'   = 'Stop'
        'InputObject'   = $db
        'MigrationType' = $MigrationType
    }                                     
    if (-not [string]::IsNullOrWhiteSpace($FolderPath)) {
        if (-not (Test-Path -Path $FolderPath)) {
            New-Item -ItemType Directory -Path $FolderPath -Force | Out-Null
        }
        $cmdArgs.Add('FolderPath', $FolderPath)
    }
    
    $result = Save-SqlMigrationReport @cmdArgs
    Write-Output $result
} catch {
    throw
}

Specifies the name of the target computer including the instance name, e.g. MyServer\Instance

Specifies the name of the database for which to generate the migration report

Specifies a PSCredential object for the connection to the SQL Server. ServerCredential is ONLY used for SQL Logins. When you are using Windows Authentication you don't specify -Credential. It is picked up from your current login.

Specifies the destination folder where the report files will be saved

Specifies the type of migration evaluation (Currently only 'OLTP' is supported)

Specifies the time period to retry the command on the target server

An interactive directory of PowerShell scripts.