# Deployment: Check AD for computername else generatecomputername with prefix

**URL:** https://forums.powershell.org/t/deployment-check-ad-for-computername-else-generatecomputername-with-prefix/2200
**Category:** PowerShell Help
**Created:** [January 15, 2014, 12:34am UTC](https://forums.powershell.org/t/deployment-check-ad-for-computername-else-generatecomputername-with-prefix/2200 "2014-01-15T00:34:25Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![cem-ozugur](https://avatars.discourse-cdn.com/v4/letter/c/7bcc69/32.png) [@cem-ozugur](https://forums.powershell.org/u/cem-ozugur)
#### Post date: [January 15, 2014, 12:34am UTC](https://forums.powershell.org/t/deployment-check-ad-for-computername-else-generatecomputername-with-prefix/2200/1 "2014-01-15T00:34:25Z")

</div>

Hello, I’m a noob to powershell. I am trying to Check AD for computername if there is none based one the UUID then generatecomputername with prefix direct to AD. But i can’t seem to figure it out.  
I got the following script which i want to keep building on:

`$ComputerModel = (Get-WmiObject -Class Win32_ComputerSystem | Select-Object Model).Model
$SerialNumber = (Get-WmiObject -Class Win32_BIOS | Select-Object SerialNumber).SerialNumber
$UUID = (Get-WmiObject Win32_ComputerSystemProduct | Select-Object -ExpandProperty UUID)UUID`

`
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
}`

---

<div class="post-metadata">

### Author: ![richard-siddaway](https://avatars.discourse-cdn.com/v4/letter/r/d78d45/32.png) [@richard-siddaway](https://forums.powershell.org/u/richard-siddaway)
#### Post date: [January 15, 2014, 2:40am UTC](https://forums.powershell.org/t/deployment-check-ad-for-computername-else-generatecomputername-with-prefix/2200/2 "2014-01-15T02:40:41Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![cem-ozugur](https://avatars.discourse-cdn.com/v4/letter/c/7bcc69/32.png) [@cem-ozugur](https://forums.powershell.org/u/cem-ozugur)
#### Post date: [January 15, 2014, 2:50am UTC](https://forums.powershell.org/t/deployment-check-ad-for-computername-else-generatecomputername-with-prefix/2200/3 "2014-01-15T02:50:49Z")

</div>

Thanks for the reply! That’s another problem i am having. I can’t seem to import the AD module in winpe, do you have any ideas?

---

<div class="post-metadata">

### Author: ![cem-ozugur](https://avatars.discourse-cdn.com/v4/letter/c/7bcc69/32.png) [@cem-ozugur](https://forums.powershell.org/u/cem-ozugur)
#### Post date: [January 15, 2014, 2:51am UTC](https://forums.powershell.org/t/deployment-check-ad-for-computername-else-generatecomputername-with-prefix/2200/4 "2014-01-15T02:51:32Z")

</div>

Thanks for the reply! That’s another problem i am having. I can’t seem to import the AD module in winpe, do you have any ideas?

---

<div class="post-metadata">

### Author: ![richard-siddaway](https://avatars.discourse-cdn.com/v4/letter/r/d78d45/32.png) [@richard-siddaway](https://forums.powershell.org/u/richard-siddaway)
#### Post date: [January 15, 2014, 3:01am UTC](https://forums.powershell.org/t/deployment-check-ad-for-computername-else-generatecomputername-with-prefix/2200/5 "2014-01-15T03:01:59Z")

</div>

I’m not 100% sure but I don’t think you can import extra PowerShell modules into winpe

---

<div class="post-metadata">

### Author: ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)
#### Post date: [May 16, 2024, 8:52pm UTC](https://forums.powershell.org/t/deployment-check-ad-for-computername-else-generatecomputername-with-prefix/2200/6 "2024-05-16T20:52:30Z")

</div>


