Skip to content

Commit 710754a

Browse files
committed
Merge branch 'development' into 'master'
Development See merge request sanderstad/PSDatabaseClone!9
2 parents 6330379 + 76ce841 commit 710754a

19 files changed

+1458
-651
lines changed

PSDatabaseClone.psd1

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@
7272
'Set-PSDCConfiguration',
7373
'Get-PSDCClone',
7474
'Get-PSDCImage',
75-
'Convert-PSDCLocalUncPathToLocalPath'
75+
'Convert-PSDCLocalUncPathToLocalPath',
76+
'New-PSDCVhdDisk',
77+
'Initialize-PSDCVhdDisk'
7678

7779
# Cmdlets to export from this module
7880
CmdletsToExport = ''

functions/Set-PSDCConfiguration.ps1

Lines changed: 0 additions & 195 deletions
This file was deleted.

functions/Get-PSDCClone.ps1 renamed to functions/clone/Get-PSDCClone.ps1

Lines changed: 79 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@
1919
Allows you to login to servers using SQL Logins as opposed to Windows Auth/Integrated/Trusted.
2020
This works similar as SqlCredential but is only meant for authentication to the PSDatabaseClone database server and database.
2121
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+
2227
.PARAMETER HostName
2328
Filter based on the hostname
2429
@@ -37,12 +42,17 @@
3742
.NOTES
3843
Author: Sander Stad (@sqlstad, sqlstad.nl)
3944
40-
Website: https://psdatabaseclone.io
45+
Website: https://psdatabaseclone.org
4146
Copyright: (C) Sander Stad, [email protected]
4247
License: MIT https://opensource.org/licenses/MIT
4348
4449
.LINK
45-
https://psdatabaseclone.io/
50+
https://psdatabaseclone.org/
51+
52+
.EXAMPLE
53+
Get-PSDCClone
54+
55+
Get all the clones
4656
4757
.EXAMPLE
4858
Get-PSDCClone -HostName host1, host2
@@ -66,6 +76,8 @@
6676
[System.Management.Automation.PSCredential]$SqlCredential,
6777
[System.Management.Automation.PSCredential]
6878
$PSDCSqlCredential,
79+
[System.Management.Automation.PSCredential]
80+
$Credential,
6981
[string[]]$HostName,
7082
[string[]]$Database,
7183
[int[]]$ImageID,
@@ -74,49 +86,77 @@
7486
)
7587

7688
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
8693
}
8794

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') {
9599

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;
112134
"
113135

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+
}
117143
}
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+
}
120160
}
121161

122162
# Filter host name

0 commit comments

Comments
 (0)