Powershell
--
Questions
--
Followers
Top Experts
Rename the computer using the serialnumber in BIOS + "-21" Â (example: P00035T-21)
AND
join our domain
It's joining the domain, but not changing the name
(scripting noobie here)
thanks
$serial = Get-WmiObject win32_bios | select -expand serialnumber
$newname = $serial + "-21"
Rename-Computer -NewName $newname -Force
Add-Computer -DomainName "cityhigh.lan" -OUPath "OU=2021;OU=Laptops;DC=cityhigh;DC=lan" -Restart
Zero AI Policy
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
I wouldn't be surprised if you had to reboot before the changed name was relevant as far as "Add-Computer" is concerned.
This, however, assumes that Rename-computer is running without throwing red error messages everywhere. Is that a fair assumption?
And you'll need to use commas instead of semicolons for the OU path.
$serial = Get-WmiObject win32_bios | select -expand serialnumber
$newname = $serial + "-21"
Add-Computer -DomainName "cityhigh.lan" -OUPath 'OU=2021,OU=Laptops,DC=cityhigh,DC=lan' -NewName $newname -Restart






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
Using your script, it tells me the new name is no different from the current name
It seems that $newname is NOT adding the "-21" to the $serial
You can try to rename it to its former name before the reboot:
Rename-Computer -NewName OldName -Force

Get a FREE t-shirt when you ask your first question.
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
I can't test it at the moment, but I'm pretty certain that Microsoft didn't add the -NewName argument to Add-Computer just to deceive you.






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
And be aware that a Windows computer name is limited to 15 characters; if the serial + "21" is longer, the command might just cut off the rest.
$newname = "$(Get-WmiObject win32_bios | select -expand serialnumber)-21"
"This computer is currently named: '$(& hostname.exe)'"
"The new name based on the serial: '$($newname)'"
However, running that along with Add-Computer, didn't work....it added to the domain, but did not change the name
And no red errors either.

Get a FREE t-shirt when you ask your first question.
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
$newname = "$(Get-WmiObject win32_bios | select -expand serialnumber)-21"
Rename-Computer -NewName $newname -Force
Add-Computer -DomainName "cityhigh.lan" -OUPath "OU=2021,OU=Laptops,DC=cityhigh,DC=lan" -Restart
Powershell
--
Questions
--
Followers
Top Experts
Windows PowerShell is a task automation and configuration management framework from Microsoft, consisting of a command-line shell and associated scripting language built on the .NET Framework. PowerShell provides full access to the Component Object Model (COM) and Windows Management Instrumentation (WMI), enabling administrators to perform administrative tasks on both local and remote Windows systems as well as WS-Management and Common Information Model (CIM) enabling management of remote Linux systems and network devices.