Skip to content

Commit d444c3e

Browse files
committed
Changed the retrieval config values. Changed credential parameters
1 parent 0f7a180 commit d444c3e

1 file changed

Lines changed: 15 additions & 5 deletions

File tree

functions/New-PSDCImage.ps1

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343
Allows you to login to servers using SQL Logins as opposed to Windows Auth/Integrated/Trusted.
4444
This works similar as SqlCredential but is only meant for authentication to the PSDatabaseClone database server and database.
4545
46+
By default the script will try to retrieve the configuration value "psdatabaseclone.database.credential"
47+
4648
.PARAMETER ImageNetworkPath
4749
Network path where to save the image. This has to be a UNC path
4850
@@ -123,17 +125,24 @@
123125

124126
begin {
125127

128+
# Get the module configurations
129+
$pdcSqlInstance = Get-PSFConfigValue -FullName psdatabaseclone.database.Server
130+
$pdcDatabase = Get-PSFConfigValue -FullName psdatabaseclone.database.name
131+
if (-not $PSDCSqlCredential) {
132+
$pdcCredential = Get-PSFConfig -FullName psdatabaseclone.database.credential -Fallback $null
133+
}
134+
else{
135+
$pdcCredential = $PSDCSqlCredential
136+
}
137+
126138
# Test the module database setup
127139
try {
128-
Test-PSDCConfiguration -SqlCredential $PSDCSqlCredential -EnableException
140+
Test-PSDCConfiguration -SqlCredential $pdcCredential -EnableException
129141
}
130142
catch {
131143
Stop-PSFFunction -Message "Something is wrong in the module configuration" -ErrorRecord $_ -Continue
132144
}
133145

134-
$pdcSqlInstance = Get-PSFConfigValue -FullName psdatabaseclone.database.Server
135-
$pdcDatabase = Get-PSFConfigValue -FullName psdatabaseclone.database.name
136-
137146
Write-PSFMessage -Message "Started image creation" -Level Output
138147

139148
# Try connecting to the instance
@@ -164,6 +173,7 @@
164173
$computer = [PsfComputer]$uriHost
165174

166175
if (-not $computer.IsLocalhost) {
176+
167177
$command = [ScriptBlock]::Create("Import-Module dbatools")
168178
Invoke-PSFCommand -ComputerName $computer -ScriptBlock $command -Credential $DestinationCredential
169179

@@ -465,7 +475,7 @@
465475
try {
466476
Write-PSFMessage -Message "Saving image information in database" -Level Verbose
467477

468-
$result += Invoke-DbaSqlQuery -SqlInstance $pdcSqlInstance -SqlCredential $PSDCSqlCredential -Database $pdcDatabase -Query $query -EnableException
478+
$result += Invoke-DbaSqlQuery -SqlInstance $pdcSqlInstance -SqlCredential $pdcCredential -Database $pdcDatabase -Query $query -EnableException
469479
}
470480
catch {
471481
Stop-PSFFunction -Message "Couldn't add image to database" -Target $imageName -ErrorRecord $_

0 commit comments

Comments
 (0)