Forum Discussion

cvandal_163340's avatar
cvandal_163340
Icon for Nimbostratus rankNimbostratus
Jul 14, 2014

Obtain Node Name by Node Description Using PowerShell

Hello,

 

Is it possible to obtain a node's name by looking at the node's description using PowerShell? Almost every node within our environment doesn't have a friendly node name however the description matches the node's hostname. I'm thinking if I could store every node and that node's properties in an array, search for the description, and if found determine the name.

 

1 Reply

  • Hi mate

    Try this one?

    Initialize Snapin
    if ( (Get-PSSnapin | Where-Object { $_.Name -eq "iControlSnapIn"}) -eq $null ){
        Add-PSSnapIn iControlSnapIn
    }
    
    Setup credentials
    $User = "user"
    $Password = "password"
    $BigIP = "10.10.10.10"
    
    Add a type/class to store the node data in
    Add-Type @'
    public class Node
    {
        public string Name;
        public string IP;
        public string Description;
        public string Partition;
    }
    '@
    
    Create an empty array to store the node objects in
    $Nodes = @()
    
    Connect to the BigIP and get an iControl Handle
    $Success = Initialize-F5.iControl -HostName $BigIP -Username $User -Password $Password
    $F5 = Get-F5.iControl
    
    Get the partition list
    $f5partitions = $f5.ManagementPartition
    $partitionlist = $f5partitions.get_partition_list()
    
    Loop through each partition saving node information
    $partitionlist | foreach-object {
        $Partition = $_.partition_name
        $f5partitions.set_active_partition("Common")
    
        $NodeNames = $f5.LocalLBNodeAddressV2.get_list()
        $NodeIPs = $f5.LocalLBNodeAddressV2.get_address($NodeNames)
        $NodeDescriptions = $f5.LocalLBNodeAddressV2.get_description($NodeNames)
    
        for($i=0;$i -lt ($NodeNames.Count);$i++){
            $objTempNode = New-Object Node
            $objTempNode.Name = $NodeNames[$i]
            $objTempNode.IP = $NodeIPs[$i]
            $objTempNode.Description = $NodeDescriptions[$i]
            $objTempNode.Partition = $Partition
    
            $Nodes += $objTempNode
        }
    }
    

    That will store your node information in $Nodes. You can filter by using ie. where-object:

    $nodes | Where-Object { $_.description.Contains("WEB") }
    

    Hope that's what you're looking for?

    Kind regards, Patrik