|
122 | 122 | } |
123 | 123 |
|
124 | 124 | # Test the module database setup |
125 | | - try { |
126 | | - Test-PSDCConfiguration -SqlCredential $pdcCredential -EnableException |
127 | | - } |
128 | | - catch { |
129 | | - Stop-PSFFunction -Message "Something is wrong in the module configuration" -ErrorRecord $_ -Continue |
| 125 | + if ($PSCmdlet.ShouldProcess("Test-PSDCConfiguration", "Testing module setup")) { |
| 126 | + try { |
| 127 | + Test-PSDCConfiguration -SqlCredential $pdcCredential -EnableException |
| 128 | + } |
| 129 | + catch { |
| 130 | + Stop-PSFFunction -Message "Something is wrong in the module configuration" -ErrorRecord $_ -Continue |
| 131 | + } |
130 | 132 | } |
131 | 133 |
|
132 | 134 | Write-PSFMessage -Message "Started image creation" -Level Verbose |
|
262 | 264 | } |
263 | 265 |
|
264 | 266 | # Take apart the vhd directory |
265 | | - if ($computer.IsLocalhost) { |
266 | | - if (Test-Path -Path $ParentVhd) { |
267 | | - $parentVhdFileName = $ParentVhd.Split("\")[-1] |
268 | | - $parentVhdFile = $parentVhdFileName.Split(".")[0] |
269 | | - } |
270 | | - else { |
271 | | - Stop-PSFFunction -Message "Parent vhd could not be found" -Target $SqlInstance -Continue |
272 | | - } |
273 | | - } |
274 | | - else { |
275 | | - $command = [scriptblock]::Create("Test-Path -Path $ParentVhd") |
276 | | - $result = Invoke-PSFCommand -ComputerName $computer -ScriptBlock $command -Credential $Credential |
277 | | - if ($result) { |
278 | | - $parentVhdFileName = $ParentVhd.Split("\")[-1] |
279 | | - $parentVhdFile = $parentVhdFileName.Split(".")[0] |
| 267 | + if ($PSCmdlet.ShouldProcess($ParentVhd, "Setting up parent VHD variables")) { |
| 268 | + if ($computer.IsLocalhost) { |
| 269 | + if (Test-Path -Path $ParentVhd) { |
| 270 | + $parentVhdFileName = $ParentVhd.Split("\")[-1] |
| 271 | + $parentVhdFile = $parentVhdFileName.Split(".")[0] |
| 272 | + } |
| 273 | + else { |
| 274 | + Stop-PSFFunction -Message "Parent vhd could not be found" -Target $SqlInstance -Continue |
| 275 | + } |
280 | 276 | } |
281 | 277 | else { |
282 | | - Stop-PSFFunction -Message "Parent vhd could not be found" -Target $SqlInstance -Continue |
| 278 | + $command = [scriptblock]::Create("Test-Path -Path $ParentVhd") |
| 279 | + $result = Invoke-PSFCommand -ComputerName $computer -ScriptBlock $command -Credential $Credential |
| 280 | + if ($result) { |
| 281 | + $parentVhdFileName = $ParentVhd.Split("\")[-1] |
| 282 | + $parentVhdFile = $parentVhdFileName.Split(".")[0] |
| 283 | + } |
| 284 | + else { |
| 285 | + Stop-PSFFunction -Message "Parent vhd could not be found" -Target $SqlInstance -Continue |
| 286 | + } |
283 | 287 | } |
284 | 288 | } |
285 | 289 |
|
286 | | - |
287 | 290 | # Check clone name parameter |
288 | | - if (-not $CloneName) { |
289 | | - $cloneDatabase = $parentVhdFile |
290 | | - $CloneName = $parentVhdFile |
291 | | - $mountDirectory = "$($parentVhdFile)_$($random)" |
292 | | - } |
293 | | - elseif ($CloneName) { |
294 | | - $cloneDatabase = $CloneName |
295 | | - $mountDirectory = "$($CloneName)_$($random)" |
| 291 | + if ($PSCmdlet.ShouldProcess($ParentVhd, "Setting up clone variables")) { |
| 292 | + if (-not $CloneName) { |
| 293 | + $cloneDatabase = $parentVhdFile |
| 294 | + $CloneName = $parentVhdFile |
| 295 | + $mountDirectory = "$($parentVhdFile)_$($random)" |
| 296 | + } |
| 297 | + elseif ($CloneName) { |
| 298 | + $cloneDatabase = $CloneName |
| 299 | + $mountDirectory = "$($CloneName)_$($random)" |
| 300 | + } |
296 | 301 | } |
297 | 302 |
|
298 | 303 | # Check if the database is already present |
299 | | - if ($server.Databases.Name -contains $cloneDatabase) { |
300 | | - Stop-PSFFunction -Message "Database $cloneDatabase is already present on $SqlInstance" -Target $SqlInstance |
| 304 | + if ($PSCmdlet.ShouldProcess($cloneDatabase, "Verifying database existence")) { |
| 305 | + if ($server.Databases.Name -contains $cloneDatabase) { |
| 306 | + Stop-PSFFunction -Message "Database $cloneDatabase is already present on $SqlInstance" -Target $SqlInstance |
| 307 | + } |
301 | 308 | } |
302 | 309 |
|
303 | 310 | # Setup access path location |
|
0 commit comments