vssadmin - how to get the Shadow ID & Volume Name as variables?

This topic contains 2 replies, has 2 voices, and was last updated by Profile photo of mc1903 mc1903 6 months, 1 week ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #36754
    Profile photo of mc1903
    mc1903
    Participant

    Hi,

    I am trying to use vssadmin.exe within a Windows 2012 R2 server Powershell script, but I cannot workout how to get the Shadow ID & Volume Name as variables?


    vssadmin create shadow /for=C:

    vssadmin 1.1 - Volume Shadow Copy Service administrative command-line tool
    (C) Copyright 2001-2013 Microsoft Corp.

    Successfully created shadow copy for 'C:\'
    Shadow Copy ID: {b01a4dab-61b0-4cfb-908c-94278500b10d}
    Shadow Copy Volume Name: \\?\GLOBALROOT\Device\HarddiskVolumeShadowCopy853

    Any help will be appreciated.

    Thanks
    M

    #36758
    Profile photo of Matt Bloomfield
    Matt Bloomfield
    Participant

    As it's a script, I guess it doesn't matter if you don't see output for vssadmin?

    Select the two strings from the command's output and assign them to a variable.
    Split the strings and select the second element, trim to remove white space.

    $string = vssadmin create shadow /for=C: | Select-String 'Shadow Copy ID','Shadow Copy Volume'
    
    $id = ($string[0] -split 'ID:')[1].trim()
    
    $Volume = ($string[1] -split 'Name:')[1].trim()
    
    Write-Output "ID = $id, Volume = $Volume"
    

    This only handles your example, if you were using list shadows you'd need a different technique as you'll probably have multiple IDs and volume names.

    #36773
    Profile photo of mc1903
    mc1903
    Participant

    Thank you Matt, that is exactly what I needed.

    Without great people like yourself, I would be completely lost with PowerShell.!!

    Thank you again.

    M

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.