@@ -225,11 +225,18 @@ function New-PDCImage {
225225 Write-PSFMessage - Message " Creating image for database $db from $SourceSqlInstance " - Level Verbose
226226
227227 # Check the database size to the available disk space
228- $availableMB = (Get-PSDrive - Name $ImageLocalPath.Substring (0 , 1 )).Free / 1 MB
228+ if ($computer.IsLocalhost ) {
229+ $availableMB = (Get-PSDrive - Name $ImageLocalPath.Substring (0 , 1 )).Free / 1 MB
230+ }
231+ else {
232+ $command = [ScriptBlock ]::Create(" (Get-PSDrive -Name $ ( $ImageLocalPath ) .Substring(0, 1)).Free / 1MB" )
233+ $ImageLocalPath = Invoke-PSFCommand - ComputerName $computer - ScriptBlock $commandGetLocalPath - Credential $DestinationCredential
234+ }
235+
229236 $dbSizeMB = $db.Size
230237
231238 if ($availableMB -lt $dbSizeMB ) {
232- Stop-PSFFunction - Message " Size of database $ ( $db.Name ) does not find within the image local path" - Target $db - Continue
239+ Stop-PSFFunction - Message " Size of database $ ( $db.Name ) does not fit within the image local path" - Target $db - Continue
233240 }
234241
235242 # Setup the image variables
@@ -354,16 +361,18 @@ function New-PDCImage {
354361 # Dismount the vhd
355362 try {
356363 Write-PSFMessage - Message " Dismounting vhd" - Level Verbose
364+
365+ # Dismount the VHD
357366 $null = Dismount-VHD - Path $vhdPath
358367
368+ # Remove the access path
359369 $null = Remove-Item - Path $accessPath - Force
360370 }
361371 catch {
362372 Stop-PSFFunction - Message " Couldn't dismount vhd" - Target $imageName - ErrorRecord $_ - Continue
363373 }
364374
365375 # Write the data to the database
366-
367376 $imageLocation = " $ ( $uri.LocalPath ) \$imageName .vhdx"
368377 $sizeMB = $dbSizeMB
369378 $databaseName = $db.Name
@@ -389,7 +398,6 @@ function New-PDCImage {
389398 $result += Invoke-DbaSqlQuery - SqlInstance $pdcSqlInstance - Database $pdcDatabase - Query $query - EnableException
390399 }
391400 catch {
392-
393401 Stop-PSFFunction - Message " Couldn't add image to database" - Target $imageName - ErrorRecord $_
394402 }
395403
0 commit comments