Jump to content


  • 0
mikejc

Task sequence problems reading reg keys or env variables

Question

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.

Share this post


Link to post
Share on other sites

3 answers to this question

Recommended Posts

  • 0

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???

Share this post


Link to post
Share on other sites

  • 0

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.

Share this post


Link to post
Share on other sites

  • 0

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...

Share this post


Link to post
Share on other sites

Join the conversation

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

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...


×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.