Author Posts

March 19, 2014 at 10:33 am

I'm newbie in powershell and I'm trying to write script to rename computer in our Active Directory.

So My question is:

Is there a way to rename all computers under OU in Active Directory?

If yes can anyone give me a hint?

Thanks in Advanced

March 19, 2014 at 10:36 am

Well, the trick here is that you have to contact each computer and ask it to rename itself. It then updates its account in AD. There's no way to just make the change in AD.

The Rename-Computer command can do it. Exactly how you use it depends. What kind of connectivity do you have to the computers? How will you come up with their new names?

This can be a big deal, too. I don't know anything about your environment, but there may be other dependencies on computers' names. You could potentially affect user profiles, potentially affect certain permissions – there are things that could go wrong. I'm not going to be able to solve all of that for you, I just want to make sure you're aware that this isn't a 100% safe operation in some environments.

March 19, 2014 at 10:46 am

Thank you very much for your answer.

Yes it's big deal specially there is no documentation for old naming convention. But I'm planing to rename computers based on their IP address in each VLAN.

Here is part of the idea

VLAN 1 = 10.10.10.X first machine ip address 10.10.10.1 computer name should be A1000001 and so on.

And I guess I have to use start up script, Am I right?

Again Thank you

March 19, 2014 at 10:53 am

You don't necessarily have to use a startup script, although that might be the easiest way to ensure that each computer actually does the change. You'll have to get the current computer name ($env:computername) and exit the script if the computer name is already the way you want. If not, you can use Rename-Computer. Note that Rename-Computer is, I believe, in PowerShell v3 and later. You'd have to use something different (like NETDOM) if your computers have an older version of PowerShell.