Skip to content

Task sequence problems reading reg keys or env variables

Featured Replies

I am putting together a pretty complex server build process using task sequences. As part of this process, I wrote a VBScript that among other things starts by enumerating the domain that the target machine is a member of.

 

Running the script from the command line works perfectly.

 

Running a Task sequence that first boots to WinPE, installs Windows 2003 x64, joins the domain, reboots, installs software, then runs the script, the script fails to obtain the domain information <null value>.

 

If a run a second task sequence that contains only a 'run command line' step to execute the script, on that same exact machine that was just built using the previous TS, it works perfectly!

 

For the life of me, I cannot figure out why a TS that runs through an entire build process fails, where the one that does nothing but runs the command works. I should point out specifically that it is the last step of the build TS, meaning it is indeed booted back to the installed OS, and not running from PE. In both instances, I do not specific an account to run the command line under, I let it use the SCCM account.

 

I tried two different methods to obtain the current domain, including accessing the %USERDOMAIN% env variable, and a RegRead to HKLM\Software\Microsoft\Windows NT\CurrentVersion\WinLogon\DefaultDomainName

 

I am not using the WMI Win32_ComputerSystem domainname value since it returns the fully qualified domain name, not the friendly one which is what I need.

As long as you are in the Task Sequence you run as a system account (except when you use a Run Command Line step with a Run as account) and then you can't access user variables like %USERDOMAIN%.

As far as I can remember the DefaultDomainName regkey doesn't have to excist at that moment. If does already excist it doesn't have to contain the domainname, it can contain the local machine name to...

 

But why do you want to get the domain name that you already know, because you just added the machine to the domain???

  • Author

As long as you are in the Task Sequence you run as a system account (except when you use a Run Command Line step with a Run as account) and then you can't access user variables like %USERDOMAIN%.

As far as I can remember the DefaultDomainName regkey doesn't have to excist at that moment. If does already excist it doesn't have to contain the domainname, it can contain the local machine name to...

 

I did some playing around, it looks like that reg key doesn't get populated until the first time a user logs onto the machine, which is why it failed to pull data from it. The env variable issue makes sense if I don't use the runas account.

 

But why do you want to get the domain name that you already know, because you just added the machine to the domain???

 

I wanted the install script to be able to be called from a Task Sequence, OR as a standard package, OR even just from the command line for existing systems, and be compatible either way. If I had the script pull the domain from the SMS.TS environment it would work in the TS, but fail installing normally. I suppose I could put a check in to try to pull from the TS environment first, and if it fails (because it is not in a TS) to then attempt to pull from alternate sources.

I wanted the install script to be able to be called from a Task Sequence, OR as a standard package, OR even just from the command line for existing systems, and be compatible either way. If I had the script pull the domain from the SMS.TS environment it would work in the TS, but fail installing normally. I suppose I could put a check in to try to pull from the TS environment first, and if it fails (because it is not in a TS) to then attempt to pull from alternate sources.

 

But what are you trying to achieve by getting the domain as a variable? If you can explain that, maby there is an easier way to achieve your goal...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.