|
90 | 90 |
|
91 | 91 | begin { |
92 | 92 |
|
| 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 | + |
93 | 103 | # Test the module database setup |
94 | 104 | try { |
95 | | - Test-PSDCConfiguration -SqlCredential $PSDCSqlCredential -EnableException |
| 105 | + Test-PSDCConfiguration -SqlCredential $pdcCredential -EnableException |
96 | 106 | } |
97 | 107 | catch { |
98 | 108 | Stop-PSFFunction -Message "Something is wrong in the module configuration" -ErrorRecord $_ -Continue |
99 | 109 | } |
100 | 110 |
|
101 | | - # Get the database values |
102 | | - $pdcSqlInstance = Get-PSFConfigValue -FullName psdatabaseclone.database.server |
103 | | - $pdcDatabase = Get-PSFConfigValue -FullName psdatabaseclone.database.name |
104 | | - |
105 | 111 | Write-PSFMessage -Message "Started removing database images" -Level Verbose |
106 | 112 |
|
107 | 113 | # Get all the items |
108 | | - $items = Get-PSDCImage -PSDCSqlCredential $PSDCSqlCredential |
| 114 | + $items = Get-PSDCImage -pdcCredential $pdcCredential |
109 | 115 |
|
110 | 116 | if ($ImageID) { |
111 | 117 | Write-PSFMessage -Message "Filtering image ids" -Level Verbose |
|
170 | 176 | try { |
171 | 177 | Write-PSFMessage -Message "Retrieving data for image '$($item.Name)'" -Level Verbose |
172 | 178 | $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 |
174 | 180 |
|
175 | 181 | # Check the results |
176 | 182 | if ($results.Count -ge 1) { |
|
181 | 187 | # Remove the clones for the host |
182 | 188 | try { |
183 | 189 | 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 |
185 | 191 | } |
186 | 192 | catch { |
187 | 193 | Stop-PSFFunction -Message "Couldn't remove clones from host $($result.HostName)" -ErrorRecord $_ -Target $result -Continue |
|
214 | 220 | try { |
215 | 221 | $query = "DELETE FROM dbo.Image WHERE ImageID = $($item.ImageID)" |
216 | 222 |
|
217 | | - $null = Invoke-DbaSqlQuery -SqlInstance $pdcSqlInstance -SqlCredential $PSDCSqlCredential -Database $pdcDatabase -Query $query |
| 223 | + $null = Invoke-DbaSqlQuery -SqlInstance $pdcSqlInstance -SqlCredential $pdcCredential -Database $pdcDatabase -Query $query |
218 | 224 | } |
219 | 225 | catch { |
220 | 226 | Stop-PSFFunction -Message "Couldn't remove image '$($item.ImageLocation)' from database" -ErrorRecord $_ -Target $query |
|
0 commit comments