0

I have been thinking to pull some data of the on a regular basis from our servers. I have done some researches and to find out which server is running VSS on what disk I found it challenging - or just hasn't found the right command.

The closes I got is this: vssadmin list shadowstorage but it is a powershell object that I can't figure out. WI get the result I need to search for strings like '(D:)' and get that line.

I would like to pick the drive and the space information in an array format, please.

Shadow Copy Storage association
   For volume: (G:)\\?\Volume{68cefbec-f673-467d-95ac-7e442df77cdb}\
   Shadow Copy Storage volume: (G:)\\?\Volume{68cefbec-f673-467d-95ac-7e442df77cdb}\
   Used Shadow Copy Storage space: 2.91 GB (0%)
   Allocated Shadow Copy Storage space: 5.80 GB (0%)
   Maximum Shadow Copy Storage space: 400 GB (19%)

Edit: I would like to get these data out:

Computername: xxxxxxxsvr01 
Drive (where VSS running on the drive): G:
Allocated Shadows Storage space: 5.80GB
Next run date: which I have no clue how to get it yet

All in a string array so I can play with it.

If someone could bring some light on this dark topic I would much appreciated.

TryHarder
  • 750
  • 1
  • 9
  • 22
  • would the WMI-Object work for your purposes? http://stackoverflow.com/questions/12159341/how-to-get-disk-capacity-and-free-space-of-remote-computer – Trey Nuckolls Oct 13 '16 at 15:41
  • Hi I have edited my query I think that not really gives info about the VSS on each drives? – TryHarder Oct 13 '16 at 15:48

2 Answers2

2

vssadmin is a commandline tool, not a PowerShell cmdlet. It generates string output, so you'd need to parse the information from the string if you want to turn it into an object.

$pattern = 'for volume: \((.*?)\)[\s\S]*?' +
           'used.*?space: (\d+.*?b)[\s\S]*?' +
           'allocated.*?space: (\d.*?b)'

& vssadmin list shadowstorage | Out-String |
  Select-String $pattern -AllMatches |
  Select-Object -Expand Matches |
  ForEach-Object {
    New-Object -Type PSObject -Property @{
      ComputerName   = $env:COMPUTERNAME
      Drive          = $_.Groups[1].Value
      UsedSpace      = $_.Groups[2].Value
      AllocatedSpace = $_.Groups[3].Value
    }
  }

A better way might be to query the Win32_ShadowStorage WMI class. The next run time can be obtained from the respective scheduled task.

Get-WmiObject -Class Win32_ShadowStorage |
  Select-Object PSComputername, @{n='Drive';e={([wmi]$_.Volume).DriveLetter}},
                AllocatedSpace, UsedSpace,
                @{n='NextRunTime';e={
                  $volume = ([wmi]$_.Volume).DeviceId -replace '[\\?]'
                  (Get-ScheduledTaskInfo "ShadowCopy$volume").NextRunTime
                }}
Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
  • Thank you very much for your detailed info. I will check it soon and will get back to you. Much appreciate your time and willingness. – TryHarder Oct 18 '16 at 21:48
0

vssadmin doesn't return a PowerShell object, it just prints text to the standard output. What you get is an array where each line of text is one item. This is convenient if you want to process the output line by line.

You will need to parse the text to get the desired values.

Example:

switch -Regex (vssadmin list shadowstorage | ? { $_ -like '   *' }) {

    'For volume: \((.+)\)' { "Volume $($Matches[1])" }

    'Shadow Copy Storage volume:' { }

    'Used Shadow Copy Storage space: ([\d|.]+) GB' { "Used: $($Matches[1]) GB" }

    'Allocated Shadow Copy Storage space: ([\d|.]+) GB' { "Allocated: $($Matches[1]) GB" }

    'Maximum Shadow Copy Storage space: ([\d|.]+) GB' { "Maximum: $($Matches[1]) GB" }

    default { "This line is not recognized yet (add a rule): $_" }
}