Author Posts

July 3, 2017 at 11:05 am

Hi All,

I am trying to retrieve my Cluster settings using the Get-Cluster Cmdlet and storing the output in a variable.
I then used the method suggested by Don Jones in the HTML reporting book and built a Hash Table containing the properties I am in interested in. However, the output I get is not formatted correctly (or atleast the way I want to see). What am I doing wrong ?

 
function Get-ClusterInfo {
    [CmdletBinding()]
    param(
        [Parameter(Mandatory=$true)]
        [string]$ClusterName

    )

    $cluster = Get-Cluster -Name $clusterName
    $props = @{'Cluster Name'=$cluster.Name;
                'Cluster Domain'=$cluster.Domain;
                'Enable Shared Volumes'=$cluster.EnableSharedVolumes;
                'Shared Volumes Root'=$cluster.SharedVolumesRoot;
                'Administrative Access Point'=$cluster.AdministrativeAccessPoint;
                'Backup In Progress'=$cluster.BackupInProgress;
                'Fix Quorum'=$cluster.FixQuorum;
                'Witness Dynamic Weight'=$cluster.WitnessDynamicWeight;
                'Dynamic Quorum'=$cluster.DynamicQuorum;
                'Prevent Quorum'=$cluster.PreventQuorum;
                'Quorum Arbitration Time Max (s)'=$cluster.QuorumArbitrationTimeMax;
                'Security Level'=$cluster.SecurityLevel;
                'Shutdown Timeout In Minutes'=$cluster.ShutdownTimeoutInMinutes;
                'Drain On Shutdown'=$cluster.DrainOnShutdown;
                'Netft IPSec Enabled'=$cluster.NetftIPSecEnabled;
                'Lower Quorum Priority NodeId'=$cluster.LowerQuorumPriorityNodeId;
                'Witness Database Write Timeout'=$cluster.WitnessDatabaseWriteTimeout;
                'Database Read/Write Mode'=$cluster.DatabaseReadWriteMode;
                'Witness Restart Interval'=$cluster.WitnessRestartInterval;
                'Recent Events Reset Time'=$cluster.RecentEventsResetTime;
                'Message Buffer Length'=$cluster.MessageBufferLength; 
                }
        New-Object -TypeName PSObject -Property $props

}# End of Get-ClusterInfo


OUTPUT :

PS C:\Users\XXXXX\Documents\Cluster> Get-ClusterInfo -ClusterName USXXXXXX


Witness Restart Interval        : 15
Enable Shared Volumes           : Enabled
Recent Events Reset Time        : 1/17/2017 10:48:03 PM
Dynamic Quorum                  : 1
Lower Quorum Priority NodeId    : 0
Prevent Quorum                  : 0
Quorum Arbitration Time Max (s) : 20
Witness Database Write Timeout  : 300
Cluster Name                    : USXXXXXXXXX
Shutdown Timeout In Minutes     : 20
Security Level                  : 1
Shared Volumes Root             : C:\ClusterStorage
Cluster Domain                  : xxx.xxxxxx.com
Netft IPSec Enabled             : 1
Administrative Access Point     : ActiveDirectoryAndDns
Database Read/Write Mode        : 0
Message Buffer Length           : 50
Backup In Progress              : 0
Drain On Shutdown               : 1
Witness Dynamic Weight          : 1
Fix Quorum                      : 0

PS C:\Users\XXXXX\Documents\Cluster>

July 3, 2017 at 7:40 pm

It'd help to know what you don't like about it ;).

July 4, 2017 at 6:54 am

Aah... The Don himself. 🙂
I want it to appear in the way i defined my Hash table, beginning with Cluster name and Cluster domain name.
Why are the rows/objects being moved around arbitrarily?

July 4, 2017 at 7:22 am

What version of Powershell do you use? Did you ever hear about "[ordered]" hashtables? 😉

https://blogs.technet.microsoft.com/heyscriptingguy/2014/09/30/use-powershell-to-create-ordered-dictionary/

July 4, 2017 at 1:54 pm

Two reasons.

One, a normal hash tabl doesn't preserve order because it creates a memory-optimized version when it's stored.

Second, a tool like you've written isn't suppose to worry about what the output looks like. While you can use "[ordered]$props =", I regard that as a kind of crutch that doesn't get you thinking about the right design patterns.

Option A would be to pipe your output to Select-Object or a Format- command. They'll preserve the order of whatever you specify for display.

Option B would be to put your tool into a script module, create a manifest for it, and have the manifest define a default view – which will give you additional control over the output display, without affecting the integrity of the underlying data. "Learn PowerShell Toolmaking in a Month of Lunches" covers this technique in excruciating detail.

Either of these approaches would be valuable for you to learn and understand, whereas [ordered] – while it will accomplish your short-term goal – won't make you a smarter person.

July 7, 2017 at 1:48 am

Thank you Olaf! I had forgotten about ordered dictionary.

@ Don : Great explanation. While ordered dictionary will take care of my short term requirement, I will work on Option A/Option B as the long term solution.