Even Easier (and automated) Computer Naming
Following on from my post on Friday about naming machines automatically, I wanted to share another bit of PowerShell which is arguably easier to use and easier to implement. If you are not using MDT it is also a great solution.
If you are using ConfigMgr 2012 R2, then you can use the Run PowerShell Script task sequence step to execute this script, I just call it Set-OSDComputerName.ps1, put it into a package, send it out to your distribution points and then you are done. I love using MDT and I love the way you can automate things like running user exit scripts but this is just easier and quicker to implement. It means I can put it with my standard package of PowerShell scripts that I use in my OS deployment engagements and off I go.
Here is the script.
$MacAddress = (Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter "IpEnabled = true" | Select-Object MacAddress).MacAddress $Escaped = $MacAddress.Replace(":", "") $OSDComputerName = $Escaped.SubString($Escaped.Length - 8,8) $TSEnv = New-Object -COMObject Microsoft.SMS.TSEnvironment $TSEnv.Value("OSDComputerName") = "$OSDComputerName"
What I like about this short script is that I probably have multiple network cards in my device but this will only pick up the one which is IP enabled. It’s easy to run, and quick to setup.