Categories
Sponsors
Archive
Blogroll
Badges
Community
|
Posted in Virtual Machine Manager, Windows Powershell, Windows Server | No Comment | 2,722 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 |
(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,556 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")
}
}
} |
$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 " "
} |
$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*" |
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,054 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 |
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.
Posted in Virtual Machine Manager, Windows Powershell, Windows Server | No Comment | 1,348 views | 30/09/2013 15:44
You can get VMs with vHBA on Hyper-V Cluster via this PowerShell script:
Get-Cluster | Get-ClusterNode | % {Get-VM -ComputerName $_.Name | Where {(($_ | Select -expand FibreChannelHostBusAdapters) -ne $Null)}} | ft Name, ComputerName, State |
Get-Cluster | Get-ClusterNode | % {Get-VM -ComputerName $_.Name | Where {(($_ | Select -expand FibreChannelHostBusAdapters) -ne $Null)}} | ft Name, ComputerName, State
You should run your PowerShell as Administrator.
Posted in Virtual Machine Manager, Windows Powershell, Windows Server | No Comment | 1,408 views | 30/09/2013 15:17
You should run this script on Cluster node. Migrates all VM online.
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 = "cluster.domain.com"
# 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();
# Get VMs and Add to VM Array
$VMs = Get-VM | Where {(($_ | Select -Expand HardDrives).Path -like "Disk*") -or (($_ | Select -expand FibreChannelHostBusAdapters) -ne $Null)}
$AddArray = $VMs | % {$VMArray.Add($_.Name)}
# 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 $False)
{
# 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 ..
}
} |
# Configuration
$DestinationCluster = "cluster.domain.com"
# 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();
# Get VMs and Add to VM Array
$VMs = Get-VM | Where {(($_ | Select -Expand HardDrives).Path -like "Disk*") -or (($_ | Select -expand FibreChannelHostBusAdapters) -ne $Null)}
$AddArray = $VMs | % {$VMArray.Add($_.Name)}
# 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 $False)
{
# 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 ..
}
}
After migration, VM will be started on destination host.
|