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

Badges
MCSE
Community

Cozumpark Bilisim Portali
Posted in Windows Powershell, Windows Server | No Comment | 1,586 views | 26/10/2013 20:44

You can use this script to move only selected VMs live between Hyper-V Clusters.

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
# Configuration
$DestinationCluster = "HyperVCluster"
 
# Get Host and Cluster Information
$Hostname = (Get-VMHost).Name
$SourceCluster = (Get-Cluster $Hostname).Name
 
# Create VM Array
$VMArray = New-Object System.Collections.ArrayList
$VMArray.Clear();
 
$AddArray = $VMArray.Add("VM01")
$AddArray = $VMArray.Add("VM02")
$AddArray = $VMArray.Add("VM03")
 
# Get All Virtual Machines
$AllVMs = Get-VM
foreach ($VM in $AllVMs)
{
	# Get VM and Cluster Information
	$VMName = $VM.Name
	$HyperVHost = $VM.ComputerName
	$VMState = $VM.State
	$ClusterGroup = Get-ClusterGroup | where Name -like "*$VMName*"
 
	if ($VMArray.Contains($VMName) -eq $True)
    {
		# Remove from Cluster Resources
		if ($ClusterGroup)
		{
			Get-ClusterGroup $ClusterGroup.Name -Cluster $SourceCluster | Remove-ClusterGroup -RemoveResources -Force
		}
 
		Write-Host " "
		Write-Host Working on $VMName ..
 
		# Get Volume and Memory Information
		$Volume = ((Get-ClusterSharedVolume -Cluster $DestinationCluster | Select -ExpandProperty SharedVolumeInfo | Select @{label="Name";expression={(($_.FriendlyVolumeName).Split("\"))[-1]}},@{label="FreeSpace";expression={($_ | Select -Expand Partition).FreeSpace}} | Sort FreeSpace -Descending)[0]).Name
		$DestinationNode = ((Get-Cluster $DestinationCluster | Get-ClusterNode | Select Name,@{label="FreeMemory";expression={([math]::round(((Get-WmiObject -ComputerName $_.Name -Class Win32_OperatingSystem).FreePhysicalMemory / 1KB), 0))}} | Sort FreeMemory -Descending)[0]).Name
 
		# Move Virtual Machine
		Move-VM $VMName -ComputerName $HyperVHost -DestinationHost $DestinationNode -IncludeStorage -DestinationStoragePath C:\ClusterStorage\$Volume\$VMName
 
		# Add to Destination Cluster Resources
		Add-VMToCluster $VMName -Cluster $DestinationCluster
 
		Write-Host Done.
	}
	else
    {
		Write-Host " "
		Write-Host Skipping $VMName ..
	}
}

You can add many VMs into array. Script will skip other VMs.


Posted in Virtual Machine Manager, Windows Powershell | No Comment | 3,641 views | 26/10/2013 20:18

You can use this script to see how much quota user role has and how much consumes in cloud.

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
# Create Quota Array
$QuotaArray = New-Object System.Collections.ArrayList
 
$UserRoles = Get-SCUserRole
foreach ($UserRole in $UserRoles)
{
	$QuotaArray.Clear();
	Write-Host " "
	Write-Host "User Role: $UserRole"
	Write-Host " "
	$Quotas = Get-SCUserRoleQuota | Where RoleID -eq $UserRole.ID
	foreach ($Quota in $Quotas)
	{
		$QuotaCloudID = $Quota.CloudID
		# Get Cloud
		$Cloud = Get-SCCloud | Where ID -eq $QuotaCloudID
		$CloudName = $Cloud.Name
		$CPUCountQuota = $Quota.CPUCount
		$MemoryMBQuota = $Quota.MemoryMB
 
		if ($QuotaArray.Contains("$CloudName") -eq $False)
		{
			# Get Cloud Usage
			$CloudUsage = Get-SCCloudUsage -Cloud $Cloud -UserRole $UserRole
 
			$CPUCountUsage = $CloudUsage.CPUUsageCount
			$MemoryUsageMB = $CloudUsage.MemoryUsageMB
			$StorageUsageGB = $CloudUsage.StorageUsageGB
			$VMUsageCount = $CloudUsage.VMUsageCount
 
			Write-Host "Cloud: $CloudName"
			Write-Host "CPU Count: $CPUCountQuota"
			Write-Host "CPU Count Usage: $CPUCountUsage"
			Write-Host "Memory: $MemoryMBQuota"
			Write-Host "Memory Usage: $MemoryUsageMB"
			Write-Host "Storage Usage: $StorageUsageGB"
			Write-Host "VM Count Usage: $VMUsageCount"
			Write-Host " "
 
			# Add to Array
			$AddArray = $QuotaArray.Add("$CloudName")
		}
	}
}

I tried to do best formating in this :) Output is even more readable now.


Posted in Virtual Machine Manager, Windows Powershell, Windows Server | No Comment | 2,609 views | 23/10/2013 09:02

You can use this script to get details information of your Hyper-V Cluster:

1
2
(Get-Cluster | Get-ClusterNode | Select Name,@{label="CPU";expression={@(Get-WmiObject -ComputerName $_.Name -Class Win32_Processor)[0].Name}},@{label="Free Memory (GB)";expression={([math]::round(((Get-WmiObject -ComputerName $_.Name -Class Win32_OperatingSystem).FreePhysicalMemory / 1MB), 0))}},@{label="Free Memory (%)";expression={([math]::round(([math]::round(((Get-WmiObject -ComputerName $_.Name -Class Win32_OperatingSystem).FreePhysicalMemory / 1MB), 0))/([math]::round(((Get-WmiObject -ComputerName $_.Name -Class Win32_OperatingSystem).TotalVisibleMemorySize / 1MB), 0))*100))}},@{label="Total Memory (GB)";expression={([math]::round(((Get-WmiObject -ComputerName $_.Name -Class Win32_OperatingSystem).TotalVisibleMemorySize / 1MB), 0))}} | Sort Name) >> C:\info.txt
(Get-ClusterSharedVolume | Select -ExpandProperty SharedVolumeInfo | Select @{label="Name";expression={(($_.FriendlyVolumeName).Split("\"))[-1]}},@{label="Free Space (GB)";expression={([math]::round(((($_ | Select -Expand Partition).FreeSpace)/ 1GB), 0))}},@{label="Percent Free (%)";expression={([math]::round((($_ | Select -Expand Partition).PercentFree), 0))}},@{label="Total Space (GB)";expression={([math]::round(((($_ | Select -Expand Partition).Size)/ 1GB), 0))}} | Sort Name) >> C:\info.txt

That will output results into C:\info.txt.


Posted in Hayattan | No Comment | 2,037 views | 23/10/2013 08:06

CozumPark’in Microsoft Turkiye ofisinde gerçekleştireceği Server 2012 R2 Day’de PowerShell v4 anlatıyorum. Gelin hep birlikte vakit geçirelim dostlar :)

RDS20082012Dayv1

Etkinlik Programı:

Salon – 1
09:00 – 09:30 Kahvaltı
09:30 – 10:30 Windows Server 2012 R2 RDS Yenilikleri
10:30 – 10:45 Çay & Kahve Arası
10:45 – 11:45 PowerShell 4: Desired State Configuration (DSC)
11:45 – 12:00 Çay & Kahve Arası
12:00 – 13:00 Hyper-V Replica

Salon – 2
09:00 – 09:30 Kahvaltı
09:30 – 10:30 Server 2012 R2 Active Directory & Group Policy, Yenilikleri
10:30 – 10:45 Çay & Kahve Arası
10:45 – 11:45 Server 2012 R2 BYOD Yetenekleri & Workplace Join
11:45 – 12:00 Çay & Kahve Arası
12:00 – 13:00 Domain Controller Clonning & Snapshot Uygulamaları

Desired State Configuration’ı ilk kez anlatma mutluluğunu duyuyor olacağım :)


Posted in Windows Powershell, Windows Server | No Comment | 4,469 views | 09/10/2013 16:07

You can find duplicated SPNs in your AD with this PowerShell script. That will output into txt file and console.

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
$ADObjects = Get-ADObject -Filter "objectClass -eq 'user' -and objectClass -eq 'computer'" -Properties "samaccountname","serviceprincipalname"
$Array = New-Object System.Collections.ArrayList
$Array.Clear();
 
foreach ($ADObject in $ADObjects)
{
   $SamAccountName = $ADObject.SamAccountName
   $ServicePrincipalName = $ADObject.ServicePrincipalName
 
   foreach ($SPN in $ServicePrincipalName)
   {
		$ReferenceObject = "$SamAccountName;$SPN"
 
		if ($Array -like "*$SPN")
		{
			$Matched = $Array -like "*$SPN"
			foreach ($Match in $Matched)
			{
				$MatchSAM = $Match.Split(";")[0]
				if ($MatchSAM -ne $SamAccountName)
				{
				   $Value = "$ReferenceObject%$Match"
				   Write-Host $Value
				   Add-Content -Value $Value -Path duplicated.txt
				}
			}
		}
		else
		{
			$Array.Add("$ReferenceObject")
		}
   }
}

You should split duplicated objects by %.


Posted in Virtual Machine Manager, Windows Powershell, Windows Server | No Comment | 1,607 views | 02/10/2013 14:56

Life saver if you have many nodes in a Hyper-V cluster :)

1
2
3
4
5
6
7
8
9
10
11
12
$SANSwitches = Get-Cluster | Get-ClusterNode | % { Get-VMSAN -ComputerName $_.Name }
Foreach ($SANSwitch in $SANSwitches)
{
	$Name = $SANSwitch.Name
	$HBADetails = $SANSwitch | Select -Expand HBAs
	$PortAddress = $HBADetails.PortAddress
	$ComputerName = $HBADetails.PSComputerName
	Write-Host "Server: $ComputerName"
	Write-Host "Switch Name: $Name"
	Write-Host "Port Address: $PortAddress"
	Write-Host " "
}

Just buy me a cup of coffee if you like it :)


Posted in Windows Powershell, Windows Server | No Comment | 1,443 views | 01/10/2013 14:28

You can see Shared Nothing Migration logs under event logs:

Applications and Services Logs > Windows > Windows > Hyper-V-VMMS > Admin

Also you can get them via PowerShell:

Get-WinEvent Microsoft-Windows-Hyper-V-VMMS-Admin -MaxEvents 10 | Where Id -like "2041*"

I don’t see messages output on my server but you may give it a try :)