|
251 | 251 | $accessPath = "$Destination\$mountDirectory" |
252 | 252 |
|
253 | 253 | # Check if access path is already present |
254 | | - if (-not (Test-Path -Path $accessPath -Credential $sou)) { |
| 254 | + if (-not (Test-Path -Path $accessPath -Credential $Credential)) { |
255 | 255 | try { |
256 | 256 | # Check if computer is local |
257 | 257 | if ($computer.IsLocalhost) { |
258 | | - |
| 258 | + $null = New-Item -Path $accessPath -ItemType Directory -Credential $Credential -Force |
259 | 259 | } |
260 | 260 | else { |
261 | | - $command = [ScriptBlock]::Create("") |
262 | | - $Destination = Invoke-PSFCommand -ComputerName $computer -ScriptBlock $command -Credential $Credential |
| 261 | + $command = [ScriptBlock]::Create("New-Item -Path $accessPath -ItemType Directory -Credential $Credential -Force") |
| 262 | + $null = Invoke-PSFCommand -ComputerName $computer -ScriptBlock $command -Credential $Credential |
263 | 263 | } |
264 | | - $null = New-Item -Path $accessPath -ItemType Directory -Credential $Credential -Force |
| 264 | + |
265 | 265 | } |
266 | 266 | catch { |
267 | 267 | Stop-PSFFunction -Message "Couldn't create access path directory" -ErrorRecord $_ -Target $accessPath -Continue |
|
279 | 279 |
|
280 | 280 | # Check if computer is local |
281 | 281 | if ($computer.IsLocalhost) { |
282 | | - |
| 282 | + $vhd = New-VHD -ParentPath $ParentVhd -Path "$Destination\$CloneName.vhdx" -Differencing |
283 | 283 | } |
284 | 284 | else { |
285 | | - $command = [ScriptBlock]::Create("") |
286 | | - $Destination = Invoke-PSFCommand -ComputerName $computer -ScriptBlock $command -Credential $Credential |
| 285 | + $command = [ScriptBlock]::Create("New-VHD -ParentPath $ParentVhd -Path '$Destination\$CloneName.vhdx' -Differencing") |
| 286 | + $vhd = Invoke-PSFCommand -ComputerName $computer -ScriptBlock $command -Credential $Credential |
287 | 287 | } |
288 | | - $vhd = New-VHD -ParentPath $ParentVhd -Path "$Destination\$CloneName.vhdx" -Differencing |
| 288 | + |
289 | 289 | } |
290 | 290 | catch { |
291 | 291 | Stop-PSFFunction -Message "Could not create clone" -Target $vhd -Continue |
|
297 | 297 |
|
298 | 298 | # Check if computer is local |
299 | 299 | if ($computer.IsLocalhost) { |
| 300 | + # Mount the disk |
| 301 | + $null = Mount-VHD -Path "$Destination\$CloneName.vhdx" -NoDriveLetter |
300 | 302 |
|
| 303 | + # Get the disk based on the name of the vhd |
| 304 | + $disk = Get-Disk | Where-Object {$_.Location -eq "$Destination\$CloneName.vhdx"} |
301 | 305 | } |
302 | 306 | else { |
303 | | - $command = [ScriptBlock]::Create("") |
304 | | - $Destination = Invoke-PSFCommand -ComputerName $computer -ScriptBlock $command -Credential $Credential |
305 | | - } |
306 | | - # Mount the disk |
307 | | - $null = Mount-VHD -Path "$Destination\$CloneName.vhdx" -NoDriveLetter |
308 | | - |
309 | | - # Get the disk based on the name of the vhd |
310 | | - $disk = Get-Disk | Where-Object {$_.Location -eq "$Destination\$CloneName.vhdx"} |
| 307 | + # Mount the disk |
| 308 | + $command = [ScriptBlock]::Create("Mount-VHD -Path `"$Destination\$CloneName.vhdx`" -NoDriveLetter") |
| 309 | + $null = Invoke-PSFCommand -ComputerName $computer -ScriptBlock $command -Credential $Credential |
311 | 310 |
|
| 311 | + # Get the disk based on the name of the vhd |
| 312 | + $command = [ScriptBlock]::Create("Get-Disk | Where-Object {$_.Location -eq `"$Destination\$CloneName.vhdx`"}") |
| 313 | + $disk = Invoke-PSFCommand -ComputerName $computer -ScriptBlock $command -Credential $Credential |
| 314 | + } |
312 | 315 | } |
313 | 316 | catch { |
314 | 317 | Stop-PSFFunction -Message "Couldn't mount vhd $vhdPath" -ErrorRecord $_ -Target $disk -Continue |
|
495 | 498 | } |
496 | 499 |
|
497 | 500 | # Add the results to the custom object |
498 | | - [PSDCClone]$clone = New-Object PSDCClone |
| 501 | + $clone = New-Object PSDCClone |
499 | 502 |
|
500 | 503 | $clone.CloneID = $result.CloneID |
501 | 504 | $clone.CloneLocation = $cloneLocation |
|
0 commit comments