Find HBA and WWN Information on Windows using WMI (Updated June 2015)

Find the WWN Information in order to Map storage etc. I recommend combining this script with Send-HtmlEmail function. Send-HTMLEmail -InputObject (Get-HBAWin -ComputerName 10.185.63.253,10.185.63.254) -Subject "HBA Info"

Get-HBAWin.ps1
 
 
 
 
 
4.8 Star
(27)
36,265 times
Add to favorites
Storage
6/25/2015
E-mail Twitter del.icio.us Digg Facebook
  • Such a failing script
    3 Posts | Last post April 04, 2019
    • script has no output. you had to tell there are prerequisites to do first to make it works!
      what a waste of time!
      1 star
    • There is pre-requisite, you should learn PowerShell first.
    • seriously though, if you read the other comments there are lots of examples of people who asked and received assistance. . . you may find your answer there.
  • Unable to Run the Script
    2 Posts | Last post May 26, 2018
    • Hi Ben, hope you are doing well. I'm an IT administrator and I have just started learning powershell to meet my job requirements. I have been asked to fetch the WWN's and SCSI ID's from all the windows servers in the estate. I'm struggling to run your script Get-HBAWin. I know you have explained in one of your blogs how to run the script but I'm not sure where to use those command you have mentioned. Please help me on this. I have added the below into the script and tried to run the command .\Get-HBAWin from a PowerShell window but it gives me an error. Consider me as dumb person and help me with this.
      
      # load the function
      .H:\Tahir\Scripts\GetHBA\Get-HBAWin.ps1
      
      # run the function
      Get-HBAWin -ComputerName Server1,Server2
    • # load the function
      . H:\Tahir\Scripts\GetHBA\Get-HBAWin.ps1
      
      
      # run the function
      Get-HBAWin -ComputerName Server1,Server2
  • information
    3 Posts | Last post March 01, 2018
    • First of all thank, great job really helpful !
      
      Something missing in the second script (with WWPN) :
      PortWWN = [string]$Ports
      
      Without I get "System.Object[]" in the email report.
    • Hi Adil,
      
      Okay that makes sense.
      
      Can you try the following:
      
      Just update the one line as follows then try it again:
      
      from:
      PortWWN          = $Ports
      
      To:
      PortWWN          = $Ports | Out-String
    • Try this
      
      $Ports = @(Get-WmiObject @Params | Select -Expandproperty Attributes | % { ($_.PortWWN | % {"{0:x2}" -f $_}) -join ":"})
      
      and 
      
      PortWWN          = ($Ports | Out-String).Trim()
  • Export the data to CSV
    2 Posts | Last post December 06, 2016
    • Hello Ben,
      
      How can I export the output of this script file to a CSV.
      At this moment i am running the script without any output file.
      Also i want to gather info regarding both portwwn and nodewwn.
      Any suggestion is highly appreciated.I am in urgent need of data collection.
      
    • Get-HBAWin | export-csv $home\desktop\info.txt -notype
  • Script is not providing any output
    7 Posts | Last post June 24, 2015
    • Hi Ben,
      
      I've tried this command .\Get-HBAWin.ps1 -ComputerName 127.0.0.1 and nothing happened. I haven't get any output. Powershell is running in Elevated mode. What's wrong? 
      
      Thanks a lot.
    • With PowerShell we put useful things in PS1 files. A function is an example of a useful thing and Get-HBAWin is an example of a function.
      
      When you run a PS1 file it launches in a protected space in memory, which we call the "Script Scope". Anything that is defined while the script runs disappears once the script has finished running.
      
      in order to run the script in the Global scope you need to do a thing called Dot Sourcing.
      # load the function
      . c:\scripts\Get-HBAWin.ps1
      
      # run the function
      Get-HBAWin -ComputerName Server1,Server2
      
      And that is all there is to it. . .  read this blog post about creating a Module.
      
      https://brwilkinson.wordpress.com/2012/08/30/save-you-pennies-in-a-jar-building-your-own-module-to-save-your-code/
    • Thank you!
    • Hi Ben,
      
      Another one question. Your function is not provide Port WWN information. Can you integrate this code?
      
      Get-WmiObject -class MSFC_FibrePortHBAAttributes -namespace "root\WMI" | Select -Expandproperty Attributes | % { ($_.PortWWN | % {"{0:x2}" -f $_}) -join ":"}
      
      Thanks!
    • Hi Amir, I don't have any HBA adapters to test with unfortunately. I don't like to make any modifications unless I can also test the new code.
    • OK. Thank you!
    • Okay I found somewhere to test . . . here is an update, I haven't really tested this much yet, on a multi card, multi port environment.
      
      
      
      function Get-HBAWin { 
      param( 
      [String[]]$ComputerName = $ENV:ComputerName,
      [Switch]$LogOffline 
      ) 
       
      $ComputerName | ForEach-Object { 
      try {
      	$Computer = $_
      	
      	$Params = @{
      		Namespace    = 'root\WMI'
      		Class        = 'MSFC_FCAdapterHBAAttributes' 
      		ComputerName = $Computer 
      		ErrorAction  = 'Stop'
      		}
      	
      	Get-WmiObject @Params  | ForEach-Object { 
      		$InstanceName = $_.InstanceName -replace '\\','\\'
              $Params['class']='MSFC_FibrePortHBAAttributes'
              $Params['filter']="InstanceName='$InstanceName'" 
              $Ports = @(Get-WmiObject @Params | Select -Expandproperty Attributes | % { ($_.PortWWN | % {"{0:x2}" -f $_}) -join ":"})
              #$NodeWWN = @(Get-WmiObject @Params | Select -Expandproperty Attributes | % { ($_.NodeWWN | % {"{0:x2}" -f $_}) -join ":"})
      
              $hash=@{ 
      				ComputerName     = $_.__SERVER 
      				NodeWWN          = (($_.NodeWWN) | ForEach-Object {'{0:x2}' -f $_}) -join ':'
                      PortWWN          = $Ports
      				Active           = $_.Active 
      				DriverName       = $_.DriverName 
      				DriverVersion    = $_.DriverVersion 
      				FirmwareVersion  = $_.FirmwareVersion 
      				Model            = $_.Model 
      				ModelDescription = $_.ModelDescription
                      UniqueAdapterId  = $_.UniqueAdapterId
                      NumberOfPorts    = $_.NumberOfPorts
                      NodeWWMv2       = $NodeWWN
      		   	   } 
      			New-Object psobject -Property $hash 
      		}#Foreach-Object(Adapter) 
      }#try
      catch {
      	Write-Warning -Message "$Computer is offline or not supported"
      	if ($LogOffline)
      	{
      		"$Computer is offline or not supported" >> "$home\desktop\Offline.txt"
      	}
      }
      
      }#Foreach-Object(Computer) 
       
      }#Get-HBAWin
  • WWPN doesnt work
    3 Posts | Last post June 24, 2015
    • Great Script to fetch NodeWWN. However, the PortWWN wouldnt be listed. The reason being PortWWN is listed only if we use the " |Select -expandproperty attributes". In case of nodeWWN we straight get it by running "get-WmiObject -computername servername -class MSFC_FCadapterHBAAttributes -Namespace 'root\wmi'".
      
      I guess the script needs to be modified to include -expandproperty attributes to be able to fetch the portWWN. 
      
      Unfortunately, "get-WmiObject -computername servername -class MSFC_FibrePortHBAAttributes -Namespace 'root\wmi' |select -expandproperty attributes |fl" successfully lists the PortWWN. however, the server name is blank.
      
      I want to fetch the PortWWN in bulk for a list of servers however, all efforts in vain so far. Any help would be highly appreciated.
    • I would suggest add another line in the script, sorry I don't have any HBA's to test or modify the main script however something like below. . .
      
      $hash=@{ 
         ComputerName     = $_.__SERVER 
         NodeWWN          = (($_.NodeWWN) | ForEach-Object {'{0:x2}' -f $_}) -join ':' 
         PortWWN          = $_.attributes | Select-Object -ExpandProperty PortWWN
         Active           = $_.Active 
         DriverName       = $_.DriverName 
         DriverVersion    = $_.DriverVersion 
         FirmwareVersion  = $_.FirmwareVersion 
         Model            = $_.Model 
         ModelDescription = $_.ModelDescription 
         }
      
      
    • Okay I had the time and chance to test this out ... first cut, let me know how this goes
      
      
      
      function Get-HBAWin { 
      param( 
      [String[]]$ComputerName = $ENV:ComputerName,
      [Switch]$LogOffline 
      ) 
       
      $ComputerName | ForEach-Object { 
      try {
      	$Computer = $_
      	
      	$Params = @{
      		Namespace    = 'root\WMI'
      		Class        = 'MSFC_FCAdapterHBAAttributes' 
      		ComputerName = $Computer 
      		ErrorAction  = 'Stop'
      		}
      	
      	Get-WmiObject @Params  | ForEach-Object { 
      		$InstanceName = $_.InstanceName -replace '\\','\\'
              $Params['class']='MSFC_FibrePortHBAAttributes'
              $Params['filter']="InstanceName='$InstanceName'" 
              $Ports = @(Get-WmiObject @Params | Select -Expandproperty Attributes | % { ($_.PortWWN | % {"{0:x2}" -f $_}) -join ":"})
              #$NodeWWN = @(Get-WmiObject @Params | Select -Expandproperty Attributes | % { ($_.NodeWWN | % {"{0:x2}" -f $_}) -join ":"})
      
              $hash=@{ 
      				ComputerName     = $_.__SERVER 
      				NodeWWN          = (($_.NodeWWN) | ForEach-Object {'{0:x2}' -f $_}) -join ':'
                      PortWWN          = $Ports
      				Active           = $_.Active 
      				DriverName       = $_.DriverName 
      				DriverVersion    = $_.DriverVersion 
      				FirmwareVersion  = $_.FirmwareVersion 
      				Model            = $_.Model 
      				ModelDescription = $_.ModelDescription
                      UniqueAdapterId  = $_.UniqueAdapterId
                      NumberOfPorts    = $_.NumberOfPorts
                      NodeWWMv2       = $NodeWWN
      		   	   } 
      			New-Object psobject -Property $hash 
      		}#Foreach-Object(Adapter) 
      }#try
      catch {
      	Write-Warning -Message "$Computer is offline or not supported"
      	if ($LogOffline)
      	{
      		"$Computer is offline or not supported" >> "$home\desktop\Offline.txt"
      	}
      }
      
      }#Foreach-Object(Computer) 
       
      }#Get-HBAWin
  • How do I query if a fiber card exists
    1 Posts | Last post March 27, 2015
    • I just need a wmi query to ask if a fiber card exists in the system and is active. Active isn't totally needed but wanted. I'm using this for GPO WMI filtering.
  • hyper-v guest
    3 Posts | Last post November 20, 2014
    • Can this parse VM target wwpn information with virtual fibre channel? 
      
      Thank you! 
    • Did you consider using the Hyper-V module for this?
      
      E.g. hyper-v\Get-VMFibreChannelHba -VMName server123 -ComputerName HVHost123
    • Otherwise try:
      
      Get-WmiObject -ComputerName server123VM -Class MSFC_FibrePortHbaAttributes -Namespace 'root\WMI'
  • How to log the errors in the file
    4 Posts | Last post June 21, 2014
    • So is there anyway to log the errors in the files it creates, with hostname then the error its gets? So I know which servers I might need to fix. Also id the 2003 server has FCINFO.EXE installed thi script should work?
    • I updated the script for you to add in logging for computers that are offline or do not have the specific class available, please let me know how you go?
    • So now it is displaying a error. I changed "$Computer is offline or not supported" >> "$home\desktop\Offline.txt" to c:\logfile.txt/ but it did not create the log. looking at the script it would seem I need to add a switch to the command . So should I use -logfile or /logfile?
    • All parameters in Powershell use the -
      
      So it would be -Logfile
      
      If you are writing to C:\logfile.txt you would need to be elevated i.e. running as Admin.
  • Why it's working wrong on win 2012 r2 ?
    3 Posts | Last post February 04, 2014
    • Script results is 
      
      nodewwn 20:00:00:xx:xx:xx:xx:xx
      
      but fcinfo shows
      
      portwwn 10:00:00:xx:xx:xx:xx:xx
      
      Is it normal ? The difference in first octet
      
      and how to get portwwn then
      
      Thank you
    • I've found the answers:
      
      How to get portwwn       Get-InitiatorPort -ConnectionType FibreChannel
      Is it normal ?           Yes
      
      but still can't get it through wmi class.
    • Sorry for annoying
      
      How to get PortWWN
      
      Get-WmiObject -class MSFC_FibrePortHBAAttributes -namespace "root\WMI" | Select -Expandproperty Attributes | % { ($_.PortWWN | % {"{0:x2}" -f $_}) -join ":"}
1 - 10 of 26 Items