Question

How can I use the output from a custom module to put into a variable preferably an object.

Here is the problem. After importing the custom module and running the cmdlet it always outputs the same info and refuses to be stored in a variable or put into the pipeline. Trying to put in the pipeline or a variable just reproduces the original output and ignores the variable or pipeline symbol.

Example:

PS C:\> Get-FCoEPorts -HbaIndex 0
Port List

Index   NodeWWN                         PortWWN                         FCID

-----   -------                         -------                         ----

 0      10:00:A0:36:9F:0B:3E:E9         20:00:A0:36:9F:0B:3E:E9                     0x4A0680

 1      20:A8:00:0D:EC:96:EA:01         00:FC:0E:00:A8:00:80:00                 0x36A00120

 ...

 93*    10:00:A0:36:9F:0B:3E:E9         20:3E:A0:36:9F:0B:3E:E9                 0x4A0764

 94     20:A8:00:0D:EC:96:EA:01         00:FC:0E:00:A8:00:80:00                 0x36A03F20

* - Virtual Ports.

So that is the expected output but trying this:

$a = Get-FCoEPorts -HbaIndex 0

or this:

(Get-FCoEPorts -HbaIndex 0).PortWWN

or this:

$getports = Get-FCoEPorts -HbaIndex 0 | select -expand PortWWN

Each command gives the same results as shown at top and trying to use the variables that are referenced results in no output... It's like PowerShell is ignoring all the other commands except Get-IntelFCoEPorts. Is this a problem with the code I'm using or is it likely a problem with the code behind the module?

My goal in working with this module is to get the PortWWN Numbers into an array or object that I can reference and use to loop through when I need to remove them.

I asked the developer for an updated version of his module, but the new version produced the same results. I want to make sure my code is correct before I badger him anymore.

UPDATE: I tried outputting to a file with no luck. The file is empty. I also tried starting and stopping a transcript like so:

C:\> $ErrorActionPreference="SilentlyContinue"
PS C:\> Stop-Transcript | out-null
PS C:\> $ErrorActionPreference = "Continue"
PS C:\> Start-Transcript -path C:\Users\Administrator\Desktop\output.txt -append
Transcript started, output file is C:\Users\Administrator\Desktop\output.txt
PS C:\> Get-IntelFCoEPorts -HbaIndex 0
    Index   NodeWWN                         PortWWN                         FCID

-----   -------                         -------                         ----

 0      10:00:A0:36:9F:0B:3E:E9         20:00:A0:36:9F:0B:3E:E9                     0x4A0680

 1      20:A8:00:0D:EC:96:EA:01         00:FC:0E:00:A8:00:80:00                 0x36A00120

 ...

 93*    10:00:A0:36:9F:0B:3E:E9         20:3E:A0:36:9F:0B:3E:E9                 0x4A0764

 94     20:A8:00:0D:EC:96:EA:01         00:FC:0E:00:A8:00:80:00                 0x36A03F20

* - Virtual Ports.
PS C:\> Stop-Transcript
Transcript stopped, output file is C:\Users\Administrator\Desktop\output.txt

The output was as so:

PS C:\> Stop-Transcript
Transcript started, output file is C:\Users\Administrator\Desktop\output.txt
PS C:\> Get-IntelFCoEPorts -HbaIndex 0
Was it helpful?

Solution

It looks like the developer is probably formatting their own output. Either that or they are using Write-Host. I suspect the former but in either case the prescribed way to do what they want is to output objects without running them through Format-* or Write-Host. If they want to have a nice default formatted display, then they need to create a format file .ps1xml and use Update-FormatData or use the module's FormatsToProcess field in the .psd1 file.

OTHER TIPS

Since the cmdlet doesn't return any value as you proved with the "$a is null" comment, I believe they're using Write-Host to output the results. If they used Format-Table before outputting results you would have recieved an array containing a FormatStartData and other formatdata objects.

For you to be able to save and pipe results they need to use Write-Output if script cmdlet or WriteObject(I think it is) if they're using binary cmdlet(.dll module). To sum it up: they should update their module.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top