Quantcast
Channel: VMware Communities: Message List
Viewing all articles
Browse latest Browse all 247646

Script or function to accept pipeline?

$
0
0

So, I wrote a script to get the WWN's of a cluster but it requires manual input and can only get per cluster.  If I wanted to allow it to do something like this:

 

Get-Datacenter | Get-WWN

 

First, does it need to be a function can I pass to a script?  Second what would I put as a parameter to be able to take that pipeline?

 

#Set mandatory parameters for cluster and csvnameparam (
[Parameter(Mandatory=$true)][string]$Cluster,
)#Get cluster and all host HBA information and change format from Binary to hex$list=Get-cluster$cluster | Get-VMhost | Get-VMHostHBA-TypeFibreChannel | Select VMHost,Device,@{N="WWN";E={"{0:X}"-f$_.PortWorldWideName}} | Sort VMhost,Device#Go through each row and put : between every 2 digitsforeach ($itemin$list){   $item.wwn = (&{for ($i=0;$i-lt$item.wwn.length;$i+=2)                       {                             $item.wwn.substring($i,2)                       }}) -join':'
}#Output CSV to current directory.$list | export-csv-NoTypeInformation  WWN.csv

Viewing all articles
Browse latest Browse all 247646

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>