Skip to content

OSD Computer = ModelNumber-SerialNumber

Featured Replies

Hi guys,

 

I have read a few articles on this but I am struggling on how to get this to work. We have dell PC's\Laptops and we need to automate the name of a new device build with the format ModelNumber-SerialNumber eg. "E5550-JAJJAJA". I have MDT integrated and I am using the gather step to gather device info. I have set the OSDComputerName value to %MODEL%-%SERIALNUMBER%

 

This isn't working, which I suspect is because the model name is usually "Latitude E5550".

 

Am I going about this the right way? Should I be using gather or is there another option to automate this?

 

Thanks

Kevin

As you say there is a space in the model name and it's probably going over the max character limit, I think it's 15.

 

In customsettings.ini create sections for each model type and use that to create the first part of the computer name.

 

The start of my ini file below to generate a hostname. I've removed some parts but this should get you started. I've seen examples where people use the model type to create a driver profile.

 

[Settings]
Priority=Decode,ByVMType,ByDesktopType,ByLaptopType,Default
Properties=ComputerType,MyCustomProperty

[ByVMType]
SubSection=VM-%IsVM%

[ByLaptopType]
SubSection=Laptop-%IsLaptop%

[ByDesktopType]
SubSection=Desktop-%IsDesktop%

[VM-True]
ComputerType=W0V

[Desktop-True]
ComputerType=W0D

[Laptop-True]
ComputerType=W0L

SkipComputerName=NO
UserExit=CleanMAC.vbs
OSDComputerName=%ComputerType%#CleanMac("%macaddress%")#

 

In my environment we do the same type of naming convention. We use a task sequence to call a powershell script to get the variable to name the computer. the powershell is pretty simple.

 

You can test using the script below and modify it accordingly. The Write-Host is what you will need to change to return the variable to your task sequence. Also however long you want the string/where you want it to start on the return. You can add "Write-Host"s to see what it is bringing back for each variable and modify accordingly. This is one I used for a Lenovo but it should be the same idea.

 

$MyModelNumber = GWMI Win32_ComputerSystem | fl Model | Out-String

$MyModelNumber = $MyModelNumber.Substring(12,4)

$MySerialNumber = GWMI Win32_Bios | fl SerialNumber | Out-String

$MySerialNumber = $MySerialNumber.Substring(19)

$MyComputerName = $MyModelNumber + '-' + $MySerialNumber

Write-host $MyComputerName

  • Author

I'm still not having much luck with this. I have created a package that points to the powershell folder, but with no program.

Here is the script;

************

$ModelNo = (Get-WMIObject -Class WIN32_ComputerSystem).Model.Split(' ')[1]
$SerialNo = (Get-WMIObject -Class WIN32_BIOS).SerialNumber
$WorkstationName = $ModelNo + '-' + $SerialNo
Rename-Computer -NewName $WorkstationName -Restart

**********

I can confirm it works, as I have ran it manually on an OS and it renames and auto restarts.

 

I then add a run command to the TS (just after the Apply OS step) with the command

powershell.exe -file rename.ps1 -executionpolicy -bypass

Which fails.

I also added a run powershell step and select set to bypass, with the command line

rename.ps1

Which also fails.
 

Any ideas?

  • Author

Ok so I got this working after making a lot of work out of it. I hope this helps someone, here are my exact steps;

 

Objective:

Powershell script to rename workstation %MODEL%-%SERIALNUMBER%

 

Here is the PowerShell script

*******

$ModelNo = (Get-WMIObject -Class WIN32_ComputerSystem).Model.Split(' ')[1]

$SerialNo = (Get-WMIObject -Class WIN32_BIOS).SerialNumber

$WorkstationName = $ModelNo + '-' + $SerialNo

# Workstations

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

    $TSEnv.Value("OSDComputerName") = "$WorkstationName"

********

 

Within the task sequence, this step NEEDS to be AFTER the apply OS and before the domain join

Create a package pointing to the .ps1, but do not create a program.

Add a TS step as follows

-Run PowerShell Script

-Package = "package created earlier"

-Script name = "scriptname.ps1"

-PowerShell execution policy = bypass

 

Thanks everyone for the help.

Kevin

  • 1 month later...

Hi Kevin,

I'm in the exact same situation as you, I would like my machines to rename themselves "model-serial", I have imported the script and added to the TS as you mentioned but it fails.

Could you please give me an example of your TS?


 

 

Cheers,

 

Jackson

Edited by JJJackson

  • Author

Hey JJJackson,

 

Have you enabled powershell in the boot image? Also it's important you have it set just after the OS install step.

13 hours ago, khawkins said:

Hey JJJackson,

 

Have you enabled powershell in the boot image? Also it's important you have it set just after the OS install step.

No I haven't, i'm very new to SCCM!
Thanks! That gives me something to try.
I did notice in the log it said something about Powershell not being installed, I thought it was referring to the install image but the boot image makes sense.

 

Cheers,

Jackson

Join the conversation

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

Guest
Reply to this topic...

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.