Need to create a shapshot of something before playing with the operating system? Or how about you’re doing something in Powershell and would like to have the ability to step back in time in the file system BEFORE you make that change?
I was digging through the old sample vbScripts from “Hey Scripting Guy” and found one in vbScript. But as always, I like to see how it works in Powershell. Especially if it’s a WMI script. It also presumes you already have Shadow Copy enabled. So the ORIGINAL sample to create a shadow copy with vbScript looked like this.
vbScript Code
Const VOLUME = "C:\"
Const CONTEXT = "ClientAccessible"
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set objShadowStorage = objWMIService.Get("Win32_ShadowCopy")
errResult = objShadowStorage.Create(VOLUME, CONTEXT, strShadowID)
If you have Shadow copy enabled, it’s a single one liner through WMI
(Get-WmiObject -list win32_shadowcopy).Create("C:\","ClientAccessible")
Just substitute in C: for the drive you’re doing a shapshot of. This of course presumes Shadow Copy is already enabled on the drive in Question.
If you’d like this can easily be made into a Function you can drop into a script or your Powershell Profile.
function global:CREATE-SHADOW ( $Drive ) { (Get-WmiObject -list win32_shadowcopy).Create($Drive,"ClientAccessible") }
So yes, you can do it in vbScript; but converting to Powershell is almost painless
The Power if Shell is in YOU
Sean
The Energized Tech




Q. What sort of star is dangerous?
http://www.uponwatches.net
interesting article. I like your take on this matter. Although there are a few points I diverge on though. But I think that clears up a few issues for me personally. Anyone else think so?
http://www.uponwatches.net/Watches-Panerai.html