Skip to content

Commit e102651

Browse files
committed
Improved should support
1 parent 89227cc commit e102651

1 file changed

Lines changed: 39 additions & 32 deletions

File tree

functions/New-PSDCClone.ps1

Lines changed: 39 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,13 @@
122122
}
123123

124124
# 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+
}
130132
}
131133

132134
Write-PSFMessage -Message "Started image creation" -Level Verbose
@@ -262,42 +264,47 @@
262264
}
263265

264266
# 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+
}
280276
}
281277
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+
}
283287
}
284288
}
285289

286-
287290
# 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+
}
296301
}
297302

298303
# 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+
}
301308
}
302309

303310
# Setup access path location

0 commit comments

Comments
 (0)