Skip to content

Commit 7304971

Browse files
committed
Fixed issues for paths with spaces
1 parent a0133c6 commit 7304971

File tree

4 files changed

+29
-13
lines changed

4 files changed

+29
-13
lines changed

functions/clone/Remove-PSDCClone.ps1

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -227,11 +227,11 @@
227227
$null = Dismount-VHD -Path $item.CloneLocation -Credential $Credential
228228
}
229229
else {
230-
$command = [ScriptBlock]::Create("Test-Path -Path $($item.CloneLocation)")
231-
Write-PSFMessage -Message "Dismounting disk $($item.CloneLocation) from $($item.HostName)" -Level Verbose
230+
$command = [ScriptBlock]::Create("Test-Path -Path '$($item.CloneLocation)'")
231+
Write-PSFMessage -Message "Dismounting disk '$($item.CloneLocation)' from $($item.HostName)" -Level Verbose
232232
$result = Invoke-PSFCommand -ComputerName $item.HostName -ScriptBlock $command -Credential $Credential
233233
#if (-not $result) {
234-
$command = [scriptblock]::Create("Dismount-VHD -Path `"$($item.CloneLocation)`"")
234+
$command = [scriptblock]::Create("Dismount-VHD -Path '$($item.CloneLocation)'")
235235
$null = Invoke-PSFCommand -ComputerName $item.HostName -ScriptBlock $command -Credential $Credential
236236
#}
237237
}
@@ -246,18 +246,18 @@
246246
try {
247247
if ($computer.IsLocalhost) {
248248
Write-PSFMessage -Message "Removing vhd access path" -Level Verbose
249-
$null = Remove-Item -Path $item.AccessPath -Credential $Credential -Force
249+
$null = Remove-Item -Path "$($item.AccessPath)" -Credential $Credential -Force
250250

251251
Write-PSFMessage -Message "Removing vhd" -Level Verbose
252-
$null = Remove-Item -Path $item.CloneLocation -Credential $Credential -Force
252+
$null = Remove-Item -Path "$($item.CloneLocation)" -Credential $Credential -Force
253253
}
254254
else {
255255
Write-PSFMessage -Message "Removing vhd access path" -Level Verbose
256-
$command = [scriptblock]::Create("Remove-Item -Path $($item.AccessPath) -Force")
256+
$command = [scriptblock]::Create("Remove-Item -Path '$($item.AccessPath)' -Force")
257257
$null = Invoke-PSFCommand -ComputerName $item.HostName -ScriptBlock $command -Credential $Credential
258258

259259
Write-PSFMessage -Message "Removing vhd" -Level Verbose
260-
$command = [scriptblock]::Create("Remove-Item -Path $($item.CloneLocation) -Force")
260+
$command = [scriptblock]::Create("Remove-Item -Path '$($item.CloneLocation)' -Force")
261261
$null = Invoke-PSFCommand -ComputerName $item.HostName -ScriptBlock $command -Credential $Credential
262262
}
263263
}

functions/image/New-PSDCImage.ps1

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,14 @@
543543
[array]$images = $null
544544

545545
# Get all the images
546-
$images = Get-PSDCImage
546+
try{
547+
$images = Get-PSDCImage
548+
}
549+
catch{
550+
Stop-PSFFunction -Message "Couldn't get images" -Target $imageName -ErrorRecord $_
551+
return
552+
}
553+
547554

548555
# Setup the new image id
549556
if ($images.Count -ge 1) {

functions/image/Remove-PSDCImage.ps1

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@
184184
# Check the result
185185
if ($resultPSRemote.Result) {
186186

187-
$command = [scriptblock]::Create("Import-Module PSDatabaseClone")
187+
$command = [scriptblock]::Create("Import-Module PSDatabaseClone -Force")
188188

189189
try {
190190
Invoke-PSFCommand -ComputerName $computer -ScriptBlock $command -Credential $Credential
@@ -237,15 +237,15 @@
237237
}
238238
}
239239
else {
240-
$command = [scriptblock]::Create("Test-Path -Path $($item.ImageLocation)")
240+
$command = [scriptblock]::Create("Test-Path -Path '$($item.ImageLocation)'")
241241
$result = Invoke-PSFCommand -ComputerName $computer -ScriptBlock $command -Credential $Credential
242242

243243
if ($result) {
244-
$command = [scriptblock]::Create("Remove-Item -Path $($item.ImageLocation) -Force")
244+
$command = [scriptblock]::Create("Remove-Item -Path '$($item.ImageLocation)' -Force")
245245
$result = Invoke-PSFCommand -ComputerName $computer -ScriptBlock $command -Credential $Credential
246246
}
247247
else {
248-
Write-PSFMessage -Message "Couldn't find image $($item.ImageLocation)" -Level Verbose
248+
Write-PSFMessage -Message "Couldn't find image '$($item.ImageLocation)'" -Level Verbose
249249
}
250250
}
251251
}

functions/support/Set-PSDCConfiguration.ps1

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,8 +311,17 @@
311311
else {
312312
# Create the JSON files
313313

314+
if ($null -eq $filePath) {
315+
$filePath = $Path
316+
}
317+
314318
# Create the PSDrive to be able to use credentials
315-
$null = New-PSDrive -Name PSDatabaseClone -PSProvider FileSystem -Root $filePath -Credential $Credential
319+
try {
320+
$null = New-PSDrive -Name PSDatabaseClone -PSProvider FileSystem -Root $filePath -Credential $Credential
321+
}
322+
catch {
323+
Stop-PSFFunction -Message "Couldn not create PS-Drive to JSON files" -Target $filePath
324+
}
316325

317326
# Create the files
318327
try {

0 commit comments

Comments
 (0)