Skip to content

Commit 89227cc

Browse files
committed
Fixed should support
1 parent ccc2422 commit 89227cc

1 file changed

Lines changed: 24 additions & 21 deletions

File tree

functions/New-PSDCImage.ps1

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,13 @@
137137
}
138138

139139
# Test the module database setup
140-
try {
141-
Test-PSDCConfiguration -SqlCredential $pdcCredential -EnableException
142-
}
143-
catch {
144-
Stop-PSFFunction -Message "Something is wrong in the module configuration" -ErrorRecord $_ -Continue
140+
if ($PSCmdlet.ShouldProcess("Test-PSDCConfiguration", "Testing module setup")) {
141+
try {
142+
Test-PSDCConfiguration -SqlCredential $pdcCredential -EnableException
143+
}
144+
catch {
145+
Stop-PSFFunction -Message "Something is wrong in the module configuration" -ErrorRecord $_ -Continue
146+
}
145147
}
146148

147149
Write-PSFMessage -Message "Started image creation" -Level Output
@@ -192,7 +194,7 @@
192194
}
193195

194196
# Get the local path from the network path
195-
if ($PSCmdlet.ShouldProcess($ImageNetworkPath, "Converting UNC path '$ImageNetworkPath' to local path")) {
197+
if ($PSCmdlet.ShouldProcess($ImageNetworkPath, "Converting UNC path to local path")) {
196198
if (-not $ImageLocalPath) {
197199
try {
198200
# Check if computer is local
@@ -215,7 +217,7 @@
215217
}
216218

217219
# Check the image local path
218-
if ($ImageLocalPath) {
220+
if ($PSCmdlet.ShouldProcess("Verifying image local path")) {
219221
if ((Test-DbaSqlPath -Path $ImageLocalPath -SqlInstance $SourceSqlInstance -SqlCredential $DestinationCredential) -ne $true) {
220222
Stop-PSFFunction -Message "Image local path $ImageLocalPath is not valid directory or can't be reached." -Target $SourceSqlInstance
221223
return
@@ -227,7 +229,6 @@
227229
}
228230

229231
$imagePath = $ImageLocalPath
230-
231232
}
232233

233234
# Check the database parameter
@@ -257,26 +258,28 @@
257258
foreach ($db in $DatabaseCollection) {
258259
Write-PSFMessage -Message "Creating image for database $db from $SourceSqlInstance" -Level Verbose
259260

260-
# Check the database size to the available disk space
261-
if ($computer.IsLocalhost) {
262-
$availableMB = (Get-PSDrive -Name $ImageLocalPath.Substring(0, 1)).Free / 1MB
263-
}
264-
else {
265-
$command = [ScriptBlock]::Create("(Get-PSDrive -Name $($ImageLocalPath.Substring(0, 1)) ).Free / 1MB")
266-
$availableMB = Invoke-PSFCommand -ComputerName $computer -ScriptBlock $commandGetLocalPath -Credential $DestinationCredential
267-
}
261+
if ($PSCmdlet.ShouldProcess($db, "Checking available disk space for database")) {
262+
# Check the database size to the available disk space
263+
if ($computer.IsLocalhost) {
264+
$availableMB = (Get-PSDrive -Name $ImageLocalPath.Substring(0, 1)).Free / 1MB
265+
}
266+
else {
267+
$command = [ScriptBlock]::Create("(Get-PSDrive -Name $($ImageLocalPath.Substring(0, 1)) ).Free / 1MB")
268+
$availableMB = Invoke-PSFCommand -ComputerName $computer -ScriptBlock $commandGetLocalPath -Credential $DestinationCredential
269+
}
268270

269-
$dbSizeMB = $db.Size
271+
$dbSizeMB = $db.Size
270272

271-
if ($availableMB -lt $dbSizeMB) {
272-
Stop-PSFFunction -Message "Size of database $($db.Name) does not fit within the image local path" -Target $db -Continue
273+
if ($availableMB -lt $dbSizeMB) {
274+
Stop-PSFFunction -Message "Size of database $($db.Name) does not fit within the image local path" -Target $db -Continue
275+
}
273276
}
274277

275278
# Setup the image variables
276279
$imageName = "$($db.Name)_$timestamp"
277280

278281
# Setup the access path
279-
$accessPath = "$($ImageLocalPath)\$imageName"
282+
$accessPath = "$ImageLocalPath\$imageName"
280283

281284
# Setup the vhd path
282285
$vhdPath = "$($accessPath).vhdx"
@@ -454,7 +457,7 @@
454457
}
455458
}
456459

457-
if ($PSCmdlet.ShouldProcess($vhdPath, "Dismount the vhd")) {
460+
if ($PSCmdlet.ShouldProcess($vhdPath, "Dismounting the vhd")) {
458461
# Dismount the vhd
459462
try {
460463
Write-PSFMessage -Message "Dismounting vhd" -Level Verbose

0 commit comments

Comments
 (0)