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 | 2,666 views | 15/08/2013 10:25

You may export and move a VM to another host or volume, or maybe you may delete a VM but configuration and VHD files may still exist on old location. In that case, you can use this script to find that old VM directories.

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
# Get Cluster Nodes
$ClusterNodes = "Cluster01Node01","Cluster02Node02"
 
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";
			$VMName = "";
 
			$ClusterNodes = Get-Cluster $ClusterNode | Get-ClusterNode
 
			foreach ($ClusterNode in $ClusterNodes)
			{				
				$VMs = Get-VM -ComputerName $ClusterNode
 
				foreach ($VM in $VMs)
				{
					$FullName = $ConfigFolder.FullName
					$FullPath = "C:\" + $FullName.Split("\")[4] + "\" + $FullName.Split("\")[5] + "\" + $FullName.Split("\")[6]
					if ($FullPath -like $VM.ConfigurationLocation)
					{
						$Result = 1;
					}
 
					$VirtualDisks = Get-VM -ComputerName $ClusterNode -Name $VM.Name | Get-VMHardDiskDrive
 
					foreach ($VirtualDisk in $VirtualDisks)
					{						
						if ($VirtualDisk.Path -like "$FullPath*")
						{
							$Result = 1;
						}
					}
				}
			}
 
			if ($Result -ne "1")
			{
				Write-Warning $ConfigFolder.FullName
			}
		}
	}
}

$ClusterNodes should contain different Cluster’s only one nodes. Using with that node name, we can query other nodes too.


Posted in Virtual Machine Manager, Windows Powershell | No Comment | 1,914 views | 12/08/2013 14:17

You can set User Role Quota for each Cloud Profile in SCVMM 2012 SP1.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
$UserRoles = "BackOffice","CallCenter"
foreach ($UserRole in $UserRoles)
{
	$UserRole = Get-SCUserRole $UserRole
	$Clouds = "DMZ Cloud","Prod Cloud","Test Cloud"
	foreach ($Cloud in $Clouds)
	{
	   $MyCloud = Get-SCCloud $Cloud
	   $CloudUsage = Get-SCCloudUsage -Cloud $MyCloud -UserRole $UserRole
	   $CPUCount = $CloudUsage.CPUUsageCount
	   $Memory = $CloudUsage.MemoryUsageMB
	   $VMCount = $CloudUsage.VMUsageCount
	   [int]$NewCPUCount = [int]$CPUCount + 40;
	   [int]$NewMemory = [int]$Memory + 81920;
	   [int]$NewVMCount = [int]$VMCount + 10;
	   Get-SCUserRoleQuota -UserRole $UserRole -Cloud $MyCloud | Set-SCUserRoleQuota -CPUCount $NewCPUCount -MemoryMB $NewMemory -VMCount $NewVMCount
	}
}

That will set on all profiles on $UserRoles array.


Posted in Windows Powershell | 1 Comment | 2,465 views | 31/07/2013 16:48

If you need to store a secure password in PowerShell, you can use this process.

First, you should create a hash from your password:

1
2
3
$Key = (3,4,2,3,56,34,254,222,1,1,2,23,42,54,33,233,1,34,2,7,6,5,35,43)
$SecureString = ConvertTo-SecureString "Your_Password" -AsPlainText -Force
$StandardString = ConvertFrom-SecureString $SecureString -Key $Key

After that you can use $StandarString output in your scripts. Just you need to convert it back to secure string:

1
2
$Key = (3,4,2,3,56,34,254,222,1,1,2,23,42,54,33,233,1,34,2,7,6,5,35,43)
$SecureString = ConvertTo-SecureString $StandardString -Key $Key

That’s it. I hope that helps.


Posted in Virtual Machine Manager, Windows Powershell, Windows Server | No Comment | 2,456 views | 26/07/2013 15:56

You can set User Role Quota for each Cloud Profile in SCVMM 2012 SP1.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
$UserRoles = "BackOffice","CallCenter","ExchangeTeam"
foreach ($UserRole in $UserRoles)
{
	$UserRole = Get-SCUserRole $UserRole
	$Clouds = "DMZ Cloud","Prod Cloud","Test Cloud"
	foreach ($Cloud in $Clouds)
	{
		$MyCloud = Get-SCCloud $Cloud
		$CPUCount = (Get-VM -Cloud $MyCloud | Where UserRole -like "$UserRole" | Measure-Object -Property CPUCount -Sum).Sum
		$Memory = (Get-VM -Cloud $MyCloud | Where UserRole -like "$UserRole" | Measure-Object -Property Memory -Sum).Sum
		$VMCount = (Get-VM -Cloud $MyCloud | Where UserRole -like "$UserRole").Count
		[int]$NewCPUCount = [int]$CPUCount + 40;
		[int]$NewMemory = [int]$Memory + 81920;
		[int]$NewVMCount = [int]$VMCount + 10;
		Get-SCUserRoleQuota -UserRole $UserRole -Cloud $MyCloud | Set-SCUserRoleQuota -CPUCount $NewCPUCount -MemoryMB $NewMemory -VMCount $NewVMCount
	}
}

That will set on all profiles on $UserRoles array.


Posted in Virtual Machine Manager, Windows Powershell, Windows Server | No Comment | 2,443 views | 26/07/2013 12:06

You can change UserRoles of virtual machines on SCVMM 2012 SP1 with following command:

1
2
3
4
5
6
$VMs = Get-VM | Where Name -like "*CALL*" | Where UserRole -eq $Null
foreach ($VM in $VMs)
{
	$UserRole = Get-SCUserRole "MyUserRole"
	$VM | Set-VM -Owner "DOMAIN\Owner" -UserRole $UserRole
}

That will only change “null” user roles. If you want to change existing user roles:

1
2
3
4
5
6
$VMs = Get-VM | Where Name -like "*CALL*" | Where UserRole -like "OldUserRole"
foreach ($VM in $VMs)
{
	$UserRole = Get-SCUserRole "NewUserRole"
	$VM | Set-VM -Owner "DOMAIN\Owner" -UserRole $UserRole
}

It will only looks for VMs like “CALL”. You can leave it blank for all virtual machines.


Posted in Virtual Machine Manager, Windows Powershell | No Comment | 2,230 views | 26/07/2013 11:59

You can get total CPU and memory usage of a user role with following command:

1
(Get-VM | Where UserRole -like "MyUserRole" | Measure-Object -Property CPUCount,Memory -Sum)

That will give you total count of cpu and memory.


Posted in Windows Powershell, Windows Server | No Comment | 1,765 views | 18/07/2013 10:10

You can get DNs of your servers 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
$DomainServers = Get-ADComputer -Filter *
$ChildDomainServers = Get-ADComputer -Filter * -SearchBase "DC=child,DC=domain,DC=com" -Server "child.domain.com"
$Servers = Get-Content C:\Servers.txt
foreach ($Server in $Servers)
{
	$DN = $null;
	$DN = ($DomainServers | where DNSHostName -eq "$Server").DistinguishedName
	if (!$DN)
	{
		$DN = ($ChildDomainServers | where DNSHostName -eq "$Server").DistinguishedName
		if (!$DN)
		{
			Add-Content -Value $Server -Path C:\DNs.txt
		}
		else
		{
			Add-Content -Value $DN -Path C:\DNs.txt
		}
	}
	else
	{
		Add-Content -Value $DN -Path C:\DNs.txt		
	}
}

You should add your server list into C:\Servers.txt.