11function Test-PdcDatabaseSetup {
2+
3+ [CmdLetBinding ()]
24 param (
3- [Parameter (Mandatory = $true )]
4- [ValidateNotNullOrEmpty ()]
55 [Alias (" ServerInstance" , " SqlServerSqlServer" )]
66 [object ]$SqlInstance ,
77
88 [System.Management.Automation.PSCredential ]
99 $SqlCredential ,
1010
11- [Parameter (Mandatory = $true )]
12- [ValidateNotNullOrEmpty ()]
1311 [string ]$Database
1412 )
1513
1614 Write-PSFMessage - Message " SqlInstance: $SqlInstance , Database: $Database " - Level Debug
1715
16+ # Create the info objects
17+ $result = [PSCustomObject ]@ {
18+ SqlInstance = $null
19+ Database = $null
20+ Check = $true
21+ Message = " "
22+ }
23+
24+ $errorOccured = $false
25+
1826 # Check if the values for the EasyClone database are set
19- if (($SqlInstance -eq ' NotConfigured' ) -or ($Database -eq ' NotConfigured' )) {
20- Stop-PSFFunction - Message " The module is not yet configured. Please run Set-PdcConfiguration to make the neccesary changes" - Target $SqlInstance
21- return
27+ if (($SqlInstance -eq $null ) -or ($Database -eq $null )) {
28+ # Get the configurations for the program database
29+ $Database = Get-PSFConfigValue - FullName psdatabaseclone.database.name - Fallback " NotConfigured"
30+ $SqlInstance = Get-PSFConfigValue - FullName psdatabaseclone.database.Server - Fallback " NotConfigured"
2231 }
2332
24- Write-PSFMessage - Message " Attempting to connect to PSDatabaseClone database server $SqlInstance .." - Level Verbose
25- try {
26- $ecServer = Connect-DbaInstance - SqlInstance $SqlInstance - SqlCredential $SqlCredential
33+ # Set the values in the info object
34+ $result.SqlInstance = $SqlInstance
35+ $result.Database = $Database
36+
37+ Write-PSFMessage - Message " Checking configurations" - Level Verbose
38+
39+ # Check the module database server and database name configurations
40+ if ($SqlInstance -eq ' NotConfigured' ) {
41+ $errorOccured = $true
42+ $result.Check = $false
43+ $result.Message = " The PSDatabaseClone database server is not yet configured. Please run Set-PdcConfiguration"
44+
45+ }
46+
47+ if ($Database -eq ' NotConfigured' ) {
48+ $errorOccured = $true
49+ $result.Check = $false
50+ $result.Message = " The PSDatabaseClone database is not yet configured. Please run Set-PdcConfiguration"
51+
2752 }
28- catch {
29- Stop-PSFFunction - Message " Could not connect to Sql Server instance $SqlInstance " - ErrorRecord $_ - Target $SqlInstance
53+
54+ Write-PSFMessage - Message " Attempting to connect to PSDatabaseClone database server $SqlInstance .." - Level Verbose
55+ if ($result.Check ) {
56+ try {
57+ $ecServer = Connect-DbaInstance - SqlInstance $SqlInstance - SqlCredential $SqlCredential
58+ }
59+ catch {
60+ $errorOccured = $true
61+ $result.Check = $false
62+ $result.Message = " Could not connect to Sql Server instance $SqlInstance "
63+ }
3064 }
3165
3266 # Check if the easyclone database is present
3367 if ($ecServer.Databases.Name -notcontains $Database ) {
34- Stop-PSFFunction - Message " PSDatabaseClone database $Database is not present on $SqlInstance " - ErrorRecord $_ - Target $SqlInstance
68+ $errorOccured = $true
69+ $result.Check = $false
70+ $result.Message = " PSDatabaseClone database $Database is not present on $SqlInstance "
3571 }
72+
73+ # Check if an error occured
74+ if (-not $errorOccured ) {
75+ $result.Message = " All OK"
76+ }
77+
78+ Write-PSFMessage - Message " Finished checking configurations" - Level Verbose
79+
80+ return $result
81+
3682}
0 commit comments