Skip to content

Commit 5b55aea

Browse files
committed
Added check to see if JSON folder exists
1 parent 261f652 commit 5b55aea

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

functions/clone/New-PSDCClone.ps1

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@
360360
$command = [ScriptBlock]::Create("New-VHD -ParentPath $ParentVhd -Path `"$Destination\$CloneName.vhdx`" -Differencing")
361361
$vhd = Invoke-PSFCommand -ComputerName $computer -ScriptBlock $command -Credential $Credential
362362

363-
if(-not $vhd){
363+
if (-not $vhd) {
364364
return
365365
}
366366
}
@@ -562,6 +562,19 @@
562562
FQDN = $fqdn
563563
}
564564

565+
# Test if the JSON folder can be reached
566+
if (-not (Test-Path -Path "PSDCJSONFolder:\")) {
567+
$command = [scriptblock]::Create("Import-Module PSDatabaseClone -Force")
568+
569+
try {
570+
Invoke-PSFCommand -ComputerName $computer -ScriptBlock $command -Credential $Credential
571+
}
572+
catch {
573+
Stop-PSFFunction -Message "Couldn't import module remotely" -Target $command
574+
return
575+
}
576+
}
577+
565578
# Setup the json file
566579
$jsonHostFile = "PSDCJSONFolder:\hosts.json"
567580

@@ -668,6 +681,19 @@
668681
IsEnabled = $active
669682
}
670683

684+
# Test if the JSON folder can be reached
685+
if (-not (Test-Path -Path "PSDCJSONFolder:\")) {
686+
$command = [scriptblock]::Create("Import-Module PSDatabaseClone -Force")
687+
688+
try {
689+
Invoke-PSFCommand -ComputerName $computer -ScriptBlock $command -Credential $Credential
690+
}
691+
catch {
692+
Stop-PSFFunction -Message "Couldn't import module remotely" -Target $command
693+
return
694+
}
695+
}
696+
671697
# Set the clone file
672698
$jsonCloneFile = "PSDCJSONFolder:\clones.json"
673699

functions/image/New-PSDCImage.ps1

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,19 @@
578578
CreatedOn = (Get-Date -format "yyyyMMddHHmmss")
579579
}
580580

581+
# Test if the JSON folder can be reached
582+
if (-not (Test-Path -Path "PSDCJSONFolder:\")) {
583+
$command = [scriptblock]::Create("Import-Module PSDatabaseClone -Force")
584+
585+
try {
586+
Invoke-PSFCommand -ComputerName $computer -ScriptBlock $command -Credential $Credential
587+
}
588+
catch {
589+
Stop-PSFFunction -Message "Couldn't import module remotely" -Target $command
590+
return
591+
}
592+
}
593+
581594
# Set the image file
582595
$jsonImageFile = "PSDCJSONFolder:\images.json"
583596

0 commit comments

Comments
 (0)