Today I will look at the basics of System Protection and how to monitor and/or manage it through Powershell, either remote or locally.
For this, we have multiple Powershell commands and ways to use those commands.
Let us look at a few options!
Now you might have done some research and think to yourself “But ... there are registry keys that seem to contain these settings” and you would be right. They “seem” to contain the values, they however also seem to not work on most Windows 10 versions. Changing them does not work for most Windows 10 devices.
Which brings me to the next point. While it should be possible to execute these commands on Windows 7 and 8/8.1 to, I have not fully tested this outside of Windows 10.
All of below scripts can be used and adjusted in various ways. These are just the basics that we can build scripts on, they can be made as extensive as you want.
So hereby the scripting. More information will follow underneath the code block.
1.1 and 1.2 are simple commands. You can combine this with information it retrieves information on which drives are attached to make it enable or disable it for all drives or even let it read out its settings from a .txt file to deploy the same settings to multiple devices.
I have to mention that this only works from the Powershell that the device in question sees as its default. For example, when I open the base Powershell on my device it opens the version 5.0 and the commands work. However, when I have a separate standalone Powershell (Like a manually installed Powershell 5.0, 6.0 or 7.0) it does not recognise the commands even when the correct modules are linked.
1.3 is interesting. The status of System Protection does not have an easy way be read out (mostly because as said above, we cannot rely on the registry keys).
The way I work around this is quite simple. What the script does is that it tries to create a checkpoint through System Protection.
If it makes a checkpoint, System Protection must be on.
If it gets back an error, it means it could not use System Protection and thus it is most likely off.
Due to the way it determines this, it gives more reliable results regardless of OS.
The vssadmin commands can not only be used in Powershell, but also in CMD.
2.1 allows us to change the amount of storage we use for one or multiple drives.
Not only can you use a percentage like /maxsize=10%, you can also use set amounts like /maxsize=500MB or /maxsize=2GB.
2.2 is for informational purpose. It gives back information on how much space is reserved for each drive. This information does not reflect whether the System protection that uses it is actually enabled!
2.3 allows you to fully clear out all shadow copies it has saved. Not much that could be more clear than that.
These scripts can be used for in multiple ways.
I myself for example run Windows Upgrades remotely. The thing with Windows Upgrades is that it resets the System Protection settings when it receives a feature upgrade.
So what I have used these commands for is to have them collect information on the settings before the upgrade. It then writes down the settings in a .txt file. After the upgrade I let it read out the .txt file and adjust the settings accordingly.
This allows me to keep System Protection settings even after Feature Upgrades.
Hoping someone else will have some use for this in their script,
Categories: Windows, Powershell, Script
Patrick Berger AKA Powershellder.
[ i ] Parallax section below. Click on the section below to upload image. Don't worry if it looks weird in the Weebly editor. It'll look normal on your published site.
To edit or delete your image, press the "toggle" button below. Then, hover over your image until a popup appears with the "edit" and "delete" options. If you don't want a white content section, leave it blank. It will disappear on your live website.