Encountered issues when setting up Windows Contextualization

So I’ve been working on getting some windows images sysprepped and ready to go. And I’ve hit a few bugs in the windows contextualization scripts. I want to make sure these are considered bugs. My setup is as follows.

First windows Image I’m trying to do this on is windows 7 professional a bit old. but the easiest? to work with. I have all 3 scripts in the D:\ Context drive. SetupComplete.cmd startup.vbs and context.ps1.

When I run SetupComplete.cmd it launches startup.vbs but it wasn’t calling powershell and going on to the unattended cleanup. in Debugging startup.vbs I found what it was doing.

Wscript.echo driveLetter
Wscript.echo Len(driveLetter)
If Not Len(driveLetter) Then
  driveLetter = "C:"
End If
Wscript.echo driveLetter

The 3 echo statements output D:, 2, and C:

So at least on Windows 7 the If Not Len() check is true when the Len() == 2
From here it does nothing because it’s trying to find my context.ps1 on C when it’s on D.

The second issue I’m hitting at least in Win7 is in the addLocalUser section of context.ps1. The line:

if(!([ADSI[::Exists("WinNT://$computerName/$username))) {

causes the script to error out if $username is not set. I’m not planning on having contextualization add any local user accounts so I had to enclose most of the function inside an check that makes sure that $username and $password have values assigned.

$username = $context["USERNAME"]
$password = $context["PASSWORD"]
if( $username -And $password) {

So it seems like pretty easy fixes but I wanted to garner some opinions instead of just creating issues on github when i’m not sure if anyone is using the issue tracking on the project for this.

My next issue is that I want to have an additional-contextualization that can join the computer to a domain but I need to reboot after renameComputer before I can run my joinDomain function. I’ve been working on a work-around but it seems like a reasonable option to have in the default contextualization. the ability to reboot and resume contextualization without a hack.

Did you ever figure a way to auto join domain in contextualization? I am about to try this with a windows 10 image.

yes I use this function but it requires sticking the credentials for a user who can auth the domain join in the template context variables. in our case it’s for a test/dev domain and the users are for tests not real users so we are ok with that.

function joinDomain($context) {
    # Join Domain
    $domain = $context["DOMAIN"]
    $joinuser = $context["JOINUSER"]
    $joinpass = $context["JOINPASS"]
    if ($domain -And $joinuser -And $joinpass) {
        if ((gwmi win32_computersystem).partofdomain -eq $false) {
            logIt("joinDomain: $domain")
            $secpass = ConvertTo-SecureString -String "$joinpass" -AsPlainText -Force
            $credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList "$joinuser", $secpass
            Add-Computer -DomainName $domain -Credential $credential
            restartComputer("Joining Domain")

This is perfect since i already have a add to domain user in my setup. Thanks a lot!!!