Summary: Microsoft Scripting Guy, Ed Wilson, talks about using Windows PowerShell Desired State Configuration to configure a system restore.
Microsoft Scripting Guy, Ed Wilson, is here. It is nearly the weekend in Charlotte, North Carolina. I decided to arise early, grab my Surface Pro 3, and head upstairs to check my email sent to scripter@microsoft.com while I sip a cup of Earl Gray tea. I usually like Fridays because I try to avoid Friday meetings, and it means that I have all day to complete my projects for the weekend.
By using the xWindowsRestore module from the DSC Resource Kit, I can easily enable or disable System Restore on my client workstations running Windows 8.1 or Windows 8. I can enable it per drive, but I cannot set the amount of drive space that is used by System Restore. To do that, I need to use the SystemRestoreConfig WMI class that is found in the Root/Default WMI namespace. A command to query this WMI class is shown here:
Get-CimInstance -Namespace root/DEFAULT -ClassName SystemRestoreConfig
The thing that is really cool, is that the script to configure a Windows restore is very similar to the one I wrote yesterday to create a system restore point: Use Desired State Configuration to Create System Restore Point.
In fact, the first portion of the script is exactly the same. I call the Configuration keyword, retrieve my list of client workstations, and import the xWindowsRestore module. This is shown here:
Configuration ConfigureSystemRestore
{
Param
(
[String[]]$NodeName = (
(Get-ADComputer -Filter "OperatingSystem -like 'Windows 8*'").name)
)
Import-DSCResource -ModuleName xWindowsRestore
For the nodes, I then call the xSystemRestore provider and ensure that the system restore is Present (which means “Turn it on”), and I specify the drive. Here is that section of the script:
Node $NodeName
{
xSystemRestore SystemRestoreExample
{
Ensure = "Present"
Drive = "C:\"
}
}
The last thing I do is call the configuration, specify the output, and then use Start-DSCConfiguration to actually perform the configuration:
ConfigureSystemRestore -output C:\serverConfig
Start-DscConfiguration -Path C:\serverConfig -Wait -Force -Verbose
One thing that is pretty cool is that if I do not know what a particular DSC resource provides, I can highlight it and use the Start IntelliSensecommand from the Edit menu to tell me what it provides. I can also highlight the resource and press CTRL plus Spacebar because that is the keyboard shortcut for the Start IntelliSensecommand. Here is an example of using IntelliSense to tell me what a resource provides:
The complete configuration script is:
#Requires -version 4.0
Configuration ConfigureSystemRestore
{
Param
(
[String[]]$NodeName = (
(Get-ADComputer -Filter "OperatingSystem -like 'Windows 8*'").name)
)
Import-DSCResource -ModuleName xWindowsRestore
Node $NodeName
{
xSystemRestore SystemRestoreExample
{
Ensure = "Present"
Drive = "C:\"
}
}
}
ConfigureSystemRestore -output C:\serverConfig
Start-DscConfiguration -Path C:\serverConfig -Wait -Force -Verbose
That is all there is to using DSC to configure a system restore on a computer running Windows 8.1 or Windows 8. Join me tomorrow when I will talk about more cool Windows PowerShell stuff.
I invite you to follow me on Twitter and Facebook. If you have any questions, send email to me at scripter@microsoft.com, or post your questions on the Official Scripting Guys Forum. See you tomorrow. Until then, peace.
Ed Wilson, Microsoft Scripting Guy