Hey Scripting Guy! I am working on a script for our district to automatically name computers based on serial numbers. We have a CSV database that pairs each computer to a name via its serial number;
Name,Serial Number
HS-LAB-01,xxxyyyzzz
HS-LAB-02,aaabbbccc
etc etc...
I'm using this in conjunction with sysprep for imaging. This way a newly imaged computer will automatically be named, joined to the domain, and placed in the correct OU. The problem is that I cannot get it to compare information from the csv file (the serial
number) to the query result from Get-WMIObject then compare that with a matching computer name. Here's what I have:
$serialnum = (Get-WmiObject win32_BIOS|select SerialNumber)
To parse the SN of the machine. This works.
$newname = (Import-CSV '\\server\share\csvdatabase.csv' | Where-Object 'Serial' -eq $serialnum | Select 'Name')
Rename-Computer -Newname $newname -DomainCredential $username
^ This doesn't work
*($username omitted)
I can enter $serialnum into PS and it will return the machine SN just fine, which means it works. However, I just draw a blank for $newname every time. Thoughts?