Skip to content

Commit 68a69c1

Browse files
committed
Replaced credential variables
1 parent 1621455 commit 68a69c1

1 file changed

Lines changed: 15 additions & 9 deletions

File tree

functions/Remove-PSDCImage.ps1

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -90,22 +90,28 @@
9090

9191
begin {
9292

93+
# Get the module configurations
94+
$pdcSqlInstance = Get-PSFConfigValue -FullName psdatabaseclone.database.Server
95+
$pdcDatabase = Get-PSFConfigValue -FullName psdatabaseclone.database.name
96+
if (-not $pdcCredential) {
97+
$pdcCredential = Get-PSFConfigValue -FullName psdatabaseclone.database.credential -Fallback $null
98+
}
99+
else {
100+
$pdcCredential = $pdcCredential
101+
}
102+
93103
# Test the module database setup
94104
try {
95-
Test-PSDCConfiguration -SqlCredential $PSDCSqlCredential -EnableException
105+
Test-PSDCConfiguration -SqlCredential $pdcCredential -EnableException
96106
}
97107
catch {
98108
Stop-PSFFunction -Message "Something is wrong in the module configuration" -ErrorRecord $_ -Continue
99109
}
100110

101-
# Get the database values
102-
$pdcSqlInstance = Get-PSFConfigValue -FullName psdatabaseclone.database.server
103-
$pdcDatabase = Get-PSFConfigValue -FullName psdatabaseclone.database.name
104-
105111
Write-PSFMessage -Message "Started removing database images" -Level Verbose
106112

107113
# Get all the items
108-
$items = Get-PSDCImage -PSDCSqlCredential $PSDCSqlCredential
114+
$items = Get-PSDCImage -pdcCredential $pdcCredential
109115

110116
if ($ImageID) {
111117
Write-PSFMessage -Message "Filtering image ids" -Level Verbose
@@ -170,7 +176,7 @@
170176
try {
171177
Write-PSFMessage -Message "Retrieving data for image '$($item.Name)'" -Level Verbose
172178
$results = @()
173-
$results += Invoke-DbaSqlQuery -SqlInstance $pdcSqlInstance -SqlCredential $PSDCSqlCredential -Database $pdcDatabase -Query $query
179+
$results += Invoke-DbaSqlQuery -SqlInstance $pdcSqlInstance -SqlCredential $pdcCredential -Database $pdcDatabase -Query $query
174180

175181
# Check the results
176182
if ($results.Count -ge 1) {
@@ -181,7 +187,7 @@
181187
# Remove the clones for the host
182188
try {
183189
Write-PSFMessage -Message "Removing clones for host $($result.HostName) and database $($result.DatabaseName)" -Level Verbose
184-
Remove-PSDCClone -HostName $result.HostName -Database $result.DatabaseName -PSDCSqlCredential $PSDCSqlCredential -Credential $Credential -Confirm:$false
190+
Remove-PSDCClone -HostName $result.HostName -Database $result.DatabaseName -pdcCredential $pdcCredential -Credential $Credential -Confirm:$false
185191
}
186192
catch {
187193
Stop-PSFFunction -Message "Couldn't remove clones from host $($result.HostName)" -ErrorRecord $_ -Target $result -Continue
@@ -214,7 +220,7 @@
214220
try {
215221
$query = "DELETE FROM dbo.Image WHERE ImageID = $($item.ImageID)"
216222

217-
$null = Invoke-DbaSqlQuery -SqlInstance $pdcSqlInstance -SqlCredential $PSDCSqlCredential -Database $pdcDatabase -Query $query
223+
$null = Invoke-DbaSqlQuery -SqlInstance $pdcSqlInstance -SqlCredential $pdcCredential -Database $pdcDatabase -Query $query
218224
}
219225
catch {
220226
Stop-PSFFunction -Message "Couldn't remove image '$($item.ImageLocation)' from database" -ErrorRecord $_ -Target $query

0 commit comments

Comments
 (0)