in

myITforum.com

This Blog

Syndication

1E Blog

Empowering Efficient IT

May 2009 - Posts

  • Machines awaiting reboot due to PendingFileRenameOperations

    Introduction

    As we know, many desktop computers do not get rebooted for long periods of time and many laptop users almost never shutdown their computer and just merely “close the lid”.  Because of this, the “pending reboot/file rename” is persisted and usually goes undetected.  Case-in-point:  After implementing this at a customer site, more than half of their computers needed to be rebooted due to a pending file rename…and they never knew it.

    A “pending file rename operation” occurs when an install needs to rename files that are in-use at the time of the install, and is waiting to have the rename completed as part of the next reboot.  Some applications will first check to see if this condition exists before installing it’s app or software (some hotfixes will not install because of this).  This is a common practice amongst software patches and updates, service packs and anti-virus updates just to name a few.

    To make this very (fun) practical and to ease your administrative duties, I’m going to provide instructions to implementing a solution that will “dynamically automate” (aahh…longtime FAVORITE phrase in IT!!!) the rebooting of all computers - running desktop OS’es -, that are awaiting a reboot due to “pending file rename operation”.

    • Create a package to reboot computers
    • Create and Assign an advertisement to the collection to reboot the computers

    Create a package to reboot computers

     


    Package program properties

    Download GracefuLReboot.vbs (by Steve Pruitt)and use it as the source-file(s) for the package.  Then create a package program with the Command-Line property as GracefuLReboot.vbs n (e.g. “n” being a numeric value for the amount of time to surpass before (re)prompting the logged-on user to reboot, should they decline during the previous attempt.  In my screen-capture below, I used “1” to represent prompting the logged-on user every 1 minute.  This is ok since it is just my lab environment.  If you want to prompt users every 60 minutes should they decline the reboot, then make the numeric value 60.  Keep in mind, this parameter only applies when NightWatchman is NOT installed on target computer.  If NightWatchman is installed, the n parameter is not used).

    Oh yeah…don’t forget to add distribution points to the package!!

    Overview of how the script chooses the reboot process

    The script checks for the existence of HKLM\System\CurrentControlSet\Control\SessionManager\PendingFileRenameOperations to determine if the computer needs to be rebooted.

    Return = objReg.GetMultiStringValue(HKEY_LOCAL_MACHINE,_
        strKeyPath,"PendingFileRenameOperations", strValue)
    If (Return = 0) And (Err.Number = 0) Then
        bRebootNeeded = True
    End If

    The script then determines what tool/method to use to reboot the computer.  If NightWatchman is installed, the script will run the following command-line:

    nightwatchman.exe -onceoff -shutdowntime=NOW -shutdownaction=reboot

    …if NightWatchman is NOT installed, the script will use WMI Win32_OperatingSystem:Win32Shutdown to reboot the computer.  Here is the VBscript code which calls the Win32Shutdown method:

    Sub RebootComputer(ByVal intTimeOut, ByVal intFlags)

    'Set objArgs = Wscript.Arguments

    'intTimeOut = objArgs(0) 'Countdown in seconds
    'intFlags = objArgs(1) 'Bitmapped set of flags to shutdown the computer: 0 = Logoff, 4 = Forced Logoff (0+4),
            '1 = Shutdown, 2 = Reboot, 6 = Forced Reboot (2+4), 8 = Power Off, 12 = Forced Power Off (8+4)

    intTimeOutSec = intTimeOut * 1000 'Convert from milliseconds to seconds

    strComputer = "."

    Set objWMIService = GetObject("winmgmts:" _
      & "{impersonationLevel=impersonate,(Shutdown)}!\\" & _
       strComputer & "\root\cimv2")

    Set colOperatingSystems = objWMIService.ExecQuery _
      ("Select * from Win32_OperatingSystem WHERE Primary=True")

    For Each objOperatingSystem in colOperatingSystems
      Wscript.Sleep intTimeOutSec 'Pause for x seconds before rebooting computer
      objOperatingSystem.Win32Shutdown intFlags

    Next

    End Sub

    Create and Assign an advertisement to the collection to reboot the computers

    Note: I want to stress that the advertisement properties below recommends using Always rerun program.  This option is only available under ConfigMgr.  If you are interested in a blog specifically for SMS, post a comment below.


    Advertisement Schedule-tab properties
    Now that the reboot package is created, create an advertisement of it and assign to the collection All Windows Workstation and Professional Systems (Note: More than likely, you will only want this executed against computers running desktop operating systems, so assigning the advertisement to this collection should be fine for you.)  On the Schedule tab for the advertisement properties, set a mandatory assignment with a recurring schedule of your choice (this will vary, depending on how aggressive you want to be.  Since this is my lab, I have it scheduled to run every 2 minutes.  However, in a production environment, the advert run every few hours or maybe once per day should be fine).  Since you are setting a recurring schedule for the advertisement, ConfigMgr will prompt you and recommend setting the Program rerun behavior to Always rerun program (Note: With this, the advertisement will run again even if it has previously run on the target computer).

    Also, make sure Enable Wake On LAN is disabled (e.g. unchecked).  This will prevent ConfigMgr or 1E WakeUp from unnecessarily waking machines.

    Impact of NightWatchman properties: MonitorJobs and PendingJobWindowMins

    As explained, if NightWatchman is installed, the reboot script will use NightWatchman to reboot the computer.  When NightWatchman is initially installed on your computers, the property MonitorJobs is enabled (default) and PendingJobWindowMins is set to 5 minutes (default).  This combination means, if NightWatchman detects any currently running jobs in SMS/ConfigMgr and/or pending jobs in SMS/ConfigMgr within the specified “look-ahead” window (e.g. 5 minutes), the reboot/restart will be deferred.  If no jobs are currently running, or pending within the time specified by PendingJobWindowMins, the reboot/restart will occur.

     Conclusion…

    Rebooting computers is one of those administrative tasks that’s at the top of the list.  As we all have been working with Windows for quite some time now, we know that rebooting is just a “good” thing to do.  Rebooting computers due to pending file rename operations, is a scenario that usually goes undetected in many environments.

    Automated rebooting of computers is always a “hot topic” and usually requires buy-in from management.  While this blog may not show you how to navigate the approval process in your company, it does provide you the tools and instructions to implement this most valuable solution.  <wink>Once you get approval…</wink>

    I hope you enjoyed…

    Troy L. Martin | Senior Consultant | 1E |

    troy.martin@1e.com | www.1e.com

  • Machines awaiting reboot due to “pending file rename operation”

    Introduction

    As we know, many desktop computers do not get rebooted for long periods of time and many laptop users almost never shutdown their computer and just merely “close the lid”.  Because of this, the “pending reboot/file rename” is persisted and usually goes undetected.  Case-in-point:  After implementing this at a customer site, more than half of their computers needed to be rebooted due to a pending file rename…and they never knew it.

    A “pending file rename operation” occurs when an install needs to rename files that are in-use at the time of the install, and is waiting to have the rename completed as part of the next reboot.  Some applications will first check to see if this condition exists before installing it’s app or software (some hotfixes will not install because of this).  This is a common practice amongst software patches and updates, service packs and anti-virus updates just to name a few.

    To make this very (fun) practical and to ease your administrative duties, I’m going to provide instructions to implementing a solution that will “dynamically automate” (aahh…longtime FAVORITE phrase in IT!!!) the rebooting of all computers - running desktop OS’es -, that are awaiting a reboot due to “pending file rename operation”.

    • Create a package to reboot computers
    • Create and Assign an advertisement to the collection to reboot the computers

    Create a package to reboot computers

     

    Package program properties
    Download GracefuLReboot.vbs (by Steve Pruitt)and use it as the source-files for the package.  Then create a package program with the Command-Line property as GracefuLReboot.vbs n (e.g. “n” being a numeric value for the amount of time to surpass before (re)prompting the logged-on user to reboot, should they decline during the previous attempt.  In my screen-capture below, I used “1” to represent prompting the logged-on user every 1 minute.  This is ok since it is just my lab environment.  If you want to prompt users every 60 minutes should they decline the reboot, then make the numeric value 60.  Keep in mind, this parameter only applies when NightWatchman is NOT installed on target computer.  If NightWatchman is installed, the n parameter is not used).

    Overview of how the script chooses the reboot process

    The script first checks to see if NightWatchman is installed.  If NightWatchman is installed, it run the following command-line:

    nightwatchman.exe -onceoff -shutdowntime=NOW -shutdownaction=reboot

    If NightWatchman is NOT installed, then the script will use the WMI Win32Shutdown method to reboot the computer.  Here is the VBscript code which calls the method:

    Sub RebootComputer(ByVal intTimeOut, ByVal intFlags)

    'Set objArgs = Wscript.Arguments

    'intTimeOut = objArgs(0) 'Countdown in seconds
    'intFlags = objArgs(1) 'Bitmapped set of flags to shutdown the computer: 0 = Logoff, 4 = Forced Logoff (0+4),
            '1 = Shutdown, 2 = Reboot, 6 = Forced Reboot (2+4), 8 = Power Off, 12 = Forced Power Off (8+4)

    intTimeOutSec = intTimeOut * 1000 'Convert from milliseconds to seconds

    strComputer = "."

    Set objWMIService = GetObject("winmgmts:" _
      & "{impersonationLevel=impersonate,(Shutdown)}!\\" & _
       strComputer & "\root\cimv2")

    Set colOperatingSystems = objWMIService.ExecQuery _
      ("Select * from Win32_OperatingSystem")

    For Each objOperatingSystem in colOperatingSystems
      Wscript.Sleep intTimeOutSec 'Pause for x seconds before rebooting computer
      objOperatingSystem.Win32Shutdown intFlags
    Next

    End Sub

    Create and Assign an advertisement to the collection to reboot the computers

    Note: I want to stress that the advertisement properties below recommends using Always rerun program.  This option is only available under ConfigMgr.  If you are interested in a blog specifically for SMS, post a comment below.


    Advertisement Schedule-tab properties
    Now that the reboot package is created, create an advertisement of it and assign to the collection All Windows Workstation and Professional Systems (Note: More than likely, you will only want this executed against computers running desktop operating systems, so assigning the advertisement to this collection should be fine for you.)  On the Schedule tab for the advertisement properties, set a mandatory assignment with a recurring schedule of your choice (this will vary, depending on how aggressive you want to be.  Since this is my lab, I have it scheduled to run every 2 minutes.  However, in a production environment, the advert run every few hours or maybe once per day should be fine).  Since you are setting a recurring schedule for the advertisement, ConfigMgr will prompt you and recommend setting the Program rerun behavior to Always rerun program (Note: With this, the advertisement will run again even if it has previously run on the target computer).

    Also, make sure Enable Wake On LAN is disabled (e.g. unchecked).  This will prevent ConfigMgr or 1E WakeUp from unnecessarily waking machines.

    Impact of NightWatchman properties: MonitorJobs and PendingJobWindowMins

    As explained, if NightWatchman is installed, the reboot script will use NightWatchman to reboot the computer.  When NightWatchman is initially installed on your computers, the property MonitorJobs is enabled (default) and PendingJobWindowMins is set to 5 minutes (default).  This combination means, if NightWatchman detects any currently running jobs in SMS/ConfigMgr and/or pending jobs in SMS/ConfigMgr within the specified “look-ahead” window (e.g. 5 minutes), the reboot/restart will be deferred.  If no jobs are currently running, or pending within the time specified by PendingJobWindowMins, the reboot/restart will occur.

     Conclusion…

    Rebooting computers is one of those administrative tasks that’s at the top of the list.  As we all have been working with Windows for quite some time now, we know that rebooting is just a “good” thing to do.  Rebooting computers due to pending file rename operations, is a scenario that usually goes undetected in many environments.

    Automated rebooting of computers is always a “hot topic” and usually requires buy-in from management.  While this blog may not show you how to navigate the approval process in your company, it does provide you the tools and instructions to implement this most valuable solution.  <wink>Once you get approval…</wink>

    I hope you enjoyed…

  • ConfigMgr package programs cannot use task sequence variables!

    When running a normal ConfigMgr package/program as a step in a task sequence, you cannot use variables on the command line. This happens because the execution of the program is actually managed by the execmgr, the clients normal execution manager, which does not know of any of the OSD environment. There are two ways to get around this limitation, use a script to reference the variables or change the step to install the software to a normal "Run Command Line" step, which can use variables and reference the original package.

    So basically, a task sequence cannot call a normal ConfigMgr program and parse it Task Sequence variables, the OSD variables are not understood by the execmgr or they are not available:

    In order to get around it you have to either use a script that runs as admin, referencing the TS object, or use the option to use a "Run Command Line" task that references the packagee source in the Task Sequence as the example below. In this example we feed two variables from the TS environment to the actual installer, and as you can see, its just a standard "Run Command Line" step:

     Hope this saves some time for you guys!

    Andreas Hammarskjöld | System Deployment Practice Lead | 1E Ltd |
    andreash@1e.com | www.1e.com

  • Running a tasks that stops WMI as a part of a ConfigMgr task sequence

    If you want to run a certain application or configuration that stops either WMI or the Agent Host you have to run it as a "Run Command Line" step. All "Install Software" steps is executed by the execmgr by the Agent Host, and when the application stops either WMI or the Agent Host service it will release the newly spawned process causing the TS to return it as a failure. The workaround is to simply use the "Run Command Line" step when using command lines/applications that reset any of these services. This works since the "Run Command Line" steps are executed by the TS engine which is not dependant on either WMI or the Agent Host service.

    The following picture shows a task to install a new ConfigMgr site, a task that resets both WMI and other underlying services, this will work since it is a "Run Command Line" step, if it was a "Install Software" step, it would fail when the ConfigMgr installation would stop the WMI service. The error for this can be seen in the SMSTS.LOG which specifies that the Agent Service is not running. So any task that stops a service that is depending on WMI has to be using a command line step in the task sequence in order to be installed. This type of applications are often anti-virus, VPN, firewalls etc etc.

    Andreas Hammarskjöld | System Deployment Practice Lead | 1E Ltd |
    andreash@1e.com | www.1e.com

  • ConfigMgr task sequence variable for distribution point

    You can use variables that reference the DP path for each package, there is no variable that references the “DP” as there could be many DPs.

    Dependnign on advert settings you can get both SMB and HTTPs locations for the DP in two difference variables. However, you can always get the UNC path by using the following environment variable, given that the package is being referenced in the TS.

    %_SMSTSUK10009F% would resolve a full UNC path for package UK10009F, ending with a backslash, so running a batch file from a TS you can specify the following command line when you have referenced the package:

    cmd.exe /c %_SMSTSUK10009F%SampleBatchFile.cmd

    Hope this helps!
     

    Andreas Hammarskjöld | System Deployment Practice Lead | 1E Ltd |
    andreash@1e.com | www.1e.com

  • Importing and Exporting ConfigMgr Tasks Sequences

    First of all, if you want to programmatically import/export tasks sequences ensure that you are on SP1, that contains the undocumented import functionality. More about that in later posts.

    If you want to import a task sequence, ensure that you have all the ConfigMgr tasks sequence extensions as you did have in the original task sequence. For instance MDT and Nomad Branch adds steps that can be used in task sequences, so if you are importing a task sequence with these steps you need to ensure that MDT is set up and that the Nomad Branch consule bits are installed prior to importing.

    There are also special cases where the password bits hinder an import, so some manual cleansing might be needed before importing.

    Andreas Hammarskjöld | System Deployment Practice Lead | 1E Ltd |
    andreash@1e.com | www.1e.com

  • Running a ConfigMgr Task Sequence command line as a specified user

    When you use the "Run this step as the following account" in ConfigMgr you need to be aware of the fact that the OSD environment does NOT follow to the new user environment. This means that scripts referencing the Microsoft.SMS.TSEnvironment or the BDD/MDT oEnvironment.Item objects will fail to run. So in order to workaround this you will have to parse any variables needed into the actual script using command line arguments. So in the picture below you can see how we workaround feeding the computername variable to a script that runs as domain admin, if the script had referenced the oEnvironment.Item("COMPUTERNAME") it would have failed.

    Andreas Hammarskjöld | System Deployment Practice Lead | 1E Ltd |
    andreash@1e.com | www.1e.com

  • When Working with ConfigMgr OSD Collection variables

    Keep in mind that these values do not apply to the target machine from parent collections if the client is not also a member of the parent collection, and linked collections does not transfer variables either. You can however advertise to linked collections and sub-collections.

    Andreas Hammarskjöld | System Deployment Practice Lead | 1E Ltd |
    andreash@1e.com | www.1e.com

  • Setting DNS Search Order with ConfigMgr

    If you are trying to set the DNS Search order during an OSD task sequence, this will never work if you specify a 127.0.0.1 address. It seems like both WMIC and ConfigMgr fails to use this as a valid address. Please also note that the DNS step has to be configured if you are setting a static IP, it cannot be blank unless you are skipping DNS configuration.

  • Controlling the installation of the ConfigMgr Provider

    The ConfigMgr (Don't you worry, SMS 2003 works exactly the same) Provider is somewhat of an unknown component when it comes to designing hierarchies. For people who haven't got a clue what the provider is; it's the WMI engine responsible to talk to the DB etc (root\sms_site_XXX).

    You can control where the Provider gets installed in the installation sequence when doing a ConfigMgr install, or if you are installing it unattended, use the SDKSERVER=SERVERINUPPERCASE value in your answer file. For Primary sites, the SDKSERVER means where the Provider goes, for the AdminUI, it means what server to point at, makes sense as the Admin console talks to the provider. By default the Provider goes onto the SQL box, and if that is not allowed for some reason, it can be on the ConfigMgr box itself. But did you know that the Provider actually could be on a completely different server?

    So what are the main reasons to have your Provider on anything but the SQL Server (Which is the default)?

    • Installing ConfigMgr SQL DB in a cluster (The provider can't be on the cluster so normally goes onto the ConfigMgr box instead)
    • You have a vast army of chipmunks connecting with their ConfigMgr consoles, over a thousand I would say...
    • You want to create a weird setup that is tricky for ISV's to detect and support
    • You are a bit dim...

    As we see above, there are a couple of instances where the Provider might end up in a few different places...

    Andreas Hammarskjöld | System Deployment Practice Lead | 1E Ltd |
    andreash@1e.com | www.1e.com

  • Installing ConfigMgr SP1 Upgrade and R2 Unattended/Silent

    In order to install/upgrade ConfigMgr the following commands and steps must be used, not rocket science but not documented anywhere either;

    1. Uninstall WAIK 1.0
      • MSIEXEC.EXE /x {31E8F586-4EF7-4500-844D-BA8756474FF1} /qn REBOOT=REALLYSUPPRESS
    2. Reboot Server (Yes, it's a must!)
    3. Run ConfigMgr SP1 PrereqCheck
      • SETUP.EXE /PREREQ /NOUSERINPUT
    4. Install ConfigMgr SP1
      • SETUP.EXE /UPGRADE <FULL_PATH_TO_PREREQ_PATCHES_WITHOUTSPACES>
    5. Install ConfigMgr R2
      • MSIEXEC.EXE /I ConfigMgr2007R2.msi /qn

    If you are building from scratch, its easier to use the slipstreamed SP1 media! :D

    As always, when copying code ensure that quotes and dashes are correct before running commands, " and " are not the same!

    Have fun!

Copyright - www.myITforum.com, Inc. - 2010 All Rights reserved.
Powered by Community Server (Commercial Edition), by Telligent Systems