Skip to content

Commit 5830b07

Browse files
committed
Fixed remote execution. FIxed return object
1 parent f87e26a commit 5830b07

1 file changed

Lines changed: 21 additions & 18 deletions

File tree

functions/New-PSDCClone.ps1

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -251,17 +251,17 @@
251251
$accessPath = "$Destination\$mountDirectory"
252252

253253
# 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)) {
255255
try {
256256
# Check if computer is local
257257
if ($computer.IsLocalhost) {
258-
258+
$null = New-Item -Path $accessPath -ItemType Directory -Credential $Credential -Force
259259
}
260260
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
263263
}
264-
$null = New-Item -Path $accessPath -ItemType Directory -Credential $Credential -Force
264+
265265
}
266266
catch {
267267
Stop-PSFFunction -Message "Couldn't create access path directory" -ErrorRecord $_ -Target $accessPath -Continue
@@ -279,13 +279,13 @@
279279

280280
# Check if computer is local
281281
if ($computer.IsLocalhost) {
282-
282+
$vhd = New-VHD -ParentPath $ParentVhd -Path "$Destination\$CloneName.vhdx" -Differencing
283283
}
284284
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
287287
}
288-
$vhd = New-VHD -ParentPath $ParentVhd -Path "$Destination\$CloneName.vhdx" -Differencing
288+
289289
}
290290
catch {
291291
Stop-PSFFunction -Message "Could not create clone" -Target $vhd -Continue
@@ -297,18 +297,21 @@
297297

298298
# Check if computer is local
299299
if ($computer.IsLocalhost) {
300+
# Mount the disk
301+
$null = Mount-VHD -Path "$Destination\$CloneName.vhdx" -NoDriveLetter
300302

303+
# Get the disk based on the name of the vhd
304+
$disk = Get-Disk | Where-Object {$_.Location -eq "$Destination\$CloneName.vhdx"}
301305
}
302306
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
311310

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+
}
312315
}
313316
catch {
314317
Stop-PSFFunction -Message "Couldn't mount vhd $vhdPath" -ErrorRecord $_ -Target $disk -Continue
@@ -495,7 +498,7 @@
495498
}
496499

497500
# Add the results to the custom object
498-
[PSDCClone]$clone = New-Object PSDCClone
501+
$clone = New-Object PSDCClone
499502

500503
$clone.CloneID = $result.CloneID
501504
$clone.CloneLocation = $cloneLocation

0 commit comments

Comments
 (0)