Author Posts

October 28, 2016 at 8:29 am

Hi,

I'm looking to create a PS script that renames a Dell workstation(s) in the following format MODELNumber-SERVICETAG (eg. E5570-123ABC1). I have managed to retrieve the service tag using the following command;

Get-WmiObject win32_bios | Select-Object -ExpandProperty SerialNumber

I'm unsure how to retrieve just the model number and then put that information before the service tag. I would also like to seperate this with a hyphen.

I'm a novice with PS and any help will be much appreciated with creating a rename workstation script.

Regards,
Thundercat

October 28, 2016 at 8:42 am

Should work with something like this:

$SerialNo = (Get-CimInstance -ClassName CIM_BIOSElement).SerialNumber
$ModelNo = (Get-CimInstance -ClassName CIM_ComputerSystem).Model.Split(' ').[1]
$NewDellWorkstationName = $ModelNo + '-' + $SerialNo

October 28, 2016 at 9:16 am

Thanks for your reply, I get the following message when I test the script;

PS R:\> $SerialNo = (Get-CimInstance -ClassName CIM_BIOSElement).SerialNumber
$ModelNo = (Get-CimInstance -ClassName CIM_ComputerSystem).Model.Split(' ').[1]
$NewDellWorkstationName = $ModelNo + '-' + $SerialNo
The term 'Get-CimInstance' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:29
+ $SerialNo = (Get-CimInstance <<<< -ClassName CIM_BIOSElement).SerialNumber + CategoryInfo : ObjectNotFound: (Get-CimInstance:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException The term 'Get-CimInstance' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:2 char:28 + $ModelNo = (Get-CimInstance <<<< -ClassName CIM_ComputerSystem).Model.Split(' ').[1] + CategoryInfo : ObjectNotFound: (Get-CimInstance:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException I'm running PS on a Windows 7 workstation. Regards, Thundercat

October 28, 2016 at 9:30 am

So you're using an older version of Powershell. What a pity. 😉 But not a problem either:

$SerialNo = (Get-WMIObject -Class WIN32_BIOS).SerialNumber
$ModelNo = (Get-WMIObject -Class WIN32_ComputerSystem).Model.Split(' ').[1]
$NewDellWorkstationName = $ModelNo + '-' + $SerialNo