PowerShell OSD Frontend with Windows Forms

Recently we upgraded to System Center Configuration Manager 2012 SP1 and I am responsible for all of our Operating System Deployment (OSD) pieces. We were using a nice little HTA with ConfigMgr 2007 but with PowerShell 3.0 support in WinPE 4.0 I just couldn’t pass up writing my own frontend!

I present the PowerShell OSD FrontEnd!

Capabilities:

Prompts for authentication to your domain

Displays basic computer information such as Make, Model, NIC, etc

Prompts for computer name, with a few samples listed

Default computer name is WK and the machines serialnumber

For VMWare virtual machines, computer name is VM and the authenticated user

Scans your site server for existing device records

Utility to format disk

Utility to delete ConfigMgr records

Utility to specify source computer for data migration

Usage:

When you boot into WinPE, you first get prompted to authenticate, note that you do not need to type your domain suffix

Once you are on the main screen you can see the basic information about the machine you are booted into

You may specify the computername you want the machine to have, and there are a few samples that you are welcome to modify as needed

The samples have a prefix and the serial number

The username that you have authenticated as is listed as the Imaged By: user

The information on the right shows any devices for the machine you are booted into on the specified ConfigMgr site server. The script searches for the following:

Computername

MAC address

SMBIOSGUID/UUID

Delete ConfigMgr Record

This is primarily intended for task sequences deployed to Unknown Devices

Format Disk Utility

Currently using DISKPART

DISKPART

select disk x, where x is the drive you choose from the dropdown

clean

create partition primary

assign letter=c

format fs=ntfs quick

active

Data Migration

Currently under construction

Specifies a computer name to migrate data and/or applications from

Customizing for your organization

There are a handful of things you need to do use this script in your organization, I have stripped out all environment specific settings so you will need to edit the following:

Create or edit the existing OSDLogo.png in the root of the script directory

322×59 pixels recommended

Edit specific lines in frontend.ps1

Line 18 – Title

Line 19 – Icon (optional)

Line 42 – Add your domain (does not need to be the FQDN)

Line 71 – Logo image

Line 129 – Sample computername

Line 136 – Sample computername

Line 143 – Sample computername

Line 150 – Sample computername

Line 353 – Add your ConfigMgr site server

Line 354 – Add your ConfigMgr site code

Line 369 – AD account to query site server via WMI, DOMAIN\username

Line 370 – AD account password

Boot image requirements

I am using this frontend as a pre-start command on all my boot images, I need this capability for the authentication before the task sequence wizard is displayed and it also acts as a nice front end for our operational teams for an almost zero-touch experience.

Your source location can actually be a network share, it does not have to be a ConfigMgr package or application, which provides some nice flexibility. Just point to the same directory as frontend.ps1.

Task Sequence requirements

In order to utilize the computername, username, and data migration functionality you need add just a few steps into your task sequence.

The script stores all variables in text files in its own root, on a WinPE 4.0 boot disc this is the following location:

x:\sms\pkg\sms10000

The text files in that location are below:

computername.txt – Computername specified by user

username.txt – User authenticated to the frontend

sourcecomputer.txt – Computer specified in the Data Migration utility

In order to translate these text files into task sequence variables I was never able to get the Run Command Line step to work properly so I created a package with different powershell scripts for each variable.

The content of each is below:

1

2

3

4

$user=get-contentx:\sms\pkg\sms10000\username.txt

$tsenv=New-Object-COMObjectMicrosoft.SMS.TSEnvironment

$tsenv.Value("ImagedByUser")=$user

$tsenv.Value("ImagedByUser")

1

2

3

4

$compname=get-contentx:\sms\pkg\sms10000\computername.txt

$tsenv=New-Object-COMObject Microsoft.SMS.TSEnvironment

$tsenv.Value("OSDComputerName")=$compname

$tsenv.Value("OSDComputerName")

1

2

3

4

$sourcecomp=get-contentx:\sms\pkg\sms10000\sourcecomputer.txt

$tsenv=New-Object-COMObject Microsoft.SMS.TSEnvironment

$tsenv.Value("SourceComputer")=$sourcecomp

$tsenv.Value("SourceComputer")

Finally I have a step to do some branding in the registry using the above variables! I use a simply Run Command Line:

$computer=Get-WMIObject-ComputerName$siteserver-Namespace"root\sms\site_$siteCode"-Query"select * from sms_r_system where name = '$typedname' or macaddresses like '$macaddress' or smbiosguid = '$uuid'"-Credential$sccmcred

$sccmconfirm=[System.Windows.Forms.MessageBox]::Show("Are you sure you want to delete all ConfigMgr records with the following info?"+"`n`n"+"WKID: "+$typedname+"`n"+"MAC: "+$macaddress+"`n"+"UUID: "+$uuid,"Confirm Delete!",4,"Exclamation")

Thanks Jason, I honestly have never looked at any open source sites and this is truly my first online publication. If it ever ends up at Github, Sourceforge, or the like I will definitely let you know.

Very Nice! Trying it out right now.
I noticed that you didn’t mention that you need to add Powershell as an optional component to the boot images where you want to use this frontend as a prestart command.
I would like to add a field to enter a location and desired language; so i can use this in the OSD TS to select the proper language. How could i do that? Add another “New-Object System.Windows.Forms.Label” ?

Thanks Rik. On my next round of updates I will add the explicit requirements needed to run everything.

To add another option you nailed it. Another Label and TextBox. Also note the ClickButton at the bottom of the script, this is where it takes the input and stores it in a .txt file to be imported as a TS variable in your task sequence. Good luck!

I just wanted to give a thanks for sharing. Working like a champ with some minor tweaking and tuning. I was able to implement some actions in our environment that I have been trying to figure out a good way of doing.

Could you run it from inside the task sequence as a cmd line? I have two different TS one for workstation and one for servers. If I add it to the boot image both will get it when I might want different menus for each. thanks

I got it to work. I am using a .net frontend and had to use the serviceui.exe to launch it from the TS. If I just ran the .ext menu from run cmd line it would launch cause I could see the process in taskmgr but it wasn’t displaying the menu.

Looks great and finally I found something on which I was working from a long time.
Actually I am a beginner as OSD point of view, so I have many queries.
First I want to know how to implement it inside the task sequence(Not for WINPE)?
Second alternative of PowerShell means DOS commands ?
Please provide if you have any detailed document regarding the frontends, how they work in TS.

Ratsour, the FrontEnd can be ran inside the task sequence but there are a few issues running inside the OS. I have not fully tested all functionality in the OS, so use at your own risk.

Most techs will use VBScript instead of DOS/Batch commands, but PowerShell is the scripting language to use. Its the most efficient and powerful to boot.

FrontEnds are really about providing your own input and manually gathering the data you need in the task sequence. You don’t always need one, and you don’t always need all the functionality that others have written. You need to evaluate what your own needs are and go from there.

IS there anyway to change this script to make it where it will do the AD authentication and if it is correct then run a bat file and if not exit?? Don’t really need all the other stuff but really new to power shell scripting.
Thanks
Chad

StandAlone media support is added in v3.0! Been working on it for the past couple months, so it’s coming soon! Just a FYI, any packages you put in your task sequences are references locally in StandAlone media. Are you looking more for a repository where a tech could choose what apps he wants to install?