PowerShell advanced function (cmdlet) to get WWN (PWWN) of all cluster nodes


I wrote a very simple PowerShell script (Advanced Function) that will simplify process to add a new disk to any failover cluster (Hyper-V, SQL) that is connected to SAN via Fibre Channel.

If you need WWN (PWWN) of all nodes in the cluster then you need to know only a name of a single node or name of the cluster.

Examples

Enter node name

Get-ClusterNodeInitiatorPort -Cluster OneOfMyNode |
    Export-Csv -Path 'C:\Temp\data.csv'

Enter cluster Name

Get-ClusterNodeInitiatorPort -Cluster MyCluster |
    Format-Table -AutoSize

Code

Function Get-ClusterNodeInitiatorPort
{
    <#
    .SYNOPSIS
        Enter name of the cluster or any node and get all node names and their WWN (PWWN)

    .DESCRIPTION
        Developer
            Developer: Rudolf Vesely, http://rudolfvesely.com/
            Copyright (c) Rudolf Vesely. All rights reserved
            License: Free for private use only

            "RV" are initials of the developer's name Rudolf Vesely and distingue names of Rudolf Vesely's cmdlets from the other cmdlets.

        Description
            Enter name of the cluster or any node and get all node names and their WWN (PWWN).

        Requirements
            Developed and tested using PowerShell 4.0.

    .PARAMETER Cluster
        Name of cluster or node.

    .EXAMPLE
        'EXAMPLE: Enter name of the cluster or any node'
        Get-ClusterNodeInitiatorPort -Cluster MyCluster |
            Format-Table -AutoSize

    .INPUTS

    .OUTPUTS
        System.Management.Automation.PSCustomObject

    .LINK
        https://techstronghold.com/
    #>

    [CmdletBinding(
        DefaultParametersetName = 'Cluster',
        SupportsShouldProcess = $true,
        PositionalBinding = $false,
        HelpURI = 'https://techstronghold.com/',
        ConfirmImpact = 'Medium'
    )]

    Param
    (
        [Parameter(
            Mandatory = $true,
            Position = 0,
            ParameterSetName = 'Cluster',
            ValueFromPipelineByPropertyName = $true
        )]
        [ValidateLength(1, 255)]
        [Alias('ClusterName')]
        [Alias('NodeName')]
        [string[]]$Cluster
    )

    Begin
    {
        # Configurations
        $ErrorActionPreference = 'Stop'
        if ($PSBoundParameters['Debug']) { $DebugPreference = 'Continue' }
        Set-PSDebug -Strict
        Set-StrictMode -Version Latest
    }

    Process
    {
        foreach ($clusterItem in $Cluster)
        {
            $clusterNodeItems = Get-ClusterNode -Cluster $clusterItem |
                Select-Object -ExpandProperty Name

            foreach ($clusterNodeItem in $clusterNodeItems)
            {
                $items = Invoke-Command -ComputerName $clusterNodeItem -ScriptBlock { Get-InitiatorPort }

                foreach ($item in $items)
                {
                    [PsCustomObject]@{
                        Computername    = $clusterNodeItem
                        NodeAddress     = $item.NodeAddress
                        PortAddress     = $item.PortAddress
                    }
                }
            }
        }
    }

    End
    {
    }
}

Leave a Reply

Your email address will not be published. Required fields are marked *

Active Directory Advanced function AlwaysOn Availability Groups AlwaysOn Failover Cluster Instances Building Cloud Cloud Cluster Cmdlet Database Deployment Design DFS Domain Controller DSC Fabric Failover Clustering File Server Group Policy Hardware Profile Host Hyper-V Installation Library Library Asset Library Server Network Operations Manager Orchestrator PowerShell PowerShell User Group PowerShell Workflow Security Service Manager SQL Server Storage System Center Template Time Time Synchronization Tips Virtual Machine Virtual Machine Manager VM Network VM Template Windows Server 2012 R2