Subscribe
Accepted Solution

format-table Issue

I beleive that I am experiancing a known issue with piping data to the format-table function.  When I run the below script it errors out on the format table.  The connect-nacontroller executes and then this error is given on the get-nacifsshare line.  Does anyone have an alternative method for me to execute this and get the data formated as a table?

out-lineoutput : The object of type "Microsoft.PowerShell.Commands.Internal.Format.FormatStartData" is not valid or not in the  correct sequence. This is likely caused by a user-specified "format-table" command which is conflicting with the default form

atting.

    + CategoryInfo          : InvalidData: (Smiley Happy [out-lineoutput], InvalidOperationException

    + FullyQualifiedErrorId : ConsoleLineOutputOutOfSequencePacket,Microsoft.PowerShell.Commands.OutLineOutputCommand

$xmldata = [xml](get-content c:\scripts\data_files\netapps.xml)

$filers = $xmldata.netapps.filer | Where-Object {$_.site -match "mcr" -and $_.nstor -match "n"} | select name

foreach ($a in $filers)
{
     Connect-NaController $a.NAME
     Get-NaCifsShare | select $a.name, mountpoint, sharename | Format-Table
}

Re: format-table Issue

Hi!

Your issue is stemming from the Select-Object command inside the for-loop.  $a.name is not a property of the object returned by Get-NaCifsShare, so Powershell is getting confused.  You can use a script parameter to achieve the result you are looking for:

Get-NaCifsShare | select @{Label="Name";Expression={$a.name}}, mountpoint, sharename | Format-Table

Hope that helps!

-Steven

Re: format-table Issue

There is also the issue that the Connect-NaController invocation is writing a controller object to the pipeline, while Get-NaCifsShare is writing share objects to the pipeline.  Format-Table doesn't know how to render a table using two different object types.  Just assign the controller result to a variable to prevent that.  This simple example works for me:

PS C:\> $filers = @("dunn", "benson")


PS C:\> foreach ($a in $filers) { $c = Connect-NaController $a; Get-NaCifsShare | select @{Label="Name";Expression={$c.Name}}, mountpoint, sharename | ft -Auto }

Name MountPoint          ShareName
---- ----------          ---------
dunn /etc                ETC$
dunn /                   C$
dunn /vol/clinton_backup clinton_backup
dunn /vol/vol2           test
dunn /vol/vol2           test2
dunn /vol/vol0/home      HOME
dunn /vol/vol1           share1
dunn /vol/vol2           share2
dunn /vol/ben_test       ben_test
dunn /vol/ben_test2      ben_test2

Name   MountPoint     ShareName
----   ----------     ---------
benson /etc           ETC$
benson /vol/vol0/home HOME
benson /              C$

Re: format-table Issue

Fantastic!  I thought Connect-NaController was somehow included and that's what the formater was choking on. Thanks for the help.

Here is the final code and a sample of the XML file is attached.  Not a very complicated script but I think the use of XML file and being able to format the data as a table makes this for a starting foundation for more complicated reports.

$xmldata = [xml](get-content c:\scripts\data_files\netapps.xml)
$filers = $xmldata.netapps.filer | Where-Object {$_.site -match "mcr" -and $_.nstor -match "n"} | select name
foreach ($a in $filers)
{
     $c = Connect-NaController $a.NAME
     Get-NaCifsShare | Select-Object @{Label="Name";Expression={$a.name}}, mountpoint, sharename | Format-Table
}