|
19 | 19 | Allows you to login to servers using SQL Logins as opposed to Windows Auth/Integrated/Trusted.
|
20 | 20 | This works similar as SqlCredential but is only meant for authentication to the PSDatabaseClone database server and database.
|
21 | 21 |
|
| 22 | + .PARAMETER Credential |
| 23 | + Allows you to login to servers or use authentication to access files and folder/shares |
| 24 | +
|
| 25 | + $scred = Get-Credential, then pass $scred object to the -Credential parameter. |
| 26 | +
|
22 | 27 | .PARAMETER HostName
|
23 | 28 | Filter based on the hostname
|
24 | 29 |
|
|
37 | 42 | .NOTES
|
38 | 43 | Author: Sander Stad (@sqlstad, sqlstad.nl)
|
39 | 44 |
|
40 |
| - Website: https://psdatabaseclone.io |
| 45 | + Website: https://psdatabaseclone.org |
41 | 46 | Copyright: (C) Sander Stad, [email protected]
|
42 | 47 | License: MIT https://opensource.org/licenses/MIT
|
43 | 48 |
|
44 | 49 | .LINK
|
45 |
| - https://psdatabaseclone.io/ |
| 50 | + https://psdatabaseclone.org/ |
| 51 | +
|
| 52 | + .EXAMPLE |
| 53 | + Get-PSDCClone |
| 54 | +
|
| 55 | + Get all the clones |
46 | 56 |
|
47 | 57 | .EXAMPLE
|
48 | 58 | Get-PSDCClone -HostName host1, host2
|
|
66 | 76 | [System.Management.Automation.PSCredential]$SqlCredential,
|
67 | 77 | [System.Management.Automation.PSCredential]
|
68 | 78 | $PSDCSqlCredential,
|
| 79 | + [System.Management.Automation.PSCredential] |
| 80 | + $Credential, |
69 | 81 | [string[]]$HostName,
|
70 | 82 | [string[]]$Database,
|
71 | 83 | [int[]]$ImageID,
|
|
74 | 86 | )
|
75 | 87 |
|
76 | 88 | begin {
|
77 |
| - |
78 |
| - # Get the module configurations |
79 |
| - $pdcSqlInstance = Get-PSFConfigValue -FullName psdatabaseclone.database.server |
80 |
| - $pdcDatabase = Get-PSFConfigValue -FullName psdatabaseclone.database.name |
81 |
| - if (-not $pdcCredential) { |
82 |
| - $pdcCredential = Get-PSFConfigValue -FullName psdatabaseclone.database.credential -Fallback $null |
83 |
| - } |
84 |
| - else { |
85 |
| - $pdcCredential = $PSDCSqlCredential |
| 89 | + # Check if the setup has ran |
| 90 | + if (-not (Get-PSFConfigValue -FullName psdatabaseclone.setup.status)) { |
| 91 | + Stop-PSFFunction -Message "The module setup has NOT yet successfully run. Please run 'Set-PSDCConfiguration'" |
| 92 | + return |
86 | 93 | }
|
87 | 94 |
|
88 |
| - # Test the module database setup |
89 |
| - try { |
90 |
| - Test-PSDCConfiguration -SqlCredential $pdcCredential -EnableException |
91 |
| - } |
92 |
| - catch { |
93 |
| - Stop-PSFFunction -Message "Something is wrong in the module configuration" -ErrorRecord $_ -Continue |
94 |
| - } |
| 95 | + # Get the information store |
| 96 | + $informationStore = Get-PSFConfigValue -FullName psdatabaseclone.informationstore.mode |
| 97 | + |
| 98 | + if ($informationStore -eq 'SQL') { |
95 | 99 |
|
96 |
| - $query = " |
97 |
| - SELECT c.CloneID, |
98 |
| - c.CloneLocation, |
99 |
| - c.AccessPath, |
100 |
| - c.SqlInstance, |
101 |
| - c.DatabaseName, |
102 |
| - c.IsEnabled, |
103 |
| - i.ImageID, |
104 |
| - i.ImageName, |
105 |
| - i.ImageLocation, |
106 |
| - h.HostName |
107 |
| - FROM dbo.Clone AS c |
108 |
| - INNER JOIN dbo.Host AS h |
109 |
| - ON h.HostID = c.HostID |
110 |
| - INNER JOIN dbo.Image AS i |
111 |
| - ON i.ImageID = c.ImageID; |
| 100 | + # Get the module configurations |
| 101 | + $pdcSqlInstance = Get-PSFConfigValue -FullName psdatabaseclone.database.server |
| 102 | + $pdcDatabase = Get-PSFConfigValue -FullName psdatabaseclone.database.name |
| 103 | + if (-not $PSDCSqlCredential) { |
| 104 | + $pdcCredential = Get-PSFConfigValue -FullName psdatabaseclone.informationstore.credential -Fallback $null |
| 105 | + } |
| 106 | + else { |
| 107 | + $pdcCredential = $PSDCSqlCredential |
| 108 | + } |
| 109 | + |
| 110 | + # Test the module database setup |
| 111 | + try { |
| 112 | + Test-PSDCConfiguration -SqlCredential $pdcCredential -EnableException |
| 113 | + } |
| 114 | + catch { |
| 115 | + Stop-PSFFunction -Message "Something is wrong in the module configuration" -ErrorRecord $_ -Continue |
| 116 | + } |
| 117 | + |
| 118 | + $query = " |
| 119 | + SELECT c.CloneID, |
| 120 | + c.CloneLocation, |
| 121 | + c.AccessPath, |
| 122 | + c.SqlInstance, |
| 123 | + c.DatabaseName, |
| 124 | + c.IsEnabled, |
| 125 | + i.ImageID, |
| 126 | + i.ImageName, |
| 127 | + i.ImageLocation, |
| 128 | + h.HostName |
| 129 | + FROM dbo.Clone AS c |
| 130 | + INNER JOIN dbo.Host AS h |
| 131 | + ON h.HostID = c.HostID |
| 132 | + INNER JOIN dbo.Image AS i |
| 133 | + ON i.ImageID = c.ImageID; |
112 | 134 | "
|
113 | 135 |
|
114 |
| - try { |
115 |
| - $results = @() |
116 |
| - $results = Invoke-DbaSqlQuery -SqlInstance $pdcSqlInstance -SqlCredential $pdcCredential -Database $pdcDatabase -Query $query -As PSObject |
| 136 | + try { |
| 137 | + $results = @() |
| 138 | + $results = Invoke-DbaSqlQuery -SqlInstance $pdcSqlInstance -SqlCredential $pdcCredential -Database $pdcDatabase -Query $query -As PSObject |
| 139 | + } |
| 140 | + catch { |
| 141 | + Stop-PSFFunction -Message "Could not execute query" -ErrorRecord $_ -Target $query |
| 142 | + } |
117 | 143 | }
|
118 |
| - catch { |
119 |
| - Stop-PSFFunction -Message "Could not execute query" -ErrorRecord $_ -Target $query |
| 144 | + elseif ($informationStore -eq 'File') { |
| 145 | + # Create the PS Drive and get the results |
| 146 | + try { |
| 147 | + if (Test-Path -Path "PSDCJSONFolder:\") { |
| 148 | + # Get the clones |
| 149 | + $results = Get-ChildItem -Path "PSDCJSONFolder:\" -Filter "*clones.json" | ForEach-Object { Get-Content $_.FullName | ConvertFrom-Json } |
| 150 | + } |
| 151 | + else { |
| 152 | + Stop-PSFFunction -Message "Could not reach clone information location 'PSDCJSONFolder:\'" -ErrorRecord $_ -Target "PSDCJSONFolder:\" |
| 153 | + return |
| 154 | + } |
| 155 | + } |
| 156 | + catch { |
| 157 | + Stop-PSFFunction -Message "Couldn't get results from JSN folder" -ErrorRecord $_ -Target "PSDCJSONFolder:\" |
| 158 | + return |
| 159 | + } |
120 | 160 | }
|
121 | 161 |
|
122 | 162 | # Filter host name
|
|
0 commit comments