locked
What's the WMI & powershell equivalent to vssadmin add shadowstorage /for=c: /on=d: ? RRS feed

  • Question

  • I need to enable shadowcopy on a Windows 2012 R2 and move the destination shadow copies to a secondary drive but I'm only granted WMI via powershell, no other .exe can be executed.

    I see a lot of various references in the WMI shadow provider with mention of for and on. How can I using WMI in powershell execute the similar command of: vssadmin add shadowstorage /for=c: /on=d: ? 

    This is my life :/

    Wednesday, December 20, 2017 12:17 PM

All replies

  • vssadmin is a command line tool and you can use it from Powershell as well. You might take a look at the help for this tool.  ;-)

    Edit: To figure out what WMI or better CIM classes are related to "shadow copies" you could try this:

    Get-CimClass -ClassName *shadow

    Best regards,

    (79,108,97,102|%{[char]$_})-join''


    • Edited by BOfH-666 Wednesday, December 20, 2017 1:14 PM
    Wednesday, December 20, 2017 1:10 PM
  • Thanks - I'm going to rubber ducky debug via this post in case someone can help me. I'm testing this at home on a Window 10 v1709 system right now which has a C & D drive in it:

    Name        : C:\
    DriveLetter : C:
    __PATH      : \\MAINFRAME\root\CIMV2:Win32_Volume.DeviceID="\\\\?\\Volume{f8e2b0ad-3658-11e5-94d0-806e6f6e6963}\\"
    DeviceID    : \\?\Volume{f8e2b0ad-3658-11e5-94d0-806e6f6e6963}\
    
    Name        : D:\
    DriveLetter : D:
    __PATH      : \\MAINFRAME\root\CIMV2:Win32_Volume.DeviceID="\\\\?\\Volume{eec3e61a-0000-0000-0000-100000000000}\\"
    DeviceID    : \\?\Volume{eec3e61a-0000-0000-0000-100000000000}\

    I figured out what I need to do but my syntax is wrong.

    I'm left with the classes in the original post:

    PS C:\WINDOWS\system32> Get-CimClass -ClassName *shadow*
    
    
       NameSpace: ROOT/CIMV2
    
    CimClassName                        CimClassMethods      CimClassProperties                                                                                                                                                                   
    ------------                        ---------------      ------------------                                                                                                                                                                   
    Win32_ShadowCopy                    {Create, Revert}     {Caption, Description, InstallDate, Name...}                                                                                                                                         
    Win32_ShadowProvider                {}                   {Caption, Description, InstallDate, Name...}                                                                                                                                         
    Win32_ShadowVolumeSupport           {}                   {Antecedent, Dependent}                                                                                                                                                              
    Win32_ShadowFor                     {}                   {Antecedent, Dependent}                                                                                                                                                              
    Win32_ShadowOn                      {}                   {Antecedent, Dependent}                                                                                                                                                              
    Win32_ShadowBy                      {}                   {Antecedent, Dependent}                                                                                                                                                              
    Win32_ShadowDiffVolumeSupport       {}                   {Antecedent, Dependent}                                                                                                                                                              
    Win32_ShadowContext                 {}                   {Caption, Description, SettingID, ClientAccessible...}                                                                                                                               
    Win32_ShadowStorage                 {Create}             {AllocatedSpace, DiffVolume, MaxSpace, UsedSpace...}                   

    I think I need to focus on Win32_ShadowStorage class because because of the method Create. Originally I thought just Win32_ShadowCopy but that has a revert method which is called out online as  being used to revert the whole system. I just need to move our existing destination so this page looks promising.

    Running this:

    $class = [wmiclass]'Win32_ShadowStorage'
    $methodname = 'Create'
    
    $class.psbase.GetMethodParameters($methodname).Properties | 
      Select-Object -Property Name, Type |
      Format-Table -AutoSize   

    gets me 

    # Name         Type
    # ----         ----
    # DiffVolume String
    # MaxSpace   UInt64
    # Volume     String

    and I noticed that:

    get-wmiobject win32_shadowstorage
    
    __GENUS          : 2
    __CLASS          : Win32_ShadowStorage
    __SUPERCLASS     : 
    __DYNASTY        : Win32_ShadowStorage
    __RELPATH        : Win32_ShadowStorage.DiffVolume="Win32_Volume.DeviceID=\"\\\\\\\\?\\\\Volume{f8e2b0ad-3658-11e5-94d0-806e6f6e6963}\\\\\"",Volume="Win32_Volume.DeviceID=\"\\\\\\\\?\\\\Volume{f8e2b0ad-3658-11e5-94d0-806e6f6e6963}\\\\\""
    __PROPERTY_COUNT : 5
    __DERIVATION     : {}
    __SERVER         : MAINFRAME
    __NAMESPACE      : root\cimv2
    __PATH           : \\MAINFRAME\root\cimv2:Win32_ShadowStorage.DiffVolume="Win32_Volume.DeviceID=\"\\\\\\\\?\\\\Volume{f8e2b0ad-3658-11e5-94d0-806e6f6e6963}\\\\\"",Volume="Win32_Volume.DeviceID=\"\\\\\\\\?\\\\Volume{f8e2b0ad-3658-11e5-94d0
                       -806e6f6e6963}\\\\\""
    AllocatedSpace   : 6430195712
    DiffVolume       : Win32_Volume.DeviceID="\\\\?\\Volume{f8e2b0ad-3658-11e5-94d0-806e6f6e6963}\\"
    MaxSpace         : 51067014348
    UsedSpace        : 5856886784
    Volume           : Win32_Volume.DeviceID="\\\\?\\Volume{f8e2b0ad-3658-11e5-94d0-806e6f6e6963}\\"
    PSComputerName   : MAINFRAME

    I'm assuming DiffVolume is where my shadowcopies would go. So I crafted a new ShadowStorage line:

    $class = 'Win32_ShadowStorage'
    $methodname = 'Create'
    [string]$DiffVolume = 'Win32_Volume.DeviceID=\\\\?\\Volume{eec3e61a-0000-0000-0000-100000000000}\\'
    [int64]$MaxSpace = '219588161699'
    [string]$Volume = 'Win32_Volume.DeviceID=\"\\\\\\\\?\\\\Volume{f8e2b0ad-3658-11e5-94d0-806e6f6e6963}\\\\\'
    
    Invoke-WmiMethod -Path $class -Name $methodname -ArgumentList $Volume, $DiffVolume, $MaxSpace

    However I get back:

    Invoke-WmiMethod : Input string was not in a correct format.
    At line:7 char:1
    + Invoke-WmiMethod -Path $class -Name $methodname -ArgumentList $Volume ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (:) [Invoke-WmiMethod], FormatException
        + FullyQualifiedErrorId : System.FormatException,Microsoft.PowerShell.Commands.InvokeWmiMethod

    I've also tried their syntax

    $Volume='Win32_Volume.DeviceID="\\\\?\\Volume{f8e2b0ad-3658-11e5-94d0-806e6f6e6963}\\"'

    and

    $Volume=((get-wmiObject -Class Win32_Volume -Namespace root\CIMV2 | where {$_.DriveLetter -eq 'C:'}) | select __RELPATH).__RELPATH

    and 

    Invoke-WmiMethod -Path $class -Name $methodname -ArgumentList (((get-wmiObject -Class Win32_Volume -Namespace root\CIMV2 | where {$_.DriveLetter -eq 'C:'}) | select __RELPATH).__RELPATH), `

    (((get-wmiObject -Class Win32_Volume -Namespace root\CIMV2 | where {$_.DriveLetter -eq 'D:'}) | select __RELPATH).__RELPATH), $MaxSpace

    but it still fails:
    Invoke-WmiMethod : Input string was not in a correct format.

    Any help would be appreciated.



    • Edited by Nathaniel B Thursday, December 21, 2017 2:17 AM powershell
    Thursday, December 21, 2017 2:14 AM
  • I don't think we can teach you how to sue WMI with ShadowCopy.  Try posting int Windows forum for SC or review the documentation on SC and how to use it.


    \_(ツ)_/

    Thursday, December 21, 2017 2:21 AM
  • Recent issues: https://www.reddit.com/r/PowerShell/comments/7jipms/wmi_shadow_copy_vssadmin_on_powershell_for/

    VSSADMIN is alive and well on Windows 10 1709. See the following.

    PS D:\scripts> vssadmin /?
    vssadmin 1.1 - Volume Shadow Copy Service administrative command-line tool
    (C) Copyright 2001-2013 Microsoft Corp.
    
    ---- Commands Supported ----
    
    Delete Shadows        - Delete volume shadow copies
    List Providers        - List registered volume shadow copy providers
    List Shadows          - List existing volume shadow copies
    List ShadowStorage    - List volume shadow copy storage associations
    List Volumes          - List volumes eligible for shadow copies
    List Writers          - List subscribed volume shadow copy writers
    Resize ShadowStorage  - Resize a volume shadow copy storage association


    \_(ツ)_/

    Thursday, December 21, 2017 2:25 AM
  • v1709 vssadmin does not include "add shadowstorage"

    C:\WINDOWS\system32>vssadmin add shadowstorage /for=c: /on=d: /maxsize=900mb
    vssadmin 1.1 - Volume Shadow Copy Service administrative command-line tool
    (C) Copyright 2001-2013 Microsoft Corp.

    Error: Invalid command.

    ---- Commands Supported ----

    Delete Shadows        - Delete volume shadow copies
    List Providers        - List registered volume shadow copy providers
    List Shadows          - List existing volume shadow copies
    List ShadowStorage    - List volume shadow copy storage associations
    List Volumes          - List volumes eligible for shadow copies
    List Writers          - List subscribed volume shadow copy writers
    Resize ShadowStorage  - Resize a volume shadow copy storage association

    C:\WINDOWS\system32>

    I've attempted to simplify my command to just this:

    Invoke-WmiMethod -class Win32_ShadowStorage -Name Create -ArgumentList @{ DiffVolume = 'C:'; MaxSpace = [UInt64]100GB; Volume = 'C:' }

    but it fails complaining about Invalid method Parameter(s):

    Invoke-WmiMethod : Invalid method Parameter(s) 
    At line:1 char:1
    + Invoke-WmiMethod -class Win32_ShadowStorage -Name Create -ArgumentLis ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidOperation: (:) [Invoke-WmiMethod], ManagementException
        + FullyQualifiedErrorId : InvokeWMIManagementException,Microsoft.PowerShell.Commands.InvokeWmiMethod


    Thursday, December 21, 2017 2:49 PM
  • Hi,

    This is a quick note to let you know that I am currently performing research on this issue and will get back to you as soon as possible. I appreciate your patience.

    If you have any updates during this process, please feel free to let me know.

    Best Regards,
    Albert

    Please remember to mark the replies as an answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Friday, December 22, 2017 9:42 AM
  • v1709 vssadmin does not include "add shadowstorage"

    Just so you understand shadows storage only servers have the ability to add shadowstorage. Workstations have never had that ability.

    On a workstation you can use "resize shadowstorage" to add or move the storage location and size for any volume.

    The API used by vssadmin and WMI are the same so WMI will not allow you perform server functions on a workstation.


    \_(ツ)_/

    Friday, December 22, 2017 10:12 AM