none
Generate WWPN from Multiple Servers RRS feed

  • Question

  • Hello, I am trying to make this script that will generate the WWPNs from multiple servers, but for some reason it is only generating the WWPN of the machine but not the hostnames, how do I make it generate the hostname of each WWPN that it lists?

    $computers=Get-ContentC:\scripts\servers.txt


    Get-WmiObject

    -computername$computers-classMSFC_FibrePortHBAAttributes-namespace"root\WMI"|Select-ExpandpropertyAttributes|%{ ($_.PortWWN |%{"{0:x2}"-f$_}) -join":"

    Wednesday, May 7, 2014 1:49 PM

Answers

  • Hi Gramelot,

    you only get the PortWWN, because you select it exclusively at the end of your pipeline. Here's a slight rebuild:

    # Get list of computernames
    $Computers = Get-Content "C:\scripts\servers.txt"
    
    # Prepare result storage
    $Results = @()
    
    # Iterate over each Computer
    foreach ($Computer in $Computers)
    {
    	# Grab PortWWN
    	$PortWWN = Get-WmiObject -computername $Computer -class MSFC_FibrePortHBAAttributes -namespace "root\WMI" | Select-ExpandpropertyAttributes | %{ ($_.PortWWN | %{ "{0:x2}" -f $_ }) -join ":" }
    	
    	# Add result to result storage
    	$Results += New-Object PSObject -Property @{ Computer = $Computer; PortWWN = $PortWWN }
    }
    
    # Report result
    $Results

    Cheers,
    Fred


    There's no place like 127.0.0.1

    • Marked as answer by Gramelot Friday, May 9, 2014 8:57 PM
    Friday, May 9, 2014 11:21 AM

All replies

  • What is in $computers?  It must be set correctly.


    ¯\_(ツ)_/¯

    Friday, May 9, 2014 10:49 AM
  • Hi Gramelot,

    you only get the PortWWN, because you select it exclusively at the end of your pipeline. Here's a slight rebuild:

    # Get list of computernames
    $Computers = Get-Content "C:\scripts\servers.txt"
    
    # Prepare result storage
    $Results = @()
    
    # Iterate over each Computer
    foreach ($Computer in $Computers)
    {
    	# Grab PortWWN
    	$PortWWN = Get-WmiObject -computername $Computer -class MSFC_FibrePortHBAAttributes -namespace "root\WMI" | Select-ExpandpropertyAttributes | %{ ($_.PortWWN | %{ "{0:x2}" -f $_ }) -join ":" }
    	
    	# Add result to result storage
    	$Results += New-Object PSObject -Property @{ Computer = $Computer; PortWWN = $PortWWN }
    }
    
    # Report result
    $Results

    Cheers,
    Fred


    There's no place like 127.0.0.1

    • Marked as answer by Gramelot Friday, May 9, 2014 8:57 PM
    Friday, May 9, 2014 11:21 AM
  • Thank you Fred!!!
    Friday, May 9, 2014 8:58 PM