|
43 | 43 | Allows you to login to servers using SQL Logins as opposed to Windows Auth/Integrated/Trusted. |
44 | 44 | This works similar as SqlCredential but is only meant for authentication to the PSDatabaseClone database server and database. |
45 | 45 |
|
| 46 | + By default the script will try to retrieve the configuration value "psdatabaseclone.database.credential" |
| 47 | +
|
46 | 48 | .PARAMETER ImageNetworkPath |
47 | 49 | Network path where to save the image. This has to be a UNC path |
48 | 50 |
|
|
123 | 125 |
|
124 | 126 | begin { |
125 | 127 |
|
| 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 | + |
126 | 138 | # Test the module database setup |
127 | 139 | try { |
128 | | - Test-PSDCConfiguration -SqlCredential $PSDCSqlCredential -EnableException |
| 140 | + Test-PSDCConfiguration -SqlCredential $pdcCredential -EnableException |
129 | 141 | } |
130 | 142 | catch { |
131 | 143 | Stop-PSFFunction -Message "Something is wrong in the module configuration" -ErrorRecord $_ -Continue |
132 | 144 | } |
133 | 145 |
|
134 | | - $pdcSqlInstance = Get-PSFConfigValue -FullName psdatabaseclone.database.Server |
135 | | - $pdcDatabase = Get-PSFConfigValue -FullName psdatabaseclone.database.name |
136 | | - |
137 | 146 | Write-PSFMessage -Message "Started image creation" -Level Output |
138 | 147 |
|
139 | 148 | # Try connecting to the instance |
|
164 | 173 | $computer = [PsfComputer]$uriHost |
165 | 174 |
|
166 | 175 | if (-not $computer.IsLocalhost) { |
| 176 | + |
167 | 177 | $command = [ScriptBlock]::Create("Import-Module dbatools") |
168 | 178 | Invoke-PSFCommand -ComputerName $computer -ScriptBlock $command -Credential $DestinationCredential |
169 | 179 |
|
|
465 | 475 | try { |
466 | 476 | Write-PSFMessage -Message "Saving image information in database" -Level Verbose |
467 | 477 |
|
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 |
469 | 479 | } |
470 | 480 | catch { |
471 | 481 | Stop-PSFFunction -Message "Couldn't add image to database" -Target $imageName -ErrorRecord $_ |
|
0 commit comments