Skip to content

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

@fimblecog

Description

@fimblecog

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}****

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions