Updated Move-VMStorage2 function for Hyper-V PowerShell

I have been updating my function that extends the Hyper-V PowerShell module cmdlet Move-VMStorage. A while ago I made a blog post about that I think that the folders on the source directory should be removed when doing a Live Storage Migration or you will get a mess with empty VM folders after a while and that can cause some confusion for the admins.

The updates in this script function are the following:

  • I will not delete folders if they do not reside within a folder with the VM´s name (In the earlier version I just deleted and that recursive with no questions asked which could have some consequences )
  • And if the folder was the default or named with another name you will get an output that tells you to clean manually
  • If you do not give the VM´s Name in the -Path parameter I will add that for you to get a nice and tidy folder structure

Here is a screendump on the updated function in action


And here you can see what happens if I move from a folder that is not named after the VM´s name


And here is a screendump of the folders that are left in the c:\vms that you need to manually delete and you might want to check that not another vm is residing inside these folders before removing them 😛

       An updated Move-VMStorage function
       To also remove the folder where the VM was residing this function also deletes the folder after moving the VM
       This function also helps you in creating a folder in the path if forgotten
       Move-VMStorage2 -VMName test -ComputerName HV02 -Path \\SMB-srv01\VMs\test
    Author: Niklas Akerlund 20130226
    Version: 0.2
    function Move-VMStorage2
            # A name of a VM
            # The name of the Hyper-V host
            $ComputerName = "localhost",
            # The path where the VM is going to be relocated to.
            [string] $Path
            # Lets move and tidy the source folder
            $VM = Get-VM $VMName -ComputerName $ComputerName
            # For some reason the path does not get refreshed when moving one VM several times in the same console that is why i do a select *
            $VMOldPath = Get-VM $VMName -ComputerName $ComputerName | select * -ExpandProperty Path 
            if ($Path -notmatch $VM.VMName){
                $Path = $Path + "\" + $VM.VMName
                Move-VMStorage -VM $VM -DestinationStoragePath $Path
                Move-VMStorage -VM $VM -DestinationStoragePath $Path
            if (($VMOldPath.StartsWith("\\")) -and $VMOldPath -match $VM.VMName) {
               Remove-Item -Path $VMOldPath -Recurse -Force
            }elseif ($VMOldPath -match $VM.VMName){
                Invoke-Command -ComputerName $VM.ComputerName -ScriptBlock {Remove-Item -Path $Using:VMOldPath -Recurse -Force}
                Write-Host "The VM :" $VM.VMName " was in the following path " $VMOldPath " Clean it manually!"

Windows 8 Client Hyper-V and exchanging files with PowerShell

Ben the Virtual PC Guy did a blog post a while ago where he showed how to get files out of a running machine, and I made a follow up where using a non Hyper-V host to get the files.

Today I read on a forum that they where discussing how to get a folder and the files from a virtual machine running on Windows 8 client Hyper-V by enabling and fiddeling with the network. In some cases you do not want to enable networking on that guest to the Win8 host and then you can use the way that Ben showed.

Or you can use an VHD that you first connect to the Win8 host and then copy the files and when you are done you can disconnect it from the host machine and connect it to the virtual machine, with this approach instead of the snapshot you can also add files from the host to the virtual machine and the other way around.

So With PowerShell I first create an VHD and mount it to the Host, create a partition and format it and then I copy the data I want to transfer and then also mount it to the VM.

Screen Shot 2013-02-24 at 20.59.13
New-VHD -Path c:\temp\MobileData.vhdx -Dynamic -SizeBytes 10GB | Select-Object Path | Mount-VHD
Get-Disk | where PartitionStyle -eq "RAW" | Initialize-Disk -PartitionStyle MBR -PassThru | New-Partition -UseMaximumSize -AssignDriveLetter -MbrType IFS | Format-Volume -Confirm:$false | Select-Object DriveLetter | ft -AutoSize
Copy-Item C:\ToVM -Destination E:\ -Recurse
Dismount-VHD C:\temp\MobileData.vhdx
Add-VMHardDiskDrive -VMName VMTest -Path C:\temp\MobileData.vhdx -ControllerType SCSI -ControllerNumber 0 -ControllerLocation 0

As you might know, why I use the SCSI controller is to be able to hot-add the virtual hard disk to the VM while it is running and not having to shut it down 🙂

The first time in the VM I have to do some massage on the disk before it appears but the next time the VM´s OS recoginize it and it can be used directly.

Screen Shot 2013-02-24 at 22.42.42
Get-Disk | where OperationalStatus -eq "Offline" | Set-Disk -IsReadOnly $false
Get-Disk | where OperationalStatus -eq "Offline" | Set-Disk -IsOffline $false
New-Item -Path E:\ToVM\ToHost -Type directory

And as you can see in the screendump above of the virtual machines folder with the files and also you can see that I can add data inside the VM to my virtual disk. If I would just use the Set-Disk -IsOffline $false I would get a volume that was write protected and here I wanted to add files and folders from the virtual machine also.

And when I am done moving files I can easily disconnect the disk from the VM from the host by using the following PowerShell cmdlet

Screen Shot 2013-02-24 at 22.06.39
Remove-VMHardDiskDrive -VMName VMTest -ControllerType SCSI -ControllerNumber 0 -ControllerLocation 0

This move folder and files way also works on the Windows 2012 Hyper-V!

Looking at the features in the Virtual PC compared to the client Hyper-V there are at lest two features I miss in the later,

  • Easily copying files between virtual machine and host
  • An network that can share the hosts without any extra manual configuration with the bridging creating a NAT solution out of the box.

Well you can´t get everything you wish for and some things you can create workarounds for 🙂

SC Orchestrator 2012 Sp1 and VMware vSphere 5.1

I have been exploring the System Center Orchestrator Integration Pack for vSphere and this is some good stuff! I have several customers that have bought Windows Datacenter Licenses with the System Center bundle and that is quite beneficial from a economical perspective! This means that they can use the System Center all parts with all VM´s and hosts. Several customers also use VMware vSphere as their virtualization platform and they can use System Center Orchestrator to build automation without any extra license cost.

In the System Center family there is only Virtual Machine Manager and Orchestrator that has connections to VMware vSphere without third party software (In Operations Manager you can use SNMP to get alarms from vCenter though).

So what can we do with Orchestrator IP for vSphere? This is the activities that is in the pack with version number 7.1.3010:

Screen Shot 2013-02-17 at 18.47.24

And what do we need to configure, well of course we need connection settings to a vCenter server and that is found under the “Options” and then you add your vCenter or if you have several and want to use them you will have to add one configuration for each.

Screen Shot 2013-02-17 at 19.12.05

And here is an simple example of a runbook that changes all VM´s memory to 384 MB, in the runbook I check if the VM is on or off and do an graceful power off activity depending on that status. For each activity in the runbook we have to add what configured vCenter we want to use or the runbook will fail!

Screen Shot 2013-02-17 at 19.19.42

The possibilites are almost endles as you can combine these activitiy with the others and interact with for example SCCM and deploy VM´s and OS. If this list of activities in the IP is not enough it can be extended by either creating your own IP or calling PowerCLI scripts from your runbook. Together with System Center Service Manager we can build nice self service portals that also does stuff on the VMware VM´s based on what the user order.

MAP 8.0 on Windows 8 and inventory VMware vSphere

This weekend I have been trying out Microsoft Assessment and Planning toolkit that late last year came in version 8.0. Last week I was attending a partner training in the DCCM PA on VMMT and one of the components in that is the MAP. The VMMT uses both SC Orchestrator and Veeam Backup and Replicaton to help in automating migration of VMware VM´s to Hyper-V.

I have been working a lot in NetIQ Platespin Recon and had some pointers to the MAP team last year at the MMS in Las Vegas, but not all ideas has yet find their way into this product and yes it is free to download so maybe the resources to this team are limited. I will show you two of the most annoying things later in this post.

I tried to install it on a Windows 8 and got the following error,

Screen Shot 2013-02-16 at 21.16.03

So with powershell I easily add the .Net 3.5 (It is not in there by default)

Screen Shot 2013-02-14 at 15.56.54
Screen Shot 2013-02-14 at 16.08.36

As you can see the output says it does not need a restart but when you try to install there will be an requirement error that says you must restart. and after that everything is ok and I successfully installed MAP.

As for when you want to inventory your VMware environment you do not need to enter every host, Point out the vCenter and an account to that and you are fine, MAP will then analyse and inventory that for hosts and VM´s. If you, as many customers I have been at, not changed your SSL certificate after installation of the vCenter it is important that you uncheck the following SSL verify check or you will not get any inventory data and it helps to also add an account that can talk wmi to the VM´s so you get more information about them.

Screen Shot 2013-02-16 at 21.42.10

So what is the annoying things with this great product. first of all it is not an service so when you want to capture performance data you have to have the application up and running the whole time it is collecting (and no that is not good design). In an migration and consolidation project you want to get data for at least a week and probably a month or more and then have to rely that the application is not closed during this time is not so good (fix that in MAP 9 please). The following screendump shows what dialog I get when I try to close the application

Screen Shot 2013-02-14 at 16.45.45

The next thing is that you might want to get some reports during the performance capture but that is not possible because the task processor is busy (well I heard about single thread applications but did not think they lived in 2013).

Screen Shot 2013-02-14 at 16.42.22

One thing they have fixed is when you are going to collect the performance data you no longer need to add the computers from a csv file as in earlier versions (did not try the 7.0 so do not know if it was fixed already then) but now actually get a list you can choose from!

Screen Shot 2013-02-16 at 23.53.39

Besides these small feature requests or what we should call them I think MAP is a great free tool to help you in getting good answers in your environment. It is not only for virtualization but also helps with answering if you can upgrade your servers to 2012 and also If your clients can run windows 8 and so much more.

Read more and find the link to download it for free here and try out for yourselves.

Managing Hyper-V 2012 with Win 2008 R2/7 RSAT tools

I have noticed several forum posts about some issues managing the Windows 2012 Hyper-V or the free Hyper-V 2012 Server.

Most of the cases are because people try to use the Hyper-V manager in Windows 2008 R2 or the Hyper-V manager from the RSAT tools in Windows 7.

As you can see on this screendump, you can successfully connect to a 2012 Hyper-V from a Win7 Hyper-V manager. But the features offered in the new Hyper-V is not accessible in this GUI, this causes some confusion when handling the VM´s and the Hyper-V role!

Screen Shot 2013-02-09 at 12.18.02

And here you can see that the server HV03 really is a 2012 version:

Screen Shot 2013-02-09 at 12.49.21

So for example, when you are going to edit the VM and add a new virtual harddisk you will notice that the new VHDX is not available

Screen Shot 2013-02-09 at 13.05.09

And as you can see in the following screendump from a new Hyper-V manager:

Screen Shot 2013-02-09 at 13.04.27

Some things work though, you can set more memory than the Windows 2008 R2 limit and also set more than 4 vCPU´s!

Screen Shot 2013-02-09 at 13.13.43

The ability to setup Hyper-V replica and to move VM´s are absent from the GUI as these are new features.

Yes It works to manage some stuff in the old Hyper-V manager but not all so my recommendation as it is not supported you should install a Windows 2012 or a Windows 8 to manage your new Hyper-V 2012 and also more importanly you will get the powershell module to manage it!

I have made a blog post about how to enable the Hyper-V manager and the Powershell module on the Windows 2012 and Windows 8!

Download all SC 2012 SP1 Evaluation VHD files with PowerShell

I was going to download the evaluation VHD´s for System Center 2012 SP1 and doing that the manual way by clicking on each of the links on the download pages and that for all SC 2012 products could seriously give you mental illness, If I counted the files correct it is 99 total + documents.

Screen Shot 2013-02-04 at 20.11.43

I found this guest post on the ScriptingGuys page where Marco did a PowerShell line how to not only find the files but also add them to BITS for download.  This script only works on PowerShell v3.0 because it is using the new Invoke-WebRequest cmdlet, and as you can see on the screendump how easily you can get all download links.

Screen Shot 2013-02-04 at 21.12.20

I have set the new url´s for SC 2012 SP1 RTM eval vhd´s  and added the .docx files and also do a check that in the volume you will store them have enough space, I made the assumption that it is approximately 70 GB total (99 files * ~700 MB each)

Here You can copy this and run on your environment, It will take some hours but at least it saves you the time in clicking 😛

# Download all SC 2012 SP1 VHD Eval
# Niklas Akerlund / Lumagate 2013-02-04

# Downloadfolder
$Dest = "D:\VHDEVAL"
$SizeOfSCSP1 = 70GB

# Get Space on volume
$SpaceRemaining = (Get-Volume $Dest.Split(":")[0]).SizeRemaining

if($SpaceRemaining -gt $SizeOfSCSP1){
((Invoke-WebRequest -Uri "http://www.microsoft.com/en-us/download/details.aspx?id=36435").links | ? href -match "rar$|exe$|docx$").href | %{Start-BitsTransfer -Source $_ -Destination $Dest}
((Invoke-WebRequest -Uri "http://www.microsoft.com/en-us/download/details.aspx?id=36424").links | ? href -match "rar$|exe$|docx$").href | %{Start-BitsTransfer -Source $_ -Destination $Dest}
((Invoke-WebRequest -Uri "http://www.microsoft.com/en-us/download/details.aspx?id=36426").links | ? href -match "rar$|exe$|docx$").href | %{Start-BitsTransfer -Source $_ -Destination $Dest}
((Invoke-WebRequest -Uri "http://www.microsoft.com/en-us/download/details.aspx?id=34781").links | ? href -match "rar$|exe$|docx$").href | %{Start-BitsTransfer -Source $_ -Destination $Dest}
((Invoke-WebRequest -Uri "http://www.microsoft.com/en-us/download/details.aspx?id=36423").links | ? href -match "rar$|exe$|docx$").href | %{Start-BitsTransfer -Source $_ -Destination $Dest}
((Invoke-WebRequest -Uri "http://www.microsoft.com/en-us/download/details.aspx?id=36428").links | ? href -match "rar$|exe$|docx$").href | %{Start-BitsTransfer -Source $_ -Destination $Dest}
((Invoke-WebRequest -Uri "http://www.microsoft.com/en-us/download/details.aspx?id=36427").links | ? href -match "rar$|exe$|docx$").href | %{Start-BitsTransfer -Source $_ -Destination $Dest}
[int]$Sum = ($SizeOfSCSP1 - $SpaceRemaining)/1GB
Write-Host "Free up at least $Sum GB and try again!"