1

My coworker and I are developing a set of scripts to use in conjunction with Windows Imager and Configuration Designer (WICD) to provision new PCs with custom software and to strip out a bunch of nasty stuff. We have all the components working independently, we just need to string them together so that they all run at once with little to no user intervention. Here's a breakdown of how it works:

Get to OOBE experience where you select region
Plug in USB drive with provisioning package at the root of the USB drive
Let things run

First script (install) creates working directories, downloads scripts from github repo, skips OOBE turning off everything, creates admin user and password, enables auto logon, uses a run once registry key to run second script.

Second script (cleanup) Waits 30 seconds to let the registry populate
Resets privacy settings, disables auto logon, deletes stored credentials, installs a piece of software, and lastly runs another script which installs more software and strips a bunch of bloatware out of Windows.

Or, at least it's supposed to run that last script. That's the only thing I don't have working. I can tell by the log files and output that it attempts to run the script but all it does is start the transcript and then exits without any output, traceback, or anything to indicate that it's failing except for a PowerShell prompt. Below is a sanitized and redacted version of the cleanup script. Is there something I'm doing wrong to get this other script to run? Is there another way I should be approaching this. Any help is greatly appreciated.

I can also post the install script and the Windows cleanup if you'd like. Line 24 is where I'm hitting a roadblock.

Start-Transcript -Append C:\Support\Logs\PostDeploymentCleanupLog.txt

#Wait for registry to populate
Start-Sleep -s 30

# Reset Privacy settings to default
reg delete HKLM\SOFTWARE\Policies\Microsoft\Windows\OOBE /v DisablePrivacyExperience /f

# Disable autoLogon
REG ADD "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" /v AutoAdminLogon /t REG_SZ /d 0 /f

# Remove stored credentials
REG DELETE "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" /v DefaultPassword /f


# Start SomeSoftware installer in quiet mode
Function Install-SomeSoftware {...} #End Function Install-SomeSoftware


Install-SomeSoftware -Server '<redacted>' -LocationID <redacted> -Token '<redacted>' -Silent -Force -Transcript

# Run WindowsSetup2_0-WIP
# Forked from SomeGuy's GitHub repo
PowerShell.exe -ExecutionPolicy Bypass -File C:\Support\Scripts\WindowsSetup2_0.ps1

#Remove unneeded directories
Remove-Item -Path C:\\Support\\Scripts -Recurse -Verbose
Remove-Item -Path C:\\Support\\Installers -Recurse -Verbose

Stop-Transcript
4
  • Two asides: Generally speaking, there's no good reason to run a *.ps1 script file via a pwoershll.exe child process - just invoke C:\Support\Scripts\WindowsSetup2_0.ps1 directly. While doing so is benign, there is no reason to use escape \ chars. as \\ in PowerShell. Commented Dec 22, 2021 at 1:26
  • I didn't write those parts myself. My coworker did and I'm just trying to get it to work before fixing other issues. I've tried invoking C:\Support\Scripts\WindowsSetup2_0.ps1 directly and it still just starts the transcript (of the second script) and terminates out to a PowerShell prompt. Commented Dec 22, 2021 at 18:08
  • That's why I called my comments asides: They don't solve your problem, but are general pointers to help you improve your code. Commented Dec 22, 2021 at 18:11
  • 1
    I'll take care of it in my housecleaning. By the way, I found an error in my WindowsSetup script which was causing cmd instances to open and not close, hence breaking the script. So I solved it Commented Dec 22, 2021 at 20:38

1 Answer 1

1

I found an error in my WindowsSetup script which was causing cmd instances to open and not close, hence breaking the script.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.