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,192 views | 07/01/2014 15:03

You can use this example to get disk indexes to use it in other orchestrator tasks like Disk Format.

1
2
3
4
5
6
7
8
9
10
11
$VMName = $PoSHQuery.VMName
$Snapshot = Get-WmiObject Win32_DiskDrive -ComputerName $VMName
$DiskIndex = "index"
foreach ($DiskItems in $Snapshot)
{
	$Index = $DiskItems.Index
	$DiskIndex += ";$Index"
}
@"
$($DiskIndex)
"@

Result gives you current disk indexes in remote server.


Posted in Windows Powershell, Windows Server | No Comment | 2,697 views | 07/01/2014 14:42

This is my format disk script for System Center Orchestrator. PoSHServer and PsExec is required for operation.

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
# Get Parameters
$VMName = $PoSHQuery.VMName
$DiskDrive = $PoSHQuery.DiskDrive
$DiskIndex = $PoSHQuery.DiskIndex
 
if (!$VMName -or !$DiskIndex -or !$DiskDrive)
{
	$ResultMessage = "A required parameter is not exist. Please check parameters."
	$Result = "1"
}
else
{
	# Clear Values
	$MountPoint = $Null;
	$DriveLetter = $Null;
 
	if ($DiskDrive.Length -gt "3")
	{
		$MountPoint = $DiskDrive
	}
	else
	{
		$DriveLetter = $DiskDrive	
	}	
 
	if ($DriveLetter)
	{
		$Type = "1"
 
		# Parameter Control
		if ($DriveLetter.Length -gt "1")
		{
			$DriveLetter = $DriveLetter.Remove(1)
		}
 
		# Create Drive Letter Array
		$DriveLetterArray = New-Object System.Collections.ArrayList
		$DriveLetterArray.Clear();
		$Volumes = (Get-WmiObject Win32_Volume -ComputerName $VMName)
		foreach ($Volume in $Volumes)
		{
			$VolumeLetter = $Volume.DriveLetter
			$AddArray = $DriveLetterArray.Add("$VolumeLetter")
		}
 
		# Control Drive Letter
		$DriveLetterControl = $DriveLetter + ":"
		if ($DriveLetterArray.Contains($DriveLetterControl) -eq $True)
		{
			$ResultMessage = "That drive letter is already exist in the server. Please format disk drive manually."
			$Result = "1"
		}
		else
		{
			$Result = "0"
		}
	}
	elseif ($MountPoint)
	{
		$Type = "2"
 
		$TargetDrive = $MountPoint.Remove(1)
		$TargetPath = $MountPoint.Split(":")[1]
		$TargetSharePath = "\\" + $VMName + "\" + $TargetDrive + "$" + $TargetPath
 
		$TestTargetPath = Test-Path $TargetSharePath
		if ($TestTargetPath)
		{
			$ResultMessage = "That mount point is already exist. Please format disk drive manually."
			$Result = "1"
		}
		else
		{
			$CreateTargetFolder = New-Item $TargetSharePath -ItemType Directory
 
			$Result = "0"
		}
	}
	else
	{
		$ResultMessage = "A required parameter is not exist. Please check parameters."
		$Result = "1"
	}	
}
 
if ($Result -eq "0")
{
	$Snapshot2 = (Get-WmiObject Win32_DiskDrive -ComputerName $VMName).Index
	$DiskIndex = $DiskIndex.TrimStart("index;")
	$Snapshot1 = $DiskIndex.Split(";")
	$DiffDiskIndex = (Diff $Snapshot1 $Snapshot2).InputObject
	if ($DiffDiskIndex)
	{
		$Value1 = "select disk $DiffDiskIndex"
		$Value2 = "online disk noerr"
		$Value3 = "attributes disk clear readonly"
		$Value4 = "create partition primary"
		$Value5 = "format fs=ntfs quick"
 
		if ($Type -eq "1")
		{
			$Value6 = "assign letter=$DriveLetter"
		}
 
		if ($Type -eq "2")
		{
			$Value6 = "assign mount=$MountPoint"
		}
 
		$Path = "\\" + $VMName + "\C$\diskpart.txt"
		Add-Content -Value $Value1 -Path $Path
		Add-Content -Value $Value2 -Path $Path
		Add-Content -Value $Value3 -Path $Path
		Add-Content -Value $Value4 -Path $Path
		Add-Content -Value $Value5 -Path $Path
		Add-Content -Value $Value6 -Path $Path
 
		$PsExecPath = "C:\Windows\System32\WindowsPowerShell\v1.0\Modules\PoSHServer\http\PsExec.exe"
		$Command1 = "diskpart /s C:\diskpart.txt"
		$Shell1 = $PSExecPath + " -accepteula \\" + $VMName + " " + $Command1
		$FormatDisk = c md.exe /c $Shell1
		Remove-Item -Path $Path
 
		$ResultMessage = "Disk is successfully formatted."
		$Result = "0"
	}
	else
	{
		$ResultMessage = "No new virtual disk detected. Please check previous steps in Orchestrator."
		$Result = "1"
	}
}
 
@"
	$($ResultMessage)
"@

This is just an example to show you how to automate disk operations via Orchestrator.


Posted in Virtual Machine Manager, Windows Powershell, Windows Server | No Comment | 1,550 views | 23/12/2013 11:15

This script requires SCVMM 2012 SP1. You should execute it on SCVMM PowerShell:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
$Pt = 0;
$VMs = Get-VM
foreach ($VM in $VMs)
{
	$VMName = $VM.Name
	$Cloud = $VM.Cloud
 
	if ($VM.PassThroughDisks)
	{
		$PassThroughDisk = "True"
		Write-Host $VMName
		Write-Host $Cloud
		$Value = $VMName + ";" + $Cloud
		Add-Content -Value $Value -Path C:\yusufozt\PassThroughDisks.txt
		$Pt++
	}
}
Write-Host "Total VM: $Pt"

You can export into Microsoft Excel for a table view.


Posted in Virtual Machine Manager, Windows Powershell, Windows Server | No Comment | 1,658 views | 23/12/2013 10:31

Merhaba,

Cumartesi günü Microsoft Türkiye’de yapmış olduğum PowerShell ile Hyper-V Yönetimi sunumunda kullanmış olduğum Powerpoint ve Demo dosyalarına aşağıdaki bağlantı üzerinden ulaşabilirsiniz.

Sunum dosyaları içerisinde düzenlediğimiz toplam 3 tane dosya var.

http\template\main.html: Tabloları yarattığımız html dosyası
http\js\custom\jquery.vm.reports.js: XML’i okuyup, yorumlayan jscript
Get-MyVMs.ps1: Hyper-V’den değerleri çekip XML haline getirdiğimiz dosya

Herkese kolay gelsin :)


Posted in Virtual Machine Manager, Windows Powershell, Windows Server | No Comment | 2,286 views | 19/12/2013 10:38

You can get memory reporting of your SCVMM Clouds via this script.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
$Clouds = Get-SCCloud
foreach ($Cloud in $Clouds)
{
	$VMs = Get-SCCloud $Cloud | Get-VM
	$VMCount = $VMs.Count
	$TotalMemory = [math]::round((($VMs | Measure-Object -Sum MemoryAssignedMB).Sum / 1KB), 0)
	$AvgMemory = [math]::round(($TotalMemory / $VMCount), 0)
 
	Write-Host "Cloud: $Cloud"
	Write-Host "VM Count: $VMCount"
	Write-Host "Total Memory: $TotalMemory GB"
	Write-Host "Avg Memory: $AvgMemory GB"
	Write-Host " "
}

You will also see average memory usage of your virtual machines.


Posted in Virtual Machine Manager, Windows Powershell, Windows Server | No Comment | 2,891 views | 19/12/2013 09:58

You can get memory reporting of your Hyper-V clusters via this script.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
$Clusters = Get-Content C:\Cluster.txt
foreach ($Cluster in $Clusters)
{
	[int]$TotalFreeMemory = 0;
	[int]$TotalMemory = 0;
	$ClusterNodes = Get-Cluster $Cluster | Get-ClusterNode
	foreach ($ClusterNode in $ClusterNodes)
	{
		[int]$FreeMemory = [math]::round(((Get-WmiObject -ComputerName $ClusterNode -Class Win32_OperatingSystem).FreePhysicalMemory / 1MB), 0)
		[int]$TotalFreeMemory = [int]$TotalFreeMemory + [int]$FreeMemory
		[int]$NodeMemory = [math]::round(((Get-WmiObject -ComputerName $ClusterNode -Class Win32_OperatingSystem).TotalVisibleMemorySize / 1MB), 0)
		[int]$TotalMemory = [int]$TotalMemory + [int]$NodeMemory
	}
	[int]$TotalAvailableMemory = [int]$TotalFreeMemory - [int]$NodeMemory
 
	Write-Host "Cluster: $Cluster"
	Write-Host "Total Memory: $TotalMemory"
	Write-Host "Total Free Memory: $TotalFreeMemory"
	Write-Host "Total Available Memory: $TotalAvailableMemory"
	Write-Host " "
}

I suppose that your all Hyper-V nodes in Cluster has same memory size.


Posted in Virtual Machine Manager, Windows Powershell, Windows Server | No Comment | 9,382 views | 15/11/2013 16:56

You can get list of virtual machines and vlan ids via PowerShell with following command:

1
Get-VM | Select Name,@{label="VlanID";expression={($_.VirtualNetworkAdapters).VlanID}}

I used SCVMM 2012 SP1. Not sure about other versions.