Search code examples
powershellmethodswmicim

Powershell CIM Method "Delete" is missing in Win32_ShadowCopy?


I try to switch from WMI to CIM, but there are methods missing: WMI way so select the next best VSS snapshot:

$SnapShot = (Get-WmiObject Win32_ShadowCopy)[0]

And then you have the working method:

$SnapShot.Delete()

However Get-CimInstance does not give me the methods by Design.

$SnapShot = (Get-CimInstance Win32_ShadowCopy)[0] and Get-CimClass -ClassName Win32_ShadowCopy only shows the methods "Create" and "Revert" - Where is the "Delete" method?

Normally if would be something like Invoke-CimMethod -ClassName Win32_ShadowCopy -MethodName "Delete" -Arguments @{ID="$SnapShot.ID"}. but no...

I've tried a lot of combinations to access or even see the "Delete" method, but where is it? WMI is not encouraged to use 'cause it is "old" when CIM is avail, but with CIM there are often methods missing or hidden somewhere non-obvious, like in this example.

Yes, I can use vssadmin.exe delete shadows /Shadow=$($SnapShot.ID) /Quiet but this is not the clean way, just a dirty workaround.


Solution

  • Probably pipe to remove-ciminstance like with win32_userprofile. .delete() is a made up method by get-wmiobject that does something similar.

    get-ciminstance win32_userprofile | ? localpath -match js2010 |remove-ciminstance