Skip to content

Commit cfb8942

Browse files
committed
Fixed call to test function
1 parent 62820d1 commit cfb8942

3 files changed

Lines changed: 32 additions & 24 deletions

File tree

functions/Invoke-PDCRepairClone.ps1

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,16 @@ function Invoke-PDCRepairClone {
4949

5050
begin {
5151
# Test the module database setup
52-
$result = Test-PDCConfiguration
53-
54-
if(-not $result.Check){
55-
Stop-PSFFunction -Message $result.Message -Target $result -Continue
56-
return
52+
try {
53+
Test-PDCConfiguration -EnableException
54+
}
55+
catch {
56+
Stop-PSFFunction -Message "Something is wrong in the module configuration" -ErrorRecord $_ -Continue
5757
}
5858

59+
$pdcSqlInstance = Get-PSFConfigValue -FullName psdatabaseclone.database.server
60+
$pdcDatabase = Get-PSFConfigValue -FullName psdatabaseclone.database.name
61+
5962
}
6063

6164
process {

functions/Remove-PDCClone.ps1

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
function Remove-PDCClone {
2-
<#
2+
<#
33
.SYNOPSIS
44
Remove-PDCClone removes one or more clones from a host
55
@@ -82,15 +82,19 @@ function Remove-PDCClone {
8282
)
8383

8484
begin {
85-
Write-PSFMessage -Message "Started removing database clones" -Level Verbose
8685

8786
# Test the module database setup
88-
$result = Test-PDCConfiguration
89-
90-
if(-not $result.Check){
91-
Stop-PSFFunction -Message $result.Message -Target $result -Continue
92-
return
87+
try {
88+
Test-PDCConfiguration -EnableException
89+
}
90+
catch {
91+
Stop-PSFFunction -Message "Something is wrong in the module configuration" -ErrorRecord $_ -Continue
9392
}
93+
94+
$pdcSqlInstance = Get-PSFConfigValue -FullName psdatabaseclone.database.server
95+
$pdcDatabase = Get-PSFConfigValue -FullName psdatabaseclone.database.name
96+
97+
Write-PSFMessage -Message "Started removing database clones" -Level Verbose
9498
}
9599

96100
process {
@@ -123,7 +127,7 @@ function Remove-PDCClone {
123127
WHERE h.HostName LIKE ( '%$($computer.ComputerName)%' ) "
124128

125129
try {
126-
$results += Invoke-DbaSqlQuery -SqlInstance $ecDatabaseServer -Database $ecDatabaseName -Query $query
130+
$results += Invoke-DbaSqlQuery -SqlInstance $pdcSqlInstance -Database $pdcDatabase -Query $query
127131
}
128132
catch {
129133
Stop-PSFFunction -Message "Couldn't retrieve clone records for host $hst" -Target $hst -Continue
@@ -197,7 +201,7 @@ function Remove-PDCClone {
197201
AND c.CloneLocation = '$($result.CloneLocation)';
198202
"
199203

200-
Invoke-DbaSqlQuery -SqlInstance $ecDatabaseServer -Database $ecDatabaseName -Query $query
204+
Invoke-DbaSqlQuery -SqlInstance $pdcSqlInstance -Database $pdcDatabase -Query $query
201205
}
202206
catch {
203207
Stop-PSFFunction -Message "Could not remove clone record from database" -ErrorRecord $_ -Target $result -Continue

functions/Remove-PDCImage.ps1

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,20 @@ function Remove-PDCImage {
4343
)
4444

4545
begin {
46-
Write-PSFMessage -Message "Started removing database images" -Level Verbose
4746

4847
# Test the module database setup
49-
$result = Test-PDCConfiguration
50-
51-
if (-not $result.Check) {
52-
Stop-PSFFunction -Message $result.Message -Target $result -Continue
53-
return
48+
try {
49+
Test-PDCConfiguration -EnableException
50+
}
51+
catch {
52+
Stop-PSFFunction -Message "Something is wrong in the module configuration" -ErrorRecord $_ -Continue
5453
}
5554

5655
# Get the database values
57-
$pdcDatabaseServer = $result.SqlInstance
58-
$pdcDatabaseName = $result.Database
56+
$pdcSqlInstance = Get-PSFConfigValue -FullName psdatabaseclone.database.server
57+
$pdcDatabase = Get-PSFConfigValue -FullName psdatabaseclone.database.name
58+
59+
Write-PSFMessage -Message "Started removing database images" -Level Verbose
5960
}
6061

6162
process {
@@ -86,7 +87,7 @@ function Remove-PDCImage {
8687
# Try to get the neccesary info from the EasyClone database
8788
try {
8889
Write-PSFMessage -Message "Retrieving data for image '$image'" -Level Verbose
89-
$results = Invoke-DbaSqlQuery -SqlInstance $ecDatabaseServer -Database $ecDatabaseName -Query $query
90+
$results = Invoke-DbaSqlQuery -SqlInstance $pdcSqlInstance -Database $pdcDatabase -Query $query
9091
}
9192
catch {
9293
Stop-PSFFunction -Message "Couldn't retrieve clone records for host $hst" -Target $hst -Continue
@@ -121,7 +122,7 @@ function Remove-PDCImage {
121122
Write-PSFMessage -Message "Removing image '$image' from file system" -Level Verbose
122123
$null = Remove-Item -Path $image -Credential $Credential -Force:$Force
123124
}
124-
else{
125+
else {
125126
Write-PSFMessage -Message "Couldn't find image $image" -Level Verbose
126127
}
127128
}

0 commit comments

Comments
 (0)