|
197 | 197 |
|
198 | 198 | # Dismounting the vhd |
199 | 199 | try { |
200 | | - if (Test-Path -Path $item.CloneLocation) { |
201 | | - Write-PSFMessage -Message "Dismounting disk $($item.CloneLocation) from $($item.HostName)" -Level Verbose |
202 | 200 |
|
203 | | - if ($computer.IsLocalhost) { |
204 | | - $null = Dismount-VHD -Path $item.CloneLocation |
205 | | - } |
206 | | - else { |
207 | | - $command = [scriptblock]::Create("Dismount-VHD -Path $($item.CloneLocation)") |
208 | | - $null = Invoke-PSFCommand -ComputerName $computer -ScriptBlock $command -Credential $Credential |
209 | | - } |
| 201 | + if ($computer.IsLocalhost) { |
| 202 | + $null = Dismount-VHD -Path $item.CloneLocation -Credential $Credential |
| 203 | + } |
| 204 | + else { |
| 205 | + $command = [ScriptBlock]::Create("Test-Path -Path $($item.CloneLocation)") |
| 206 | + Write-PSFMessage -Message "Dismounting disk $($item.CloneLocation) from $($item.HostName)" -Level Verbose |
| 207 | + $result = Invoke-PSFCommand -ComputerName $item.HostName -ScriptBlock $command -Credential $Credential |
| 208 | + #if (-not $result) { |
| 209 | + $command = [scriptblock]::Create("Dismount-VHD -Path `"$($item.CloneLocation)`"") |
| 210 | + $null = Invoke-PSFCommand -ComputerName $item.HostName -ScriptBlock $command -Credential $Credential |
| 211 | + #} |
210 | 212 | } |
211 | 213 | } |
212 | 214 | catch { |
|
216 | 218 | # Remove clone file and related access path |
217 | 219 | try { |
218 | 220 | if ($computer.IsLocalhost) { |
219 | | - if (Test-Path -Path $item.AccessPath) { |
220 | | - Write-PSFMessage -Message "Removing vhd access path" -Level Verbose |
221 | | - $null = Remove-Item -Path $item.AccessPath -Credential $Credential -Force |
222 | | - } |
223 | | - |
224 | | - if (Test-Path -Path $item.CloneLocation) { |
225 | | - Write-PSFMessage -Message "Removing vhd" -Level Verbose |
226 | | - $null = Remove-Item -Path $item.CloneLocation -Credential $Credential -Force |
227 | | - } |
| 221 | + Write-PSFMessage -Message "Removing vhd access path" -Level Verbose |
| 222 | + $null = Remove-Item -Path $item.AccessPath -Credential $Credential -Force |
| 223 | + |
| 224 | + Write-PSFMessage -Message "Removing vhd" -Level Verbose |
| 225 | + $null = Remove-Item -Path $item.CloneLocation -Credential $Credential -Force |
228 | 226 | } |
229 | 227 | else { |
230 | | - if (Test-Path -Path $item.AccessPath) { |
231 | | - Write-PSFMessage -Message "Removing vhd access path" -Level Verbose |
232 | | - $command = [scriptblock]::Create("Remove-Item -Path $($item.AccessPath) -Force") |
233 | | - $null = Invoke-PSFCommand -ComputerName $computer -ScriptBlock $command -Credential $Credential |
234 | | - } |
235 | | - |
236 | | - if (Test-Path -Path $item.CloneLocation) { |
237 | | - Write-PSFMessage -Message "Removing vhd" -Level Verbose |
238 | | - $command = [scriptblock]::Create("Remove-Item -Path $($item.CloneLocation) -Force") |
239 | | - $null = Invoke-PSFCommand -ComputerName $computer -ScriptBlock $command -Credential $Credential |
240 | | - } |
| 228 | + Write-PSFMessage -Message "Removing vhd access path" -Level Verbose |
| 229 | + $command = [scriptblock]::Create("Remove-Item -Path $($item.AccessPath) -Force") |
| 230 | + $null = Invoke-PSFCommand -ComputerName $item.HostName -ScriptBlock $command -Credential $Credential |
| 231 | + |
| 232 | + Write-PSFMessage -Message "Removing vhd" -Level Verbose |
| 233 | + $command = [scriptblock]::Create("Remove-Item -Path $($item.CloneLocation) -Force") |
| 234 | + $null = Invoke-PSFCommand -ComputerName $item.HostName -ScriptBlock $command -Credential $Credential |
241 | 235 | } |
242 | 236 | } |
243 | 237 | catch { |
|
0 commit comments