|
129 | 129 | $pdcSqlInstance = Get-PSFConfigValue -FullName psdatabaseclone.database.Server |
130 | 130 | $pdcDatabase = Get-PSFConfigValue -FullName psdatabaseclone.database.name |
131 | 131 | if (-not $PSDCSqlCredential) { |
132 | | - $pdcCredential = Get-PSFConfig -FullName psdatabaseclone.database.credential -Fallback $null |
| 132 | + $pdcCredential = Get-PSFConfigValue -FullName psdatabaseclone.database.credential -Fallback $null |
133 | 133 | } |
134 | | - else{ |
| 134 | + else { |
135 | 135 | $pdcCredential = $PSDCSqlCredential |
136 | 136 | } |
137 | 137 |
|
|
148 | 148 | # Try connecting to the instance |
149 | 149 | Write-PSFMessage -Message "Attempting to connect to Sql Server $SourceSqlInstance.." -Level Output |
150 | 150 | try { |
151 | | - $SourceServer = Connect-DbaInstance -SqlInstance $SourceSqlInstance -SqlCredential $SourceSqlCredential |
| 151 | + $sourceServer = Connect-DbaInstance -SqlInstance $SourceSqlInstance -SqlCredential $SourceSqlCredential |
152 | 152 | } |
153 | 153 | catch { |
154 | 154 | Stop-PSFFunction -Message "Could not connect to Sql Server instance $SourceSqlInstance" -ErrorRecord $_ -Target $SourceSqlInstance |
|
172 | 172 | # Setup the computer object |
173 | 173 | $computer = [PsfComputer]$uriHost |
174 | 174 |
|
175 | | - if (-not $computer.IsLocalhost) { |
| 175 | + # Check if Hyper-V is enabled |
| 176 | + if (-not (Test-PSDCHyperVEnabled -HostName $uriHost -Credential $DestinationCredential)) { |
| 177 | + Stop-PSFFunction -Message "Hyper-V is not enabled on the remote host." -ErrorRecord $_ -Target $uriHost |
| 178 | + return |
| 179 | + } |
176 | 180 |
|
| 181 | + # Check if the computer is localhost and import the neccesary modules... just in case |
| 182 | + if (-not $computer.IsLocalhost) { |
177 | 183 | $command = [ScriptBlock]::Create("Import-Module dbatools") |
178 | 184 | Invoke-PSFCommand -ComputerName $computer -ScriptBlock $command -Credential $DestinationCredential |
179 | 185 |
|
|
182 | 188 |
|
183 | 189 | $command = [ScriptBlock]::Create("Import-Module PSDatabaseClone") |
184 | 190 | Invoke-PSFCommand -ComputerName $computer -ScriptBlock $command -Credential $DestinationCredential |
185 | | - |
186 | | - $command = "Convert-PSDCLocalUncPathToLocalPath -UncPath '$ImageNetworkPath'" |
187 | | - $commandGetLocalPath = [ScriptBlock]::Create($command) |
188 | 191 | } |
189 | 192 |
|
190 | 193 | # Get the local path from the network path |
|
195 | 198 | $ImageLocalPath = Convert-PSDCLocalUncPathToLocalPath -UncPath $ImageNetworkPath |
196 | 199 | } |
197 | 200 | else { |
| 201 | + $command = "Convert-PSDCLocalUncPathToLocalPath -UncPath `"$ImageNetworkPath`"" |
| 202 | + $commandGetLocalPath = [ScriptBlock]::Create($command) |
198 | 203 | $ImageLocalPath = Invoke-PSFCommand -ComputerName $computer -ScriptBlock $commandGetLocalPath -Credential $DestinationCredential |
199 | 204 | } |
| 205 | + |
200 | 206 | Write-PSFMessage -Message "Converted '$ImageNetworkPath' to '$ImageLocalPath'" -Level Verbose |
201 | 207 | } |
202 | 208 | catch { |
|
224 | 230 | # Check the database parameter |
225 | 231 | if ($Database) { |
226 | 232 | foreach ($db in $Database) { |
227 | | - if ($db -notin $SourceServer.Databases.Name) { |
| 233 | + if ($db -notin $sourceServer.Databases.Name) { |
228 | 234 | Stop-PSFFunction -Message "Database $db cannot be found on instance $SourceSqlInstance" -Target $SourceSqlInstance |
229 | 235 | } |
230 | | - |
231 | | - $DatabaseCollection = $SourceServer.Databases | Where-Object { $_.Name -in $Database } |
232 | 236 | } |
| 237 | + |
| 238 | + $DatabaseCollection = $sourceServer.Databases | Where-Object { $_.Name -in $Database } |
233 | 239 | } |
234 | 240 | else { |
235 | 241 | Stop-PSFFunction -Message "Please supply a database to create an image for" -Target $SourceSqlInstance -Continue |
|
0 commit comments