You can simplify your WMI calls
$ComputerModel = Get-WmiObject -Class Win32_ComputerSystem | Select-Object -ExpandProperty Model
$SerialNumber = Get-WmiObject -Class Win32_BIOS | Select-Object -ExpandProperty SerialNumber
$UUID = Get-WmiObject Win32_ComputerSystemProduct | Select-Object -ExpandProperty UUID
Not sure what you are trying to achieve after that as Microsoft.SMS.TSEnvironment is for working with Configuration Manager Task Sequences not AD
In any event the code you are using has some potential issues and I think it should look like this
# Workstations
if (($ComputerModel -match "Precision") -or ($ComputerModel -match "Optiplex"))
{
$OSDComputerName = $SerialNumber + "-" + "WS"
$TSEnv = New-Object -COMObject Microsoft.SMS.TSEnvironment
$TSEnv.Value("OSDComputerName") = $OSDComputerName
}
# Laptops
if ($ComputerModel -match "HP Compaq nc6320")
{
$OSDComputerName = $SerialNumber + "-" + "LAP"
$TSEnv = New-Object -COMObject Microsoft.SMS.TSEnvironment
$TSEnv.Value("OSDComputerName") = $OSDComputerName
}
You could use a switch statement instead or an if-else but lets leave that until we’ve sorted your problem with AD
Can you show the code where you are accessing AD?