Categories
Sponsors
Archive
Blogroll
Badges
Community
|
Posted in Virtual Machine Manager, Windows Powershell, Windows Server | No Comment | 3,580 views | 22/08/2013 10:12
This is pretty cool and detailed report for VMs with Dynamic Disk. It requires SCVMM 2012 to get details but it’s possible to change it to use Hyper-V PowerShell Cmdlet.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
| $VMs = Get-VM
foreach ($VM in $VMs)
{
$Disks = Get-VM $VM | Get-SCVirtualHardDisk
foreach ($Disk in $Disks)
{
if ($Disk.VHDType -ne "FixedSize")
{
$DiskLocation = $Disk.Location
$CSVVolume = ($Disk.Location.Split("\"))[2]
$DiskName = ($Disk.Location.Split("\"))[-1]
$DiskSize = ([math]::round(($Disk.Size/1GB), 0))
$DiskMSize = ([math]::round(($Disk.MaximumSize/1GB), 0))
$DiskHost = $Disk.VMHost
$CSVFreeSpace = ([math]::round(((Get-SCStorageVolume | where VMHost -eq $DiskHost | Where Name -like "*$CSVVolume*").FreeSpace/1GB), 0))
$CSVCapacity = ([math]::round(((Get-SCStorageVolume | where VMHost -eq $DiskHost | Where Name -like "*$CSVVolume*").Capacity/1GB), 0))
$Value = $VM.Name + ";" + $DiskName + ";" + $CSVVolume + ";" + $CSVFreeSpace + ";" + $CSVCapacity + ";" + $DiskMSize + ";" + $DiskSize + ";" + $DiskHost
Add-Content -Path DiskUsage.txt -Value $Value
}
}
} |
$VMs = Get-VM
foreach ($VM in $VMs)
{
$Disks = Get-VM $VM | Get-SCVirtualHardDisk
foreach ($Disk in $Disks)
{
if ($Disk.VHDType -ne "FixedSize")
{
$DiskLocation = $Disk.Location
$CSVVolume = ($Disk.Location.Split("\"))[2]
$DiskName = ($Disk.Location.Split("\"))[-1]
$DiskSize = ([math]::round(($Disk.Size/1GB), 0))
$DiskMSize = ([math]::round(($Disk.MaximumSize/1GB), 0))
$DiskHost = $Disk.VMHost
$CSVFreeSpace = ([math]::round(((Get-SCStorageVolume | where VMHost -eq $DiskHost | Where Name -like "*$CSVVolume*").FreeSpace/1GB), 0))
$CSVCapacity = ([math]::round(((Get-SCStorageVolume | where VMHost -eq $DiskHost | Where Name -like "*$CSVVolume*").Capacity/1GB), 0))
$Value = $VM.Name + ";" + $DiskName + ";" + $CSVVolume + ";" + $CSVFreeSpace + ";" + $CSVCapacity + ";" + $DiskMSize + ";" + $DiskSize + ";" + $DiskHost
Add-Content -Path DiskUsage.txt -Value $Value
}
}
}
It also shows CSV volume name, capacity and free space information.
Posted in Virtual Machine Manager, Windows Powershell | No Comment | 2,667 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
}
}
}
} |
# 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,915 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
}
} |
$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 Virtual Machine Manager, Windows Powershell, Windows Server | No Comment | 2,457 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
}
} |
$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
} |
$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
} |
$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,232 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) |
(Get-VM | Where UserRole -like "MyUserRole" | Measure-Object -Property CPUCount,Memory -Sum)
That will give you total count of cpu and memory.
Posted in Virtual Machine Manager, Windows Powershell, Windows Server | 1 Comment | 3,571 views | 16/07/2013 09:23
You can get Cluster names from your Hyper-V host list 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
| # Prepare Cluster Array
$ClusterArray = New-Object System.Collections.ArrayList
$Servers = Get-Content -Path C:\Servers.txt
foreach ($Server in $Servers)
{
$VMHost = Get-VMHost -ComputerName $Server
$HyperVFQDN = $VMHost.FullyQualifiedDomainName
if ($VMHost)
{
$ClusterName = (@(Get-Cluster $Server | Get-ClusterGroup | where GroupType -eq "VirtualMachine") | Select-Object -First 1).Cluster.Name
if ($ClusterName)
{
$TestCluster = $ClusterArray.Contains("$ClusterName")
if ($TestCluster -ne $True)
{
# Update Cluster Array
$ClusterArray.Add("$ClusterName") | Out-Null
}
Write-Host $ClusterName
}
}
} |
# Prepare Cluster Array
$ClusterArray = New-Object System.Collections.ArrayList
$Servers = Get-Content -Path C:\Servers.txt
foreach ($Server in $Servers)
{
$VMHost = Get-VMHost -ComputerName $Server
$HyperVFQDN = $VMHost.FullyQualifiedDomainName
if ($VMHost)
{
$ClusterName = (@(Get-Cluster $Server | Get-ClusterGroup | where GroupType -eq "VirtualMachine") | Select-Object -First 1).Cluster.Name
if ($ClusterName)
{
$TestCluster = $ClusterArray.Contains("$ClusterName")
if ($TestCluster -ne $True)
{
# Update Cluster Array
$ClusterArray.Add("$ClusterName") | Out-Null
}
Write-Host $ClusterName
}
}
}
After that you can use your Cluster names to get CSV reports.
|