Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Remove-Containerdata.ps1 fails when encounters mounted vhd #12

Open
fimblecog opened this issue Jan 17, 2020 · 1 comment
Open
Assignees
Labels
bug Something isn't working

Comments

@fimblecog
Copy link

Describe the bug
The script runs in its native form at first but then fails and kicks out when it encounters a VHD that is mounted.

To Reproduce
Have a user logged into a VDI desktop and run the script on their volume. When it comes to their vhd the script will fail and say that it can't identify a drive letter.

Expected behavior
I expect it to log that the disk is mounted and continue on.

Desktop (please complete the following information):

  • OS: Windows Server 2016 Standard

Additional context
Here's how I got it to keep going past the failure.

I inserted a function that I retrieved from another script that may be one of yours. I modified it some to make it work though.

function checkFileStatus($FileInfo)
{

    try 
    {
        $fileStream = $FileInfo.Open( [System.IO.FileMode]::Open, [System.IO.FileAccess]::Read)
        $filestream.Close()
        return $false
    }
    catch
    {
        
        return $true
    }
}

Then I inserted the bold text below to screen for mounted containers

  # Step through each Container
    ForEach ($container in $Containers) {


        ****$locked = checkFileStatus($container)
        If ($locked -eq $true) {continue}****
@aaronparker aaronparker self-assigned this Jan 23, 2020
@aaronparker aaronparker added the bug Something isn't working label Oct 9, 2020
@ssboparai
Copy link

I had the same issue. i used the following code instead of the Add-FSLDriverLetter module.

  1. Comment out
    #$MountPath = Add-FslDriveLetter -Path $container.FullName -Passthru
  2. Add the following code :
    $Disk = Mount-DiskImage -ImagePath $container.FullName -PassThru -NoDriveLetter -ErrorAction Stop | Get-Diskimage
    if ($Disk){
    set-partition -DiskNumber $Disk.Number -PartitionNumber 1 -NewDriveLetter Z -ErrorAction Stop
    $MountPath = "Z:"
    }else{$MountPath = $null
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants