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

Badges
MCSE
Community

Cozumpark Bilisim Portali
Posted in Windows Powershell | No Comment | 24,563 views | 02/05/2014 23:01

You can add Windows Azure PowerShell module into PSModulePath with following:

1
2
3
4
5
6
7
8
#Save the current value in the $p variable.
$p = [Environment]::GetEnvironmentVariable("PSModulePath")
 
#Add the new path to the $p variable. Begin with a semi-colon separator.
$p += ";C:\Program Files (x86)\Microsoft SDKs\Windows Azure\PowerShell\"
 
#Add the paths in $p to the PSModulePath value.
[Environment]::SetEnvironmentVariable("PSModulePath",$p)

Save it into C:\Users\yusufozturk\Documents\WindowsPowerShell\profile.ps1.


Posted in Hayattan | No Comment | 2,205 views | 15/04/2014 15:34

Merhaba,

12 Nisan 2014 Cumartesi günü Microsoft Türkiye’de yapmış olduğum sunumun dosyalarını aşağıdan indirebilirsiniz.

Dosyaları kullanabilmek aynı zamanda PoSHServer kurulumunu da yapmanız gerekecektir.

Kolay gelsin.


Posted in Virtual Machine Manager, Windows Powershell | No Comment | 1,606 views | 01/04/2014 10:41

You can search a VM directory in Cluster Shared Volumes (CSV) with following 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
# VM Name
$VMName = "VM Test"
 
# Get Cluster Nodes
$ClusterNodes = "vmhost01.domain.com","vmhost12.domain.com"
 
foreach ($ClusterNode in $ClusterNodes)
{
	$Volumes = Get-ChildItem -Directory -Path \\$ClusterNode\C$\ClusterStorage\
	foreach ($Volume in $Volumes)
	{
		$ConfigFolders = Get-ChildItem -Directory -Path \\$ClusterNode\C$\ClusterStorage\$Volume
 
		foreach ($ConfigFolder in $ConfigFolders)
		{
			$Result = "0";
 
			Write-Host $ConfigFolder
 
			if ($ConfigFolder -like "*$VMName*")
			{
				Write-Host " "
				Write-Warning "VMName: $VMName"
				Write-Warning "Volume: $Volume"
				Write-Warning "VMHost: $ClusterNode"
				Write-Host " "
			}
		}
	}
}

This script requires at least PowerShell v3 to work.


Posted in Virtual Machine Manager, Windows Powershell | No Comment | 1,769 views | 31/03/2014 17:04

You can grant a user role to a virtual machine with following command:

1
2
3
$UserRole = Get-SCUserRole -Name "Test User Role"
$VM | Set-SCVirtualMachine -Owner $UserRole.Members[0].Name -UserRole $UserRole
Grant-SCResource -Resource $VM -UserName $UserRole.Members[0].Name -UserRoleID @($UserRole.ID.Guid)

After that you will be able to reach it from System Center App Controller.


Posted in Virtual Machine Manager, Windows Powershell | 2 Comments | 3,774 views | 31/03/2014 16:45

You can use following script to get VM CPU Counts on SCVMM 2012 R2:

1
2
3
4
5
6
7
8
9
PS C:\Users\yusufozt\Desktop> $Results = Get-VM | Measure-Object -Property CPUCount -Sum
PS C:\Users\yusufozt\Desktop> $Results
 
Count    : 108
Average  :
Sum      : 292
Maximum  :
Minimum  :
Property : CPUCount

You can get total count by using $Results.Sum value.


Posted in Virtual Machine Manager, Windows Powershell | 2 Comments | 6,053 views | 25/03/2014 16:50

You can get VM list in a VMHostCluster with following command:

1
((Get-SCVMHOST -VMHostCluster $Cluster).Name | foreach { Get-VM -VMHost $_ }).Name

That will output all virtual machine names in that cluster.


Posted in Virtual Machine Manager, Windows Powershell, Windows Server | No Comment | 1,738 views | 25/03/2014 16:44

You can use this script to move your VMs into another Cloud (Cloud Migration) and Cluster on SCVMM 2012 R2.
This script only works on SCVMM 2012 R2 due to vHBA control.
You can remove vHBA control to make it work on SCVMM 2012 SP1.

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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# Parameters
$DestinationCloud = "New Cloud"
$DestinationHostCluster = "cluster.domain.com"
 
# Create VM Array
$VMArray = New-Object System.Collections.ArrayList
$VMArray.Clear();
 
# Add VMs into Array
$AddArray = $VMArray.Add("VM01")
$AddArray = $VMArray.Add("VM02")
$AddArray = $VMArray.Add("VM03")
$AddArray = $VMArray.Add("VM04")
 
# Get Destination Cloud
$Cloud = Get-SCCloud -Name $DestinationCloud
 
# Cloud Host Group Path
$HostGroupPath = (($Cloud.HostGroup)[0]).Path + "*"
 
foreach ($VMName in $VMArray)
{
	# Get VM
	$VM = Get-SCVirtualMachine -Name $VMName
 
	# Output
	Write-Host VM Name: $VMName
	Write-Host " "
 
	if ($VM.HasPassthroughDisk -eq $False -and $VM.HasVirtualFibreChannelAdapters -eq $False)
	{
		# Current Cloud
		$CurrentCloud = Get-SCCloud -Name $VM.Cloud.Name
 
		# Current Hyper-V Host
		$CurrentVMHost = Get-SCVMHost -ComputerName $VM.VMHost.Name
 
		# Create Job Guid
		$JobGuid = [System.Guid]::NewGuid().toString()
 
		# Remove from Cloud
		$SetCloud = $VM | Set-SCVirtualMachine -RemoveFromCloud
 
		# Get Best Available Hyper-V Host
		if ($DestinationHostCluster)
		{
			$VMHostName = (@(Get-SCVMHost | Where {$_.VMHostGroup -like $HostGroupPath -and $_.HostCluster.Name -eq $DestinationHostCluster -and $_.CoresPerCPU -eq $CurrentVMHost.CoresPerCPU -and $_.CPUArchitecture -eq $CurrentVMHost.CPUArchitecture -and $_.CPUFamily -eq $CurrentVMHost.CPUFamily } | Select Name,AvailableMemory | Sort AvailableMemory -Descending)[0]).Name
		}
		else
		{
			$VMHostName = ((Get-SCVMHost | Where {$_.VMHostGroup -like $HostGroupPath -and $_.CoresPerCPU -eq $CurrentVMHost.CoresPerCPU -and $_.CPUArchitecture -eq $CurrentVMHost.CPUArchitecture -and $_.CPUFamily -eq $CurrentVMHost.CPUFamily } | Select Name,AvailableMemory | Sort AvailableMemory -Descending)[0]).Name
		}
 
		if ($VMHostName)
		{
			# Output
			Write-Host Target Host: $VMHostName
 
			# Get Best Available CSV
			$VolumeName = ((Get-SCStorageVolume | Where {$_.VMHost -eq $VMHostName -and $_.IsClusterSharedVolume -eq $True} | Select Name,FreeSpace | Sort FreeSpace -Descending)[0]).Name
 
			# Output
			Write-Host Target Volume: $VolumeName
			Write-Host " "
 
			# Get Hyper-V Host Information
			$VMHost = Get-SCVMHost -ComputerName $VMHostName
			[int64]$VMHostAvailableMemory = [int64]$VMHost.AvailableMemory + 10240 		# Leave 10 GB Available Memory
 
			# Get CSV Information
			$Volume = Get-SCStorageVolume -Name $VolumeName -VMHost $VMHostName
			[int64]$VolumeFreeSpace = [int64]$Volume.FreeSpace + 107374182400 			# Leave 100 GB Free Space
 
			# Control Free Memory
			if ($VM.Memory -lt $VMHostAvailableMemory -and $VM.TotalSize -lt $VolumeFreeSpace)
			{
				# Get Virtual Network Adapters
				$VirtualNetworkAdapters = $VM | Get-SCVirtualNetworkAdapter
 
				foreach ($VirtualNetworkAdapter in $VirtualNetworkAdapters)
				{
					# Clear VM Network
					$VMNetwork = $Null;
 
					# Get VM Network
					$VMNetwork = Get-SCVMNetwork | Where {$_.Name -eq $VirtualNetworkAdapter.VMNetwork.Name}
 
					if (!$VMNetwork)
					{
						$VMNetwork = Get-SCVMNetwork | Where {$_.VMSubnet.SubnetVLANs.VLanID -eq $VirtualNetworkAdapter.VLanID}
					}
 
					# Destination Virtual Network
					$VirtualNetwork = ((Get-VM -Cloud $Cloud | Where {$_.VirtualNetworkAdapters.VMNetwork.Name -eq $VirtualNetworkAdapter.VMNetwork.Name -and $_.VirtualNetworkAdapters.VirtualNetwork})[0]).VirtualNetworkAdapters.VirtualNetwork
 
					# Set VM Network Adapter
					$SetSCVirtualNetworkAdapter = Set-SCVirtualNetworkAdapter -VirtualNetworkAdapter $VirtualNetworkAdapter -VirtualNetwork $VirtualNetwork -VMNetwork $VMNetwork -JobGroup $JobGuid
				}
 
				# Move VM
				$MoveSCVirtualMachine = $VM | Move-SCVirtualMachine -VMHost $VMHostName -HighlyAvailable $True -UseLAN -UseDiffDiskOptimization -JobGroup $JobGuid -Path $VolumeName
 
				Write-Host "Migration process is finished."
				Write-Host "Please check job results to ensure that if operation is successful.."
				Write-Host " "
				Write-Host " "
 
				# Set Cloud
				$SetCloud = $VM | Set-SCVirtualMachine -Cloud $Cloud
 
				# Refresh VM
				$RefreshVM = $VM | Refresh-VM
			}
			else
			{
				Write-Host "Not enough resources to move VM.."
				Write-Host "Skipping migration.."
				Write-Host " "
				Write-Host " "
 
				# Set Cloud
				$SetCloud = $VM | Set-SCVirtualMachine -Cloud $CurrentCloud
			}
		}
		else
		{
			Write-Host "There is no available host to migrate VM.."
			Write-Host "Skipping migration.."
			Write-Host " "
			Write-Host " "
		}
	}
	else
	{
		Write-Host "VM has Pass-through disks or vHBA.."
		Write-Host "Skipping migration.."
		Write-Host " "
		Write-Host " "
	}
}

After migrations, please check SCVMM job results to see if migrations are successful.