demo-module-explore22.psm1

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
Function Get-VMClusterInfo {
<#
    .NOTES
    ===========================================================================
        Created by: David Stamen
        Organization: VMware
        Blog: www.davidstamen.com
        Twitter: @davidstamen
    ===========================================================================
    .SYNOPSIS
        This is a demo function created for Session to Build and Publish a Powershell Module
    .DESCRIPTION
        This is a demo function created for Session to Build and Publish a Powershell Module
    .EXAMPLE
        Get-VMClusterInfo -Server vc.lab.local -User administrator@vsphere.local -Password VMware1! -Cluster MyCluster01
#>

    Param(
        [parameter(Mandatory=$true)]
        [string] $Server,
        [parameter(Mandatory=$true)]
        [string] $Username,
        [parameter(Mandatory=$true)]
        [String] $Password,
        [parameter(Mandatory=$true)]
        [string] $Cluster
    )
    Connect-VIServer -Server $Server -User $Username -Password $Password  | Out-Null
    $ClusterInfo = Get-Cluster $Cluster
    $Hosts = Get-Cluster $Cluster | Get-VMHost

    $Hosts | ForEach-Object { $ClusterAvailableMemory += $_.MemoryTotalGB}
    $Hosts | ForEach-Object { $ClusterUsedMemory += $_.MemoryUsageGB}
    $Hosts | ForEach-Object { $ClusterAvailableCPU += $_.CpuTotalMhz}
    $Hosts | ForEach-Object { $ClusterUsedCPU += $_.CpuUsageMhz}


        $Result = [pscustomobject] @{
        "Cluster Name" = $ClusterInfo.Name;
        "Host Count" = $Hosts.Count
        "Cluster Available CPU (Mhz)" = $ClusterAvailableCPU
        "Cluster Used CPU (Mhz)" = $ClusterUsedCPU
        "Cluster Available Memory (GB)" = [math]::Round($ClusterAvailableMemory,2)
        "Cluster Used Memory (GB)" = [math]::Round($ClusterUsedMemory,2)
        "DRS Status" = $ClusterInfo.DrsEnabled
        "HA Status" = $ClusterInfo.HAEnabled
    }
    $Result
    Disconnect-VIServer -Server $Server -Confirm:$False  | Out-Null

}