Reduce the number of reboots in SCCM

sccm

One of the most asked questions for me about SCCM is “How can we reduce the number of reboots needed?

I know it sounds like a silly question, but let’s consider the following scenario. If you have (and most certainly do) Java, Adobe and Flash in your infrastructure, you already know by now that you have monthly updates for them. But they don’t all come at once, and if you have any other monthly software updates, the end-user will have to reboot (if necessary) the machine for each and every update that you push. I have seen situations where the user received 3 or 4 updates/day and each and every one had a soft-reboot in place in order for the package to place the user information. It gets a little bit frustrating don’t you think?

Yes, you could say that you can configure the deployment to consider the return code 0 and 3010 as success without reboot and just pop-up a message from the installation script of the package to inform the user to reboot…but that doesn’t solve the problem doesn’t it? The reboot is still needed…only not enforced by SCCM.

After some digging around i have come up with a simple solution..and that is Task Schedule.

By using a PowerShell script, you can get the current logged in user on the machine by a simple WMI query and create a Task Schedule that runs on his account to “repair” the application. Let’s see how we can do that.

Say we have an MSI that needs self-healing and doesn’t have an Advertised Shortcut. When you place it in SCCM you will modify the return code 0 to a soft reboot right?

Instead of that, create a simple batch file:

 

 msiexec /i YourMSI.msi /qb
PowerShell -NoProfile -ExecutionPolicy Bypass -Command "& './TaskSchedule.ps1'" 

Easy right? So what does the TaskSchedule.ps1 look like?

$user = Get-CimInstance –ClassName Win32_ComputerSystem | Select-Object UserName $computer = $env:COMPUTERNAME
$time = (get-date).AddMinutes(1).ToString("HH:mm")
schtasks /create /s $computer /tn "YourMSIRepair" /sc once /tr "msiexec /fus {ProductCode} /qb" /st $time /ru $user

 

So let’s break it down on what is actually happening.

$user = Get-CimInstance –ClassName Win32_ComputerSystem | Select-Object UserName

By using CimInstance we get the user that is currently logged in. The ouput will be domain\username.

$computer = $env:COMPUTERNAME

Self explanatory, we get the computer name.

$time = (get-date).AddMinutes(1).ToString("HH:mm")

Get the current time and add 1 minute. This is the minimum ammount of time you can add, you cannot set seconds.

The most important part:

schtasks /create /s $computer /tn "YourMSIRepair" /sc once /tr "msiexec /fus {ProductCode} /qb" /st $time /ru $user

We create a task on the current computer with the name “YourMSIRepair”, that will run only once the repair of the application, at the desired hour as described above, and this will run only on the current logged in user.

 

That’s it. Now implement your MSI in SCCM with the install.cmd created earlier and the PowerShell script besides it. After the MSI will finish installation (from system context), on the logged in user the repair will start in 1 minute.

This way the user doesn’t have to Log Off/Log On or Reboot the machine to receive the user information.

 

Leave a comment

Your email address will not be published. Required fields are marked *

four + nine =