In this guide, I will how to image workstations with static IPs using a PowerShell form, System Center Configuration Manager, and SQL Server.

Alex Pazik

Alexander specializes in Windows deployments and systems management applications such as System Center Configuration Manager and System Center Operations Manager.

One of the biggest challenges I’ve struggled with while using SCCM is image deployment on computers that use a static IP. If your environment has only a few workstations that use a static IP, typing in and configuring individual network settings variables may not be a great solution, but it is certainly a manageable one. However, if your environment has well over 400 workstations that all use static IPs and can’t use DHCP at any point during or after the imaging process, setting individual variables is not very desirable or efficient.

Step 1 – First, you will need to create a database that contains the name, IP address, subnet mask, and gateway of each workstation in your environment that uses a static IP. The easiest way to do this is to create a comma-delimited CSV file in Microsoft Excel and import it into a database as a table. If you know your keyboard shortcuts and use a solid naming convention, this shouldn’t take too long.

Create Excel spreadsheet

Create Excel spreadsheet

Once you compose your spreadsheet, save it as a comma-delimited CSV file with a friendly name, such as “Workstations.csv,” and exit Excel.

Step 2 – Open the SQL Server Management Studio and connect to your server’s database engine. Create a new database or select an existing one that will hold your imported table. For this guide, I will be creating a new database called “WKS_SCS” and I will assign myself as the database owner. Click OK to create the database.

Create database

Create database

Step 3 – Now we are going to import the table with our workstation information. Right-click on the database you just created and navigate to “Tasks” > “Import Data.”

Import data

Import data

When the SQL Server Import and Export Wizard open, click Next and for the Data Source, choose “Flat File Source.” Next to file name, browse to and select the file that contains the workstation information, which you created earlier; leave all the defaults as is. To verify that the SQL read the CSV correctly, click on the Preview tab to see a preview of your table. Click Next, and for the Destination, choose “SQL Server Native Client 11.0.” Select or enter the server name and database you wish to import the information into and click next. You can either change the name of your table or leave it as is. I am going to change the name of my table to “dbo.NetworkConfig.” Click next to begin importing your table. Once the import completes, close the Import and Export Wizard.

Successful import

Successful import

When you refresh your database in Object Explorer, you should see your new table. Now we need to create an SQL login that has read privileges to that table so we can pull information down for our PowerShell form.

New database

New database

Step 4 – In Object Explorer, navigate to the Logins node and create a new login that has access to the database you created and can read the table you imported. For this guide, I created an account called “db.readonly” and have given it db_datareader and db_denydatawriter membership.

Read only account

Read only account

Once you create the login, you should see a new user under the Logins node, as well as the Users node for the database you are using to hold your table.

Read only account (cont.)

Read only account (cont.)

You may now exit SQL Server Management Studio.

Step 5 – Open Windows PowerShell ISE and copy and paste the following script (the script is longer than 10 lines):

You will need to edit all fields that contain an entry with the suffix “Your.” You can run a search in your script to find all these entries. When you are done, save the script to a Configuration Manager-accessible network location with the name “prestart.ps1.” For this guide, I will save the script to the following location:

Now we are going to create the boot image.

Step 6 – Open the System Center Configuration Manager console. Click on the Software Library tab to expand the Operating Systems node and click on the Boot Images applet. Find and open “Add Boot Image” in the Ribbon above. When the Add Boot Image wizard launches, point the wizard to the location of your boot image. When I create a new boot image, I always create a new folder, give it a logical name (i.e., WinPE 10.0 v4), and copy a vanilla boot.wim generated by the copype command. Click Next and give the boot image a name, version, and description. Click Next once more to start adding the boot image to Configuration Manager. Close the wizard once the boot image is added.

Enter boot image data

Enter boot image data

Step 7 – Right-click on the recently added boot image and select “Properties.” Click on the Drivers tab and add any necessary drivers.

Add drivers

Add drivers

Click on the Customization tab and check the box “Enable prestart command.” Copy and paste the following in the “Command line” box:

Check the box “Include files for the prestart command” and navigate to the folder where you saved your script. Optionally, you can choose a custom wallpaper to use with your boot image. For this guide, I am going to add a custom wallpaper. Check the box “Enable command support (testing only).”

Add customization(s)

Add customization(s)

Click on the Optional Components tab and add the following components:

Windows PowerShell (WinPE-DismCmdlets)
Windows PowerShell (WinPE-StorageWMI)
Microsoft .NET (WinPE-NetFx)
Windows PowerShell (WinPE-PowerShell)

Optional components

Optional components

Click Apply and choose Yes to update the distribution points with the boot image.

Step 8 – Navigate to the Task Sequences applet under the Operating Systems node and either create a new task sequence or select an existing one. For this guide, I am going to select an existing task sequence “(Family WKS) Windows 10 Pro x64.” Add a new “Run Command Line” task sequence step and place it before the step “Partition Disk 0 – BIOS” / “Partition Disk 0 – EUFI” but after the step “Restart in WinPE.”

Add Task Sequence step

Add Task Sequence step

Copy and paste the following in the “Command line” box:

Click Apply and close the task sequence. Right-click on the task sequence and select “Properties.” Make sure the task sequence is using the boot image you just created.

Select Task Sequence boot image

Select Task Sequence boot image

Step 9 – Now we need to create a new task sequence media. Select the task sequence you just edited and open “Create Task Sequence Media” in the Ribbon above. Specify whatever options are required in your environment and create the task sequence media. Do not add any variables or a prestart command. Close the wizard when the media is done being created. We are now ready to begin imaging workstations.

Step 10 – Boot into the task sequence using the media you created in the previous step. On the “Welcome to the Task Sequence Wizard” splash screen, click Next to bring up the Workstation Unattend form. Type the computer name into the textbox labeled “Computer Name.” When SQL runs a query off that name and finds a result, it will automatically populate the other fields in the form. Click Apply to apply these settings to the NIC and generate the “Variables.ps1” script.

Workstation unattended

Workstation unattended

Close the Workstation Unattend form. Select the task sequence you edited earlier and click Next. The wizard will resolve all dependencies and begin executing the task sequence. Shortly after the task sequence begins, you should see the following step:

Apply custom TS variables

Apply custom TS variables

To verify the task sequence variables were applied correctly, press F8 to open a Command Prompt and enter the following commands:

If the variables applied correctly, PowerShell will echo the name of the computer specified in the Workstation Unattend form.

Variables successfully applied

Variables successfully applied

When the workstation finishes imaging, it will have the correct name as well as the correct static network settings.

Are you an IT pro? Apply for membership!

0
Share

Related Posts

3 Comments
  1. MikeC 2 years ago

    Line 77: There is one of those annoying 'curly quotes' in your script in step 5.

    Thank you for sharing your work!

    0

  2. MikeC 2 years ago

    Actually, there are a number of them:

    Line 57:     (“FALSE”)

    Should be:        ("FALSE")

     

    0

    • Michael Pietroforte 2 years ago

      Thanks for the hint! I corrected the script now. I always wonder why curly quotes can't be used in programming languages. I mean, wouldn't it be easier to see where a quote starts and where it ends?

      0

Leave a reply

Your email address will not be published. Required fields are marked *

*

CONTACT US

Please ask IT administration questions in the forum. Any other messages are welcome.

Sending
© 4sysops 2006 - 2019

Log in with your credentials

or    

Forgot your details?

Create Account