Thursday, June 13, 2013

Building a Hyper-v VHost without buying any software $FREE$

Goal: Free core server managed by a GUI environment without Microsoft Hyper-v Manager Software needed and all free (aka no $) and a replacement for vmconnect.

Download it at

Here is how to build a vhost and install the software you downloaded

Broad listing of setups steps:
Build your hardware, enable Virtualization in the BIOS
Download the Free hyper-v server file named "HyperV_Server_2012_FREE.ISO"
Burn your ISO to a DVD
Boot to the DVD
Follow the prompts (not many very basic, do google search if have a question)
Choose the language and such then click “Next”:
Click “Install Now”
Next we need to choose which type of Server 2012 installation you want:
There is Core = Free, Standard GUI = paid, Core Standard = No GUI (paid) can be converted to GUI and Standard GUI = Paid
Now we need to agree to the Licensing terms, check the box for “I Accept…” and click “Next”:
Now depending on whether this is an upgrade or fresh install, choose the correct option for you.
For a new install, select “Custom: Install Windows only (advanced)":
If you want to partition the drive click on “Drive Options (advanced)" otherwise click “Next”:
You should now be at the screen where the installation takes place. This takes some time.
Once the server has booted up you will need to provide the default Adminstrator account with a proper password. Click “OK” enter a password twice and then proceed:

Then you will be greeted by SConfig (PS if you accidentally close the SConfig box you can type Sconfig in the DOS prompt and it should load, if not then type logoff in the DOS prompt and you will need to log in again but SConfig will be there for you.)

Choose Option 4 to Configure Remote Management:
a. Enter Selection: 1 to Enable Remote Management
b. Enter Selection: 3 to Allow Remote Machines to Ping server.
Click Yes.

Enter Selection: 4 to Return to Main Menu.
Choose Option 7 to configure Remote Desktop Settings.
a. Type E for (E)nable and press Enter.
b. Enter Selection: 2 to allow any version of Remote Desktop to connect.
You will be returned to the Main Menu.

Choose Option 9 to open the Date and Time GUI.
a. Configure the date and time as you would Server 2008 R2
You will be returned to the Main Menu.

Choose Option 8 to configure Network Settings.
a. It will only list the NICs that are connected to a network.
b. Select the Index# for the adapter you want to configure:
c. You will be shown Current Settings.
Select Option 1 to enter IP Address.
a. Enter S for (S)tatic IP address and press Enter.
b. Enter the new IP Address and press Enter.
c. Press Enter again to accept the default Subnet of /24.
d. Enter the new Static Gateway IP and press Enter.
You will be returned to the Network Adapter Settings Menu.

Select Option 2 to enter DNS IP Addresses.
a. Set the Preferred DNS server IP and press Enter.
 You will get a confirmation Popup. Press OK to continue.
b. Set the Alternate DNS server IP and press Enter.
 You will get a confirmation Popup. Press OK to continue..
You will be returned to the Network Adapter Settings Menu.
c. Select Option 4 to Return to the Main Menu.

In the black CMD/DOS window that is opened by default, type the following in to configure some standard settings: (these are ones I use and recommend) PS no need to install .Net 4.0 as it is already part of the base install.

:Disable TCPChimney
netsh int tcp set global chimney=disabled
:Disable Firewall
netsh advfirewall set allprofiles state off
NOTE: This will allow to RDP and map drives as the firewall is on by default and will prevent you from doing anything remotely until you either turn it off or put in exceptions. I opt to turn it off because I have hardware firewalls.

:Install SNMP-Services (only neeed if you plan on monitoring your VHOST with some monitoring software)
powershell.exe -command "Add-WindowsFeature SNMP-Service"

Choose Option 2 to configure Server Hostname
a. Enter the VHOST hostname and press Enter.
b. You will be prompted to Reboot the server. Click Yes.

ADD THE VHOST TO THE DOMAIN… Not really Needed, but I will show you how.
1. Form the console use the SConfig window.
2. Select Option 1 to Join the VHOST to a Domain.
a. Press D for (D)omain
b. Type the Full Domain and press Enter.
c. Type the Domain Administrator User Name and press Enter.
d. Type the Domain Administrator Password and press Enter.
i. You will be prompted if you want to change the hostname. Click No.
ii. You will be prompted to Restart the machine. Click Yes.

Unzip on your PC then RDP to your VHOST and copy the files to C:\
You can use a thumb drive or create an ISO if you like just get the files to C:\pshvm30

You will have file structure like this

************* you must do it this way or it will not work properly ***********************
at the DOS prompt you get when you login into core server 2012
cd pshvm30
install_snmp.bat (only do this one if you will monitor your server with an SNMP enabled monitoring device)
cd a43

Contents of set.bat
Disables the tcp global chimney
netsh int tcp set global chimney=disabled

Contents of install_snmp.bat
powershell.exe -command "Add-WindowsFeature SNMP-Service"
Install the sNMP Service - Mainly used for monitoring etc.

now close the dos prompt that opens when you login and close the sconfig window as well

Browse with the A43 file manager and go to C:\pshvm30\runme.bat and double click it to set these setting and install needed runtime etc.

contents of runme.bat
Turns off the windows firewall
netsh advfirewall set allprofiles state off
Imports needed registry settings
regedit.exe /s C:\pshvm30\autostart.reg
Allows you to run powershell scripts
powershell.exe Set-ExecutionPolicy unrestricted -force
Stops powershell from asking if you really want to run my scripts
powershell.exe dir c:\pshvm30 -Recurse | Unblock-File
Is required for freeRDp to work so you can connect from the server console to a VM

to launch PSHVM30 use the shortcut in the A43 file manager or C:\pshvm30\pshvm30.bat

DISCLAIMER: and James Stephan are not responible for any damage caused to your environment use at your own risk.

* You will need to copy your OS ISO file into the folder C:\iso.

** If you know for a fact that your VM has an IP but when you connect via FreeRDP it stops at the crtl+alt+del screen, you can use the following work arounds below or you just need to install the Microsoft Integration Tools onto your VM so that the powershell script can see the IP it needs to attach too. If you wish to run just wfreerdp.exe you will need to open a DOS prompt, change directory to C:\software and type wfreerdp enter. Wfreerdp.exe does not load a GUI interface like mstsc.exe does you have to tell it via command line what IP you want to connect too.

If your VM's are setup properly you will not need these next steps but they are good to know.

Monday, June 3, 2013

POWERSHELL: Managing a VM's NIC's ..Changing vSwitch, adding a NIC and attaching to a the new vSwitch.

This has now been added to a free powershell hyper-v manager project.

Changing a vSwitch
So we have a VM named Test1 which is plugged into the vSwitch "Prod Network" and we want to move it to the "TEST Network"
In powershell type
get-vmnetworkadapter -vmname "Test1" | connect-vmnetworkadapter -switchname "TEST Network"

you can run this to see your VM's and vswitches thay are attached to. NOTE: if a VM Name is listed multiple times it has more than one NIC.
get-vmnetworkadapter * | Select vmname,switchname,ipaddresses | sort "VMName" | format-table -autosize  

Adding a new NIC and adding that new NIC to a vSwitch.
I am assuming you have NIC(1) plugged into the "PROD NETWORK" vSwitch and in this case we are adding a new NIC(2) assigned to the "BACKUP Network" vSwitch.
You need to log onto the VM and rename the Current NIC(1) to "PROD NIC1". Once it is renamed you need to shutdown and power off the VM.
Now we are ready to add a new NIC(2) and attached it to the vSwitch "BACKUP Network"
In powershell type:
Add-VMNetworkAdapter –VMName "Test1" –Name “Backup NIC2” -SwitchName "BACKUP Network" 
Now you can start the VM: Start-VM "Test1"
Once it is booted you need to RDP to the Server and rename the new "Network Adapter" to “Backup NIC2”
Now you see both NIC's renamed

Now you need to click somewhere in the white area under your NIC's and press the ALT key, you will see a Toolbar appear, Click Advanced/Advanced Settings.

Now change the network order as desired, in this case "PROD Network" needs to come first. Click OK to save your changes.

Export and Import a with Powershell

This has now been added to a free powershell hyper-v manager project.

To Export
Create C:\export ( it creates the server name folder for you)
in powershell type  export-vm –Name Test1 –Path C:\export\test1 be patient this may take a while if your VHDx file is fixed and rather large.

Now you can browse to C:\export\test1 and you will see your exported VM structure.

To Import exactly as it was exported on the vhost with the same VMID
The original VM has to be deleted or this process needs to happen on a new VHOST.
This will import your server just as it was exported, this a not a copy of the original exported VM  is the THE ORIGINAL VM and will not import until you remove the old VM that was exported.

create folder under C:\virtualservers\"NEW NAME" in this case IMPORTVM
in powershell type
Import-VM -Path 'c:\export\test1\test1\Virtual Machines\EA6DD389-27A5-4929-8264-BD1B01D06B3C.XML' -VhdDestinationPath "c:\virtualservers\test1" -VirtualMachinePath "c:\virtualservers\test1" -SnapshotFilePath "c:\virtualservers\test1" -SmartPagingFilePath "c:\virtualservers\test1" -copy

To Import as a copy with a new VMID
The original VM DOES NOT have to be deleted or this process can to happen on a new vhost
This will import your server just as it was exported, this a copy of the original exported VM  the name will remain the sames as it was exported but the VMID will change. Thus if you import back onto the original VHOST you will havbe two servers named TEST1. You do weell to rename the new TEST1 ASAP. name Rename -VM TEST1 -NewName TEST3

create folder under C:\virtualservers\"NEW NAME" in this case IMPORTVM
in powershell type
Import-VM -Path 'c:\export\test1\test1\Virtual Machines\EA6DD389-27A5-4929-8264-BD1B01D06B3C.XML' -VhdDestinationPath "c:\virtualservers\test1" -VirtualMachinePath "c:\virtualservers\test1" -SnapshotFilePath "c:\virtualservers\test1" -SmartPagingFilePath "c:\virtualservers\test1" -copy -generatenewid

NOTE: you may want to run sysprep on the new copy of the server.

VMconnect.exe replacement using a Powershell script and freeRDP's wfreerdp.exe

This is an official codeplex project at
This has now been added to a free powershell hyper-v manager project.

Connect/Access your VM while OS being installed or if you need to add and IP address

read all about it and download it from there but here is a work around if you find yourself faced with needing to send a crtl+alt+del to a VM via the freeRDp interface.

So far there is no crtl+alt+del button so you have two work arounds. The first one assumes you are RDP'ed into the VHOST so you can press crt+alt+end, then you can  press esc to get out this screen:

Now minimize, then maximize your VHOST RDP session so you can now type in the password field. Yeah I found that one by accident.

Or once you get the RDP screen to open you can use this button

then choose these options, click Apply and OK.

Now you will see this on screen keyboard, click the Ctrl, click the Alt, click and hold the Del
if you did it right you will see you can now type the Administrator PWD.

I find it easiest to use the  ease of access button again, uncheck the three boxes, apply and save and then close the onscreen keyboard and type the Administator password with my normal keyboard.