Categories
Sponsors
Archive
Blogroll
Badges
Community
|
Posted in Virtual Machine Manager, Windows Powershell, Windows Server | No Comment | 1,349 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,409 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.
Posted in Virtual Machine Manager, Windows Powershell, Windows Server | No Comment | 1,594 views | 30/09/2013 15:15
You should run this script on Cluster node. Migrates all VM by shutting down first.
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
| # 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
# Stop Virtual Machine
if ($VMState -ne "Off")
{
Stop-VM $VMName -Force
}
# 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
# Start Virtual Machine
if ($VMState -ne "Off")
{
Start-VM $VMName -ComputerName $DestinationNode
}
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
# Stop Virtual Machine
if ($VMState -ne "Off")
{
Stop-VM $VMName -Force
}
# 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
# Start Virtual Machine
if ($VMState -ne "Off")
{
Start-VM $VMName -ComputerName $DestinationNode
}
Write-Host Done.
}
else
{
Write-Host " "
Write-Host Skipping $VMName ..
}
}
After migration, VM will be started on destination host.
Posted in Windows Powershell, Windows Server | No Comment | 2,012 views | 27/09/2013 15:50
You can get VMs with Passthrough disks and vHBA on Hyper-V Cluster via this PowerShell script:
Get-Cluster | Get-ClusterNode | % {Get-VM -ComputerName $_.Name | Where {(($_ | Select -Expand HardDrives).Path -like "Disk*") -or (($_ | Select -expand FibreChannelHostBusAdapters) -ne $Null)}} |
Get-Cluster | Get-ClusterNode | % {Get-VM -ComputerName $_.Name | Where {(($_ | Select -Expand HardDrives).Path -like "Disk*") -or (($_ | Select -expand FibreChannelHostBusAdapters) -ne $Null)}}
You should run your PowerShell as Administrator.
Posted in Windows Powershell, Windows Server | No Comment | 1,995 views | 27/09/2013 10:11
You can get WWN information from servers like this:
1
2
3
4
5
6
7
| $Servers = "VMHOST01","VMHOST02","VMHOST03","VMHOST04"
Foreach ($Server in $Servers)
{
Write-Host $Server
Invoke-Command -ComputerName $Server -ScriptBlock {&C:\StorageTools\fcinfo\fcinfo}
Write-Host " "
} |
$Servers = "VMHOST01","VMHOST02","VMHOST03","VMHOST04"
Foreach ($Server in $Servers)
{
Write-Host $Server
Invoke-Command -ComputerName $Server -ScriptBlock {&C:\StorageTools\fcinfo\fcinfo}
Write-Host " "
}
You must deploy fcinfo.exe to hosts before you execute this script. You may also use WMI to get WWNs.
Posted in Windows Powershell, Windows Server | 2 Comments | 7,686 views | 24/09/2013 10:47
There are some disk operations you can do in Windows Server 2008 R2 with PowerShell:
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
| # Getting Disk Signature
Get-WmiObject Win32_DiskDrive | ft Name, Signature, Index
# Add Disk Signatures into Array
$Signatures = "650992792","650992689"
# Making Them Online
foreach ($Signature in $Signatures)
{
$Disk = Get-WmiObject Win32_DiskDrive | Where {$_.Signature -eq $Signature}
$DiskID = $Disk.index
$DiskPartScript = @"
select disk $DiskID
online disk noerr
"@
$DiskPartScript | diskpart
}
# Making Them Offline
foreach ($Signature in $Signatures)
{
$Disk = Get-WmiObject Win32_DiskDrive | Where {$_.Signature -eq $Signature}
$DiskID = $Disk.index
$DiskPartScript = @"
select disk $DiskID
offline disk noerr
"@
$DiskPartScript | diskpart
} |
# Getting Disk Signature
Get-WmiObject Win32_DiskDrive | ft Name, Signature, Index
# Add Disk Signatures into Array
$Signatures = "650992792","650992689"
# Making Them Online
foreach ($Signature in $Signatures)
{
$Disk = Get-WmiObject Win32_DiskDrive | Where {$_.Signature -eq $Signature}
$DiskID = $Disk.index
$DiskPartScript = @"
select disk $DiskID
online disk noerr
"@
$DiskPartScript | diskpart
}
# Making Them Offline
foreach ($Signature in $Signatures)
{
$Disk = Get-WmiObject Win32_DiskDrive | Where {$_.Signature -eq $Signature}
$DiskID = $Disk.index
$DiskPartScript = @"
select disk $DiskID
offline disk noerr
"@
$DiskPartScript | diskpart
}
Get-Disk is not available in Windows Server 2008 R2, so you should go with WMI.
Posted in Windows Powershell, Windows Server | No Comment | 1,546 views | 24/09/2013 10:31
There are some disk operations you can do in Windows Server 2012 with PowerShell:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
| # Getting Disk Signature
Get-Disk | ft FriendlyName, Signature
# Add Disk Signatures into Array
$Signatures = "4D53465420202020E55D0891031DB04CB1F2B507ED9FDC88","4D53465420202020E55D0891031DB04CB1F2B507ED9FDC89"
# Making Them Online
foreach ($Signature in $Signatures)
{
Get-Disk | Where {$_.Signature -eq $Signature} | Set-Disk -IsOffline $False
}
# Making Them Offline
foreach ($Signature in $Signatures)
{
Get-Disk | Where {$_.Signature -eq $Signature} | Set-Disk -IsOffline $True
} |
# Getting Disk Signature
Get-Disk | ft FriendlyName, Signature
# Add Disk Signatures into Array
$Signatures = "4D53465420202020E55D0891031DB04CB1F2B507ED9FDC88","4D53465420202020E55D0891031DB04CB1F2B507ED9FDC89"
# Making Them Online
foreach ($Signature in $Signatures)
{
Get-Disk | Where {$_.Signature -eq $Signature} | Set-Disk -IsOffline $False
}
# Making Them Offline
foreach ($Signature in $Signatures)
{
Get-Disk | Where {$_.Signature -eq $Signature} | Set-Disk -IsOffline $True
}
Get-Disk is not available in Windows Server 2008 R2, so you should go with WMI.
|