Hyper-V & PowerShell – Getting The Host On The Network

Note: I’d normally configure TCP-IP at this point but the cmdlets that I seem to need to use either are not working correctly or are very confusing – that’s pre-beta software for you!  I’ll try to return to that topic at a later point if I find a solution.

When you install Windows without some clever imaging solution, the machine comes up with some random (not completely) computer name.  You can PowerShell this if you want:

Rename-Computer MyNewComputerName –restart

In a previous blog post I mentioned that POSH (PowerShell) is great for scripting.  You can put a whole load of these commands in a single PS1 file and run it.  This cmdlet is an example of where you’d need user input.  In that case, the following embeds the prompt for a new computer name inside of the Rename-Computer cmdlet.  When you run this, the embedded Read-Host cmdlet is run and provides the user input to the Rename-Computer cmdlet.

Rename-Computer (Read-Host “Enter a new computer name”) –restart

Once that reboot is done, you can join a domain.  The following cmdlet does just that.  It will fire up a traditional Windows prompt for a user name and password to do the domain join.

Add-Computer –DomainName “demo.internal” –Restart

Want some help and examples beyond what you can get from Get-Help?  Try this:

Get-Help Add-Computer –Online

That should fire up your web browser and bring you to an official MSFT web page for the cmdlet in question.  A nice example you’ll find for Add-Computer is that you can use the –OUPath flag to specify a location to place the new computer object in your domain.  I tend to have a special OU for Hyper-V hosts so that’s where I’d place the computer object.  So instead of using the default computer object creation location (and probably forgetting to move the object to the correct one before the reboot), I can save some human effort by running:

Add-Computer –DomainName “demo.internal” –OUPath “OU=Hyper-V, OU=Servers, OU=Company, DC=demo, DC=com” –Restart

And that’s your host named and in the domain, all ready to manage with SCVMM.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.