Author | Pollus Brodeur (@pollusb) |
Availability | Windows, Linux, macOS |
Want to see the source code for this command? Check out Measure-DbaDiskSpaceRequirement on GitHub.
Want to see the Bill Of Health for this command? Check out Measure-DbaDiskSpaceRequirement.
Calculates disk space requirements for database migration between SQL Server instances
Analyzes database files on source and destination instances to calculate space requirements before migration. Shows file size differences, mount points, and identifies potential overwrites when copying databases between SQL Server instances.
The function compares data and log files from the source database against existing files on the destination, accounting for scenarios where files exist only on source, only on destination, or on both sides. This prevents migration failures due to insufficient disk space and helps plan storage allocation.
Accepts pipeline input with Source, Database, and Destination properties, making it ideal for bulk migration planning from CSV files, SQL queries, or PowerShell objects.
Measure-DbaDiskSpaceRequirement
[-Source] <DbaInstanceParameter>
[-Database] <String>
[[-SourceSqlCredential] <PSCredential>]
[-Destination] <DbaInstanceParameter>
[[-DestinationDatabase] <String>]
[[-DestinationSqlCredential] <PSCredential>]
[[-Credential] <PSCredential>]
[-EnableException]
[<CommonParameters>]
PS C:\> Measure-DbaDiskSpaceRequirement -Source INSTANCE1 -Database DB1 -Destination INSTANCE2
Calculate space needed for a simple migration with one database with the same name at destination.
PS C:\> @(
>> [PSCustomObject]@{Source='SQL1';Destination='SQL2';Database='DB1'},
>> [PSCustomObject]@{Source='SQL1';Destination='SQL2';Database='DB2'}
>> ) | Measure-DbaDiskSpaceRequirement
Using a PSCustomObject with 2 databases to migrate on SQL2.
PS C:\> Import-Csv -Path .\migration.csv -Delimiter "`t" | Measure-DbaDiskSpaceRequirement | Format-Table -AutoSize
Using a CSV file. You will need to use this header line "Source
PS C:\> $qry = "SELECT Source, Destination, Database FROM dbo.Migrations"
PS C:\> Invoke-DbaCmd -SqlInstance DBA -Database Migrations -Query $qry | Measure-DbaDiskSpaceRequirement
Using a SQL table. We are DBA after all!
Specifies the source SQL Server instance containing the database to analyze for migration.
This is where the database currently exists and from which file sizes will be measured.
Alias | |
Required | True |
Pipeline | true (ByPropertyName) |
Default Value |
Specifies the name of the database to analyze on the source instance.
The database must exist on the source server as the function reads actual file sizes from this database.
Alias | |
Required | True |
Pipeline | true (ByPropertyName) |
Default Value |
Specifies the destination SQL Server instance where the database will be migrated.
Used to determine target file paths, check for existing databases with the same name, and calculate mount point requirements.
Alias | |
Required | True |
Pipeline | true (ByPropertyName) |
Default Value |
Login to the target instance using alternative credentials. Accepts PowerShell credentials (Get-Credential).
Windows Authentication, SQL Server Authentication, Active Directory - Password, and Active Directory - Integrated are all supported.
For MFA support, please use Connect-DbaInstance.
Alias | |
Required | False |
Pipeline | true (ByPropertyName) |
Default Value |
Specifies the database name to use on the destination instance if different from the source database name.
When omitted, the destination database will use the same name as the source database.
Useful when migrating databases that need to be renamed or when avoiding naming conflicts on the destination server.
Alias | |
Required | False |
Pipeline | true (ByPropertyName) |
Default Value |
Login to the target instance using alternative credentials. Accepts PowerShell credentials (Get-Credential).
Windows Authentication, SQL Server Authentication, Active Directory - Password, and Active Directory - Integrated are all supported.
For MFA support, please use Connect-DbaInstance.
Alias | |
Required | False |
Pipeline | true (ByPropertyName) |
Default Value |
The credentials to use to connect via CIM/WMI/PowerShell remoting.
Alias | |
Required | False |
Pipeline | true (ByPropertyName) |
Default Value |
By default, when something goes wrong we try to catch it, interpret it and give you a friendly warning message.
This avoids overwhelming you with "sea of red" exceptions, but is inconvenient because it basically disables advanced scripting.
Using this switch turns this "nice by default" feature off and enables you to catch exceptions with your own try/catch.
Alias | |
Required | False |
Pipeline | false |
Default Value | False |