|
137 | 137 | } |
138 | 138 |
|
139 | 139 | # 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 | + } |
145 | 147 | } |
146 | 148 |
|
147 | 149 | Write-PSFMessage -Message "Started image creation" -Level Output |
|
192 | 194 | } |
193 | 195 |
|
194 | 196 | # 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")) { |
196 | 198 | if (-not $ImageLocalPath) { |
197 | 199 | try { |
198 | 200 | # Check if computer is local |
|
215 | 217 | } |
216 | 218 |
|
217 | 219 | # Check the image local path |
218 | | - if ($ImageLocalPath) { |
| 220 | + if ($PSCmdlet.ShouldProcess("Verifying image local path")) { |
219 | 221 | if ((Test-DbaSqlPath -Path $ImageLocalPath -SqlInstance $SourceSqlInstance -SqlCredential $DestinationCredential) -ne $true) { |
220 | 222 | Stop-PSFFunction -Message "Image local path $ImageLocalPath is not valid directory or can't be reached." -Target $SourceSqlInstance |
221 | 223 | return |
|
227 | 229 | } |
228 | 230 |
|
229 | 231 | $imagePath = $ImageLocalPath |
230 | | - |
231 | 232 | } |
232 | 233 |
|
233 | 234 | # Check the database parameter |
|
257 | 258 | foreach ($db in $DatabaseCollection) { |
258 | 259 | Write-PSFMessage -Message "Creating image for database $db from $SourceSqlInstance" -Level Verbose |
259 | 260 |
|
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 | + } |
268 | 270 |
|
269 | | - $dbSizeMB = $db.Size |
| 271 | + $dbSizeMB = $db.Size |
270 | 272 |
|
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 | + } |
273 | 276 | } |
274 | 277 |
|
275 | 278 | # Setup the image variables |
276 | 279 | $imageName = "$($db.Name)_$timestamp" |
277 | 280 |
|
278 | 281 | # Setup the access path |
279 | | - $accessPath = "$($ImageLocalPath)\$imageName" |
| 282 | + $accessPath = "$ImageLocalPath\$imageName" |
280 | 283 |
|
281 | 284 | # Setup the vhd path |
282 | 285 | $vhdPath = "$($accessPath).vhdx" |
|
454 | 457 | } |
455 | 458 | } |
456 | 459 |
|
457 | | - if ($PSCmdlet.ShouldProcess($vhdPath, "Dismount the vhd")) { |
| 460 | + if ($PSCmdlet.ShouldProcess($vhdPath, "Dismounting the vhd")) { |
458 | 461 | # Dismount the vhd |
459 | 462 | try { |
460 | 463 | Write-PSFMessage -Message "Dismounting vhd" -Level Verbose |
|
0 commit comments