|
112 | 112 | $DestinationCredential,
|
113 | 113 | [System.Management.Automation.PSCredential]
|
114 | 114 | $PSDCSqlCredential,
|
115 |
| - [Parameter(Mandatory = $true)] |
116 |
| - [ValidateNotNullOrEmpty()] |
117 | 115 | [string]$ImageNetworkPath,
|
118 | 116 | [string]$ImageLocalPath,
|
119 | 117 | [Parameter(Mandatory = $true, ValueFromPipeline = $true)]
|
|
131 | 129 | return
|
132 | 130 | }
|
133 | 131 |
|
| 132 | + # Checking parameters |
| 133 | + if (-not $ImageNetworkPath) { |
| 134 | + Stop-PSFFunction -Message "Please enter the network path where to save the images" |
| 135 | + return |
| 136 | + } |
| 137 | + |
134 | 138 | # Get the information store
|
135 | 139 | $informationStore = Get-PSFConfigValue -FullName psdatabaseclone.informationstore.mode
|
136 | 140 |
|
|
207 | 211 | }
|
208 | 212 | }
|
209 | 213 |
|
210 |
| - # Check if Hyper-V is enabled |
211 |
| - if (-not (Test-PSDCHyperVEnabled -HostName $uriHost -Credential $DestinationCredential)) { |
212 |
| - Stop-PSFFunction -Message "Hyper-V is not enabled on the host." -ErrorRecord $_ -Target $uriHost |
213 |
| - return |
214 |
| - } |
215 |
| - |
216 | 214 | # Get the local path from the network path
|
217 | 215 | if (-not $ImageLocalPath) {
|
218 | 216 | if ($PSCmdlet.ShouldProcess($ImageNetworkPath, "Converting UNC path to local path")) {
|
|
232 | 230 | }
|
233 | 231 |
|
234 | 232 | Write-PSFMessage -Message "Converted '$ImageNetworkPath' to '$ImageLocalPath'" -Level Verbose
|
| 233 | + |
235 | 234 | }
|
236 | 235 | catch {
|
237 | 236 | Stop-PSFFunction -Message "Something went wrong getting the local image path" -Target $ImageNetworkPath
|
238 | 237 | return
|
239 | 238 | }
|
240 | 239 | }
|
241 | 240 | }
|
| 241 | + else { |
| 242 | + # Cleanup the values in the network path |
| 243 | + if ($ImageLocalPath.EndsWith("\")) { |
| 244 | + $ImageLocalPath = $ImageLocalPath.Substring(0, $ImageLocalPath.Length - 1) |
| 245 | + } |
| 246 | + |
| 247 | + # Check if the assigned value in the local path corresponds to the one retrieved |
| 248 | + try { |
| 249 | + # Check if computer is local |
| 250 | + if ($computer.IsLocalhost) { |
| 251 | + $convertedLocalPath = Convert-PSDCLocalUncPathToLocalPath -UncPath $ImageNetworkPath -EnableException |
| 252 | + } |
| 253 | + else { |
| 254 | + $command = "Convert-PSDCLocalUncPathToLocalPath -UncPath `"$ImageNetworkPath`" -EnableException" |
| 255 | + $commandGetLocalPath = [ScriptBlock]::Create($command) |
| 256 | + $convertedLocalPath = Invoke-PSFCommand -ComputerName $computer -ScriptBlock $commandGetLocalPath -Credential $DestinationCredential |
| 257 | + } |
| 258 | + |
| 259 | + Write-PSFMessage -Message "Converted '$ImageNetworkPath' to '$ImageLocalPath'" -Level Verbose |
| 260 | + |
| 261 | + # Check if the ImageLocalPath and convertedLocalPath are the same |
| 262 | + if ($ImageLocalPath -ne $convertedLocalPath) { |
| 263 | + Stop-PSFFunction -Message "The local path '$ImageLocalPath' is not the same location as the network path '$ImageNetworkPath'" -Target $ImageNetworkPath |
| 264 | + return |
| 265 | + } |
| 266 | + |
| 267 | + } |
| 268 | + catch { |
| 269 | + Stop-PSFFunction -Message "Something went wrong getting the local image path" -Target $ImageNetworkPath |
| 270 | + return |
| 271 | + } |
| 272 | + } |
242 | 273 |
|
243 | 274 | # Check the image local path
|
244 | 275 | if ($PSCmdlet.ShouldProcess("Verifying image local path")) {
|
|
269 | 300 | Stop-PSFFunction -Message "Please supply a database to create an image for" -Target $SourceSqlInstance -Continue
|
270 | 301 | }
|
271 | 302 |
|
| 303 | + # Check if Hyper-V is enabled |
| 304 | + if (-not (Test-PSDCHyperVEnabled -HostName $uriHost -Credential $DestinationCredential)) { |
| 305 | + Stop-PSFFunction -Message "Hyper-V is not enabled on the host." -ErrorRecord $_ -Target $uriHost |
| 306 | + return |
| 307 | + } |
| 308 | + |
272 | 309 | # Set time stamp
|
273 | 310 | $timestamp = Get-Date -format "yyyyMMddHHmmss"
|
274 | 311 |
|
|
543 | 580 | [array]$images = $null
|
544 | 581 |
|
545 | 582 | # Get all the images
|
546 |
| - try{ |
| 583 | + try { |
547 | 584 | $images = Get-PSDCImage
|
548 | 585 | }
|
549 |
| - catch{ |
| 586 | + catch { |
550 | 587 | Stop-PSFFunction -Message "Couldn't get images" -Target $imageName -ErrorRecord $_
|
551 | 588 | return
|
552 | 589 | }
|
|
0 commit comments