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

Badges
MCSE
Community

Cozumpark Bilisim Portali
Posted in Windows Powershell, Windows Server | 1 Comment | 7,343 views | 01/11/2013 20:43

You can use this script to get local group information from a list of remote servers:

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
$Servers = Get-Content C:\Servers.txt
Foreach ($Server in $Servers)
{
	$Groups = Get-WmiObject Win32_GroupUser –Computer $Server
	$LocalAdmins = $Groups | Where GroupComponent –like '*"Administrators"'
	$LocalUsers = $Groups | Where GroupComponent –like '*"Users"'
	$RDPUsers = $Groups | Where GroupComponent –like '*"Remote Desktop Users"'
 
	Write-Host "Server: $Server"
	Write-Host " "
	Write-Host "Local Admins:"
	$LocalAdmins |% {  
	$_.partcomponent –match ".+Domain\=(.+)\,Name\=(.+)$" > $nul  
	$matches[1].trim('"') + "\" + $matches[2].trim('"')
	}
	Write-Host " "
	Write-Host "Local Users:"
	$LocalUsers |% {  
	$_.partcomponent –match ".+Domain\=(.+)\,Name\=(.+)$" > $nul  
	$matches[1].trim('"') + "\" + $matches[2].trim('"')
	}
	Write-Host " "
	Write-Host "Remote Desktop Users:"
	$RDPUsers |% {  
	$_.partcomponent –match ".+Domain\=(.+)\,Name\=(.+)$" > $nul  
	$matches[1].trim('"') + "\" + $matches[2].trim('"')
	}
	Write-Host " " 
}

This is a quick script that I used today. So didn’t get chance to add error handling, sorry.


Posted in Windows Powershell, Windows Server | No Comment | 1,591 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, Windows Server | No Comment | 2,730 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 Windows Powershell, Windows Server | No Comment | 4,575 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,612 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,450 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 :)


Posted in Windows Powershell, Windows Server | No Comment | 4,056 views | 01/10/2013 10:30

You can use this function to convert your password into secure password.

1
2
3
4
5
6
7
8
9
10
function Generate-Password
{
	$Password = Read-Host "Please type your password"
	$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 "$Password" -AsPlainText -Force
	$StandardString = ConvertFrom-SecureString $SecureString -Key $Key
	$StandardString
}
 
Generate-Password

You can use output key in your PowerShell scripts.