Jump to content


khawkins

OSD Computer = ModelNumber-SerialNumber

Recommended Posts

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

Share this post


Link to post
Share on other sites

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%")#

 

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...


×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.