PowerShell get shadowstorage maxspace for C drive as string

977 views Asked by At

How would I go about getting the maxspace used by shadowstorage on C drive as a string in GB? Only thing I found so far is this cmdlet which lists all parameters:

get-wmiobject win32_shadowstorage

But I only need the valued of MaxSpace converted in GB and only for C drive. The purpose of this is for using in a wpf app later on as if/else statement. PowerShell seems to be the fastest way to achieve this and the "elderly" vssadmin seems only to accept parameters, not to retrieve anything...

Thanks in advance

1

There are 1 answers

0
JosefZ On BEST ANSWER

Run Get-WmiObject -Class "Win32_ShadowStorage". You can be interested in the following properties:

  • AllocatedSpace (Data type: uint64) Allocated space on the differential area volume.
  • DiffVolume     (Data type: Win32_Volume) Reference to the differential volume.
  • Volume         (Data type: Win32_Volume) Reference to the original volume.

Properties DiffVolume and Volume look like (GUID can vary)

Win32_Volume.DeviceID="\\\\?\\Volume{95570d86-0703-4b5c-8909-c967baecabd3}\\"

and this appearance invites you to check the Win32_Volume class, and Bingo! There is the DriveLetter property! Putting this together:

Get-WmiObject -Class "Win32_ShadowStorage" | 
ForEach-Object { 
    $aux = $_.Maxspace/1GB
    Get-WmiObject -Class "Win32_Volume" -Filter (
            $_.DiffVolume -replace 'Win32_Volume\.', '') | 
        Select-Object -Property DriveLetter, DeviceID | 
            Where-Object DriveLetter -eq 'C:' | 
                ForEach-Object { [string]$aux }
}