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

Fix disk shrink failure from missing disk image and partition objects #54

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

4oo4
Copy link

@4oo4 4oo4 commented Jan 28, 2022

This is a solution I found for when disk shrinking fails, and says it cannot get partition information: #43 (comment)

For some reason, Mount-DiskImage passthru will sometimes have a null value for the DiskNumber property, so this is piped into Get-DiskImage to preserve all properties.

Partition information ($partinfo) would fail silently, because when Get-Partition -DiskNumber $mountedDisk.Number -ErrorAction Stop only returns $null, but does not register as an exception, so the catch {} blocks would never fire. Instead, this is now partially handled through if statements.

Without these changes, in certain cases the script would execute, but not actually shrink any disks, and it would output that it could not get partition information in the logfile.

For some reason, `Mount-DiskImage` passthru will sometimes have a null value for the `DiskNumber` property, so this is piped into `Get-DiskImage`  to preserve all properties. 

Partition information (`$partinfo`) would fail silently, because when `Get-Partition -DiskNumber $mountedDisk.Number -ErrorAction Stop` only returns `$null`, but does not register as an exception, so the `catch {}` blocks would never fire. Instead, this is now partially handled through if statements.

Without these changes, in certain cases the script would execute, but not actually shrink any disks, and it would output that it could not get partition information in the logfile.
@PyroSoul630
Copy link

THANK YOU!!!!!!

I was able to use this script to finally get all of my Profiles compressed! I would really recommend reviewing this for a new final release.

I am so grateful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants