|
110 | 110 | ) |
111 | 111 |
|
112 | 112 | begin { |
| 113 | + # Check if the setup has ran |
| 114 | + if (-not (Get-PSFConfigValue -FullName psdatabaseclone.setup.status)) { |
| 115 | + Stop-PSFFunction -Message "The module setup has NOT yet successfully run. Please run 'Set-PSDCConfiguration'" |
| 116 | + return |
| 117 | + } |
| 118 | + |
113 | 119 | # Get the information store |
114 | 120 | $informationStore = Get-PSFConfigValue -FullName psdatabaseclone.informationstore.mode |
115 | 121 |
|
|
145 | 151 | if ($Disabled) { |
146 | 152 | $active = 0 |
147 | 153 | } |
| 154 | + |
| 155 | + # Set the location where to save the diskpart command |
| 156 | + $diskpartScriptFile = Get-PSFConfigValue -FullName psdatabaseclone.diskpart.scriptfile -Fallback "$env:APPDATA\psdatabaseclone\diskpartcommand.txt" |
148 | 157 | } |
149 | 158 |
|
150 | 159 | process { |
|
351 | 360 | try { |
352 | 361 | Write-PSFMessage -Message "Creating clone from $ParentVhd" -Level Verbose |
353 | 362 |
|
| 363 | + $command = "create vdisk file='$Destination\$CloneName.vhdx' parent='$ParentVhd'" |
| 364 | + |
354 | 365 | # Check if computer is local |
355 | 366 | if ($computer.IsLocalhost) { |
356 | | - $vhd = New-VHD -ParentPath $ParentVhd -Path "$Destination\$CloneName.vhdx" -Differencing |
| 367 | + # Set the content of the diskpart script file |
| 368 | + Set-Content -Path $diskpartScriptFile -Value $command -Force |
| 369 | + |
| 370 | + $script = [ScriptBlock]::Create("diskpart /s $diskpartScriptFile") |
| 371 | + $null = Invoke-PSFCommand -ScriptBlock $script |
357 | 372 | } |
358 | 373 | else { |
359 | 374 | $command = [ScriptBlock]::Create("New-VHD -ParentPath $ParentVhd -Path `"$Destination\$CloneName.vhdx`" -Differencing") |
|
366 | 381 |
|
367 | 382 | } |
368 | 383 | catch { |
369 | | - Stop-PSFFunction -Message "Could not create clone" -Target $vhd -Continue |
| 384 | + Stop-PSFFunction -Message "Could not create clone" -Target $vhd -Continue -ErrorRecord $_ |
370 | 385 | } |
371 | 386 | } |
372 | 387 |
|
|
378 | 393 | # Check if computer is local |
379 | 394 | if ($computer.IsLocalhost) { |
380 | 395 | # Mount the disk |
381 | | - $null = Mount-VHD -Path "$Destination\$CloneName.vhdx" -NoDriveLetter |
| 396 | + $null = Mount-DiskImage -ImagePath "$Destination\$CloneName.vhdx" |
382 | 397 |
|
383 | 398 | # Get the disk based on the name of the vhd |
384 | 399 | $disk = Get-Disk | Where-Object {$_.Location -eq "$Destination\$CloneName.vhdx"} |
385 | 400 | } |
386 | 401 | else { |
387 | 402 | # Mount the disk |
388 | | - $command = [ScriptBlock]::Create("Mount-VHD -Path `"$Destination\$CloneName.vhdx`" -NoDriveLetter") |
| 403 | + $command = [ScriptBlock]::Create("Mount-DiskImage -ImagePath `"$Destination\$CloneName.vhdx`"") |
389 | 404 | $null = Invoke-PSFCommand -ComputerName $computer -ScriptBlock $command -Credential $Credential |
390 | 405 |
|
391 | 406 | # Get the disk based on the name of the vhd |
|
0 commit comments