"I want to patch my workstations, but I'd like to have a System Restore done before hand, and also be able to have patching verify this has been done before hand."
So that got me thinking; well I know we could run a PowerShell command to enable and create a system restore point.
*NOTE this only works with workstation class OS's. There is a role for Windows Backup you can add for servers. I will add a snippet example doing something similar for that as well.
enable system restore:
Enable-ComputerRestore -drive "c:\"
Create a restore point:
Checkpoint-Computer -description "My_first_checkpoint" -restorepointtype "Modify_Settings"
Source: http://mcpmag.com/articles/2012/02/21/powershell-windows-restore.aspx
How to run this above command from the K1 using Launch a Program:
NOTE: I found in the description, you can not use spaces
However, I wanted to take that a step further, and setup a Smart Label that includes only systems that have had a system restore point in the last 24 hours.
To accomplish this, i would need to get a date of the last checkpoint into the K1000 in a date type format so I can use date operators on it.
For that, I introduce to you the ShellCommandDateReturn custom inventory rule!
To get the last date of the last system restore point created, I run this:
get-computerrestorepoint | format-table @{Label=" "; Expression={$_.ConvertToDateTime($_.CreationTime)}} -HideTableHeaders
This should output something like this:
(If you want to see the whole enchilada, you can run just get-computerrestorepoint to see all the details and verify the output above)
From there, I tried using just the command above in my shellcommanddatereturn rule:
ShellCommandDateReturn(cmd /q /c powershell.exe -command "get-computerrestorepoint | Sort-Object -property CreationTime -descending | Select-Object -first 1 | format-table @{Label=' '; Expression={$_.ConvertToDateTime($_.CreationTime)}} -HideTableHeaders")
And it worked beautifully!
Now I can make a smart label based off of that date:
BONUS:
Someone shared this with me a while ago and thought I'd share it here since it helps me immensely when looking for my custom inventory rules under Software:
Create a Software Custom Inventory Label with the following MySQL query:
SELECT ID FROM SOFTWARE
WHERE (SOFTWARE.IS_MANUAL='1')
AND ((SOFTWARE.INVENTORY_RULE != ''))
This will show you all your custom inventory rules. Enjoy!
If anyone has an example of one running (any powershell script) in 6.3, let me know - brucegoose03 9 years ago
ShellCommandDateReturn(cmd /q /c powershell.exe -command "get-computerrestorepoint | Sort-Object -property CreationTime -descending | Select-Object -first 1 | format-table @{Label=' '; Expression={$_.ConvertToDateTime($_.CreationTime)}} -HideTableHeaders")
Does 6.3 allow offline scripts to run at every checkin? Or are you running the script as an online script? - flip1001 9 years ago
Has anyone else who has used this experienced the same thing? Do you think this is from the PowerShell command, or the ShellCommandDateReturn rule? - ondrar 9 years ago
Thanks for the advice, and sorry for muddying up this post with an unrelated problem. - ondrar 9 years ago