PowerShell Get registry value data for backups

Scenario:

PowerShell Get registry value data for backups.

I have created this script for a specific reason. The reason is to avoid losing data and make sure that all data is included in the process of backups. Be aware that the script you will read below does not check data integrity of backups and health check. It only ensures you that all drives from each server will be included in the process during backup. When you are using VSS for backups a specific value in Windows registry can bring you a nightmare. There is a value in registry called DrivesToExclude that when you are backing up your Hyper-V Virtual Machines with VSS, it excludes those drives from backups. The value is under “HKLM:SYSTEM\CurrentControlSet\Control\BackupRestore\FilesNotToSnapshot“. In general the script retrieves data from the registry everyday and informs you for any wrong configuration on a server.

Let’s go in more detail on what it is going on in the script.

Firstly the script retrieves from Active Directory all computer objects under the servers organizational unit and saves the DNS names for those servers in a variable. Next you will see a function, which checks if the value exists or not and returns a true or false value. In the function I declare the path in registry and the key to check within the function. If the function will return true, then the script will retrieve that actual data of the registry key, by connecting to the specific server, that is used later to send it on email report. Please note here that, as I am also checking the server that the script is running on, I use a different command to check the specific server. If you use the same command as the other servers you will receive an error. Invoke-command is only used on remote servers and cannot be applied on this one.

At the end, if the specific registry key exists on a server and the script retrieved the actual key data on the server, an HTML email report is prepared. The HTML email report is send only if there is a server with the specific key configured. If nothing is found on the servers, no email will be sent. The table in the report includes the DNS name of the server, the value that the function returns, which is true or false and the actual registry key data. At the end of the script an error report is sent if there are any errors or exceptions while the script run. The error report is an HTML email with all values of the array of the default error variable. When the email is compiled, it will be sent and you will know if there was an error or exception thrown during the run.

You can download the script here or copy it from below.

Let me know your thoughts. You can comment below.

Related Links:

Solution / Script: