How to enable volume shadow copy on specific drive (D:, E:,...) and set up schedule using Powershell ?
I just need some hints how to start.
How to enable volume shadow copy on specific drive (D:, E:,...) and set up schedule using Powershell ?
I just need some hints how to start.
You can create a Shadow copy on a specific drive using WMI object like it's explained in Microsoft Article.
Enable volume shadow copy on specific drive (D:, E:,...) is two things
It took me a little while to get this to worked (after finding the simple error causing it to fail), and the function is incomplete. I want to add the ability to enable it on a remote computer, which will probably have to be done via a task that is ran once. If anybody modifies this and adds that, let me know!
Even though this works, and it mimics what happens when you do it via the GUI, it still shows as disabled for that drive. But if you enable it, nothing changes! (LOL) I'm guessing there's something that needs to also be modified in the registry.
After a whole bunch of messing with it, got it to work slightly differently (it also seems to show up properly via the GUI).
Shoutouts to this page for a bit of help: https://social.technet.microsoft.com/forums/windowsserver/en-US/fb69840d-5f52-4711-8168-2faa23088233/shadow-copy-schedule-per-script
The downside to using schtasks (what that page uses) is that you can't have multiple triggers as far as I can see.
Also because of the way I troubleshot the solution (Used a bindiff of working/not working xml), I'm not entirely convinced that the flags I use are optimal.
Simpler means using schtasks that shows in the UI, compatible in PowerShell 2. Designed for a standard build, may need to play about with $volumeinfo[x] when creating $taskrun to find the appropriate volume.
Can configure the following arguments appropriately:
NOTE: The /TR switch REQUIRES the space at the end, if it is not there it replaces the final backslash with a double quote causing the VSS UI to not recognise the task.
Shadow Copy is actually enabled by creating tasks that call vssadmin.exe.
PowerShell 3.0 has cmdlets that enable you to create tasks, but these depend upon syscalls that weren't implemented until Windows 8 / Windows Server 2012. You need the following three of these cmdlets to do this the PowerShell way:
In earlier versions of Windows, you will be restricted to using schtasks.exe.
However -- and this is where this answer differs from the others -- creating a Shadow Copy task in these ways is not the right way to do things, as any changes you make will not show up in the GUI. As such, an unobservant user may be unaware that Shadow Copy has been enabled, thus resulting in them enabling a second instance of it, or worse silently overwriting your task (if you followed Windows's naming conventions (VolumeShadowCopy{$GUID})).
What you need to do, is create one via the GUI (preferably on Win7/Win2008, as newer versions of Windows use taskxml 1.2 by default instead of the more compatible taskxml 1.1), export the task as XML via schtasks, programmatically edit that XML, save that XML as UTF16, and import it. Thankfully, once you get past the GUI at the beginning, this can all be done on the commandline.
I would like to post code, but what I wrote is proprietary, and I do not have permission from my employer. I hope that the XML tip will, at the very least, save you countless hours. I just deployed the XML solution across hundreds of managed servers, to great success.
This is what I use in PowerShell. Its a link to my site, but it looks a lot better than it does pasted here.
Thanks to everyone, that was contributing to this thread. It was helpful and saved me a lot of work. The following PowerShell Script was tested on Windows Server 2008 R2.
The following example creates a Snapshot every 2h between Mo.-Fr. from 08:00h-18:00h on Volume C:
If you want to modify the schedule just edit or replace the inline XML-Data.
Attention: No warranty. No responsibiltiy. Please test in your own lab before use in production enviroment.
The best I can do is point you here, and specifically point out this one and this one.
Neither address exactly what you're looking for, but I will point out you can create shadow copies at any point as VSS is a background service that runs until called.
I got exactly what i needed with the following code, my requirement was to configure VSS but also it needed to be visible in the GUI. The key part to make it visible in the GUI is to add the volume ID in the scheduled task name as pointed by user261949 (that's a bit strange, honestly i was searching for a registry key but i found absolutely nothing..). I ended up with the following code that suits my needs:
Thanks all for your useful informations !
This is the easiest way to enable Shadow copies via powershell, it works in Windows 10