search
Categories
Sponsors
VirtualMetric Hyper-V Monitoring, Hyper-V Reporting
Archive
Blogroll

Badges
MCSE
Community

Cozumpark Bilisim Portali
Posted in Virtual Machine Manager, Windows Powershell | No Comment | 4,563 views | 16/07/2013 09:21

You can get CSV reports from your all Clusters with following PowerShell script:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
$Clusters = Get-Content -Path C:\Clusters.txt
foreach ($Cluster in $Clusters)
{
	# Get CSV Disks
	$CSVDisks = Get-ClusterSharedVolume -Cluster $Cluster
 
	foreach ($CSVDisk in $CSVDisks)
	{
		# Get CSV Volume Information
		$CSVVolumeInfo = $CSVDisk | Select -Expand SharedVolumeInfo
		$CSVFriendlyName = $CSVVolumeInfo.FriendlyVolumeName
		$CSVVolume = $CSVFriendlyName.Split("\")[2]
		$CSVVolume = $CSVVolume.ToLower()
		$CSVVolumeID = $CSVDisk.Id
		$CSVState = $CSVDisk.State
 
		# CSV Free Disk Space
		[int]$CSVDiskDriveFreeSpace = ([math]::round((($CSVVolumeInfo | Select -Expand Partition).FreeSpace / 1GB), 0))
 
		# CSV Total Disk Space
		[int]$CSVDiskSpace = ([math]::round((($CSVVolumeInfo | Select -Expand Partition).Size / 1GB), 0))
 
		# CSV Used Disk Space
		[int]$CSVDiskDriveUsedSpace = [int]$CSVDiskSpace - [int]$CSVDiskDriveFreeSpace
 
		# CSV Health
		if ($CSVState -eq "Online")
		{
			if ($CSVVolumeInfo.MaintenanceMode -eq $False)
			{
				if ($CSVVolumeInfo.RedirectedAccess -eq $True)
				{
					$CSVHealth = "Warning"
					$CSVHealthDetails = "Volume is in redirected access."
				}
				else
				{
					$CSVHealth = "Healthy"
					$CSVHealthDetails = "Volume is healthy."
				}
			}
			else
			{
				$CSVHealth = "Monitor"
				$CSVHealthDetails = "Volume is in maintenance mode."	
			}									
		}
		else
		{
			$CSVHealth = "Critical"
			$CSVHealthDetails = "Volume is in offline state."
		}
 
		# CSV Reports
		Write-Host $Cluster
		$Value = $Cluster + ";" + $CSVVolume + ";" + $CSVDiskSpace + ";" + $CSVDiskDriveUsedSpace + ";" + $CSVDiskDriveFreeSpace + ";" + $CSVHealth
		Add-Content -Value $Value -Path C:\CSVVolumes.txt
	}
}

You can export CSVVolumes.txt into Excel file for a good looking reporting :)


Posted in Virtual Machine Manager, Windows Powershell | No Comment | 4,495 views | 25/06/2013 08:40

If you need to sync OS name with VM name on Hyper-V, you can use KVP exchange feature:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
$HyperVHost = "MyHyperV"
filter Import-CimXml
{
   $CimXml = [Xml]$_
   $CimObj = New-Object -TypeName System.Object
   foreach ($CimProperty in $CimXml.SelectNodes("/INSTANCE/PROPERTY"))
   {
       $CimObj | Add-Member -MemberType NoteProperty -Name $CimProperty.NAME -Value $CimProperty.VALUE
   }
   $CimObj
}
 
$VMs = Get-VM -ComputerName $HyperVHost
foreach ($VM in $VMs)
{
   $VMInfo = Get-WmiObject -ComputerName $HyperVHost -Namespace root\virtualization -Query "Select * From Msvm_ComputerSystem Where ElementName='$VM'"
   $KVPData = Get-WmiObject -ComputerName $HyperVHost -Namespace root\virtualization -Query "Associators of {$VMInfo} Where AssocClass=Msvm_SystemDevice ResultClass=Msvm_KvpExchangeComponent"
   $KVPExport = $KVPData.GuestIntrinsicExchangeItems
   $Hostname = ($KVPExport | where {$_.Name -eq "FullyQualifiedDomainName"}).Data
   $VM | Rename-VM -NewName $Hostname
}

Btw, I haven’t tested this script yet. But that should work :)


Posted in Virtual Machine Manager, Windows Powershell | No Comment | 1,970 views | 17/06/2013 14:57

You can get your prod VMs list, Hyper-V hostname, clustername and csv paths like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
$VMs = Get-SCVirtualMachine | where {$_.HostGroupPath -like "All Hosts\*Prod*"}
foreach ($VM in $VMs)
{
	$VMName = $VM.Name
	$VMHostname = $VM.Hostname
	$VMHasPassthroughDisk = $VM.HasPassthroughDisk
	$VMHost = Get-SCVMHost $VMHostname
	$VMHostCluster = $VMHost.HostCluster
	$VMHardDisk = @($VM | Get-VirtualHardDisk)[0].Location
	$VMHardDiskLocation = $VMHardDisk.Split("\")[2]
	$Value = $VMName + "," + $VMHostname + "," + $VMHostCluster + "," + $VMHardDiskLocation
	Add-Content -Value $Value -Path "VMList.txt"
}

If you need to get all vms, just try “All Hosts\*” for all host groups.


Posted in Virtual Machine Manager, Windows Powershell, Windows Server | 4 Comments | 4,972 views | 22/05/2013 16:59

In this sample script, I use SCVMM 2012 to get virtual machine list.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
$Servers = Get-Content C:\Servers.txt
foreach ($Server in $Servers)
{
	$VMInfo = Get-VM $Server
	$VMHost = $VMInfo.VMHost
	$VMHostName = $VMHost.Name
	$VMHostGroup = $VMHost.VMHostGroup
 
	if ($VMInfo.PassThroughDisks)
	{
		$PassThroughDisk = "True"
	}
	else
	{
		$PassThroughDisk = "False"
	}
 
	if ($VMHostGroup -like "All Hosts\*")
	{
		Add-Content -Value $Server -Path C:\Servers.txt
		Add-Content -Value $VMHostName -Path C:\VMHosts.txt
		Add-Content -Value $PassThroughDisk -Path C:\PassThroughDisks.txt
	}
}

Also you can filter specific Host Groups like in this sample.


Posted in Virtual Machine Manager, Windows Powershell | 10 Comments | 16,297 views | 04/04/2013 20:25

Hi guys and ladies! :)

Update: v1.4 is here! Thanks for your feedbacks.

Hyper-V VM Migration Script is ready! Now it’s possible to migrate your VMs from Hyper-V v2 to Hyper-V v3 with quick migration capabilities.

It supports following scenarios:

1. Standalone Hyper-V v2 Host
2. Hyper-V v2 Host in trusted domain
3. Hyper-V v2 Host in untrusted domain

Update v1.4:
1. Fixed network configuration issue on different subnets
2. Improved debugging

Update v1.3:
1. Added support for servers on different subnets

Update v1.2:
1. Linux VM migration support
2. Fixed a bug while getting vhd name
3. Advanced debugging switch (use -DebugMode)

So why it supports untrusted domains? Because you may not want to install Windows Server 2012 Cluster into your existing Windows Server 2008 R2 environment. If you have totally different environment for Hyper-V v3, then this script is your best friend.

Advantages:

1. It supports BITS! It’s ready to move large VHD files.
2. It supports “Rollback“. If there will be any problem, this script will undo any changes!!! :)
3. Licensed in GPLv2. You can use this script in your organization without any licensing issues. Totally free!

How to Install?
1. First download Hyper-V VM Migration Script:
Download Script

2. You can use exe or msi file to installation. I’ve just used migration.exe file to installation.

3. Change Powershell path if you have different drive path.

4. Click Install to begin installation.

5. That’s it! You can start using migration script.

6. Go to Powershell and type following to change execution policy as “AllSigned”.

Set-ExecutionPolicy AllSigned

7. Allow my code publishing certificate. This will prevent you to run untrusted scripts.

New-Migration

8. Installation is done! Now we can start migration of virtual machines.

How to use?

Example 1: If want to migrate VM01 from HV001 (10.10.10.2) to your local Hyper-V v3 host, use following:

New-Migration -VMName "VM01" -VMHost "HV001" -VMPath "C:\ClusterStorage\Volume1"

BTW, -VMPath switch is the destination path. Not your current VM path. This script finds VM path automatically.

Example 2: If HV001 (10.10.10.2) is a standalone machine, use following:

New-Migration -VMName "VM01" -VMHost "10.10.10.2" -Username "Administrator" -Password "123456" -VMPath "C:\ClusterStorage\Volume1"

Example 3: If HV001 (10.10.10.2) is a member of a untrusted domain, use following:

New-Migration -VMName "VM01" -VMHost "10.10.10.2" -Username "Domain\Administrator" -Password "123456" -VMPath "C:\ClusterStorage\Volume1"

Example 4: Having trouble with migration? Use debugging switch (-DebugMode) to see what really makes that problem:

New-Migration -VMName "VM01" -VMHost "10.10.10.2" -VMPath "C:\ClusterStorage\Volume1" -DebugMode

Requirements:

1. You should install this script on to your Hyper-V v3 host.

2. This script doesn’t allow you to migrate VMs if they have snapshots. You should remove them first.

3. Requires Powershell v3. (It comes by default on Windows Server 2012)

4. Hyper-V v2 host and Hyper-V v3 host should have same network switch names. If they are different, this script connects first external network to your virtual machine.

Thanks for using Hyper-V VM Migration script!

-Yusuf.


Posted in Virtual Machine Manager | No Comment | 4,626 views | 07/01/2013 21:34

I specified SQL Server 2012 Always On Group name as a database server while SCVMM 2012 SP1 installation.
SCVMM didn’t see instance name and other databases but installed server and console well.
When I checked database of SCVMM, I see that database is not synced as I expected.

SCVMM creates databases with “Simple” recovery model. You should make it “Full” before adding it to Always-On Group.

Take a full backup of SCVMM database.

Now you can add it to Always-On Group.

Our SCVMM database is now in Always-On Group.

Then I made a failover test to see how SCVMM is reacting..

But boom! SCVMM GUI is crashed! I checked service and saw that service is stopped.

I’ve tried to restart SCVMM service but it gave me error:

Because SCVMM creates “Computer Account” only on primary SQL Server.

You should create same user on your failover SQL Server. After that you will be able to start SCVMM service.

Then I tried a failover test again and no problem! SCVMM works without any problem :)


Posted in Virtual Machine Manager, Windows Powershell | No Comment | 5,911 views | 12/10/2012 11:55

1. How to create RunAs Account?

1
2
3
$SecurePassword = ConvertTo-SecureString "P@ssw0rd!" -AsPlainText -Force
$Credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList "yusufozturk\Administrator", $SecurePassword
New-SCRunAsAccount -Name "Domain Admin" -Credential $Credential

2. How to get RunAs Account?

1
Get-SCRunAsAccount -Name "Domain Admin"

3. How to remove RunAs Account?

1
Get-SCRunAsAccount -Name "Domain Admin" | Remove-SCRunAsAccount