Question

I am writing my first custom CMDLet in powershell 2.0. I have encoutered a problem with custom formatting temaplate xml being not used in my cmdlet. Here is my formatting file:

<Configuration>
<ViewDefinitions>
  <View>
    <Name>abc</Name>
    <ViewSelectedBy>
      <TypeName>ExtractServicesCmd.ServiceInfo</TypeName>
    </ViewSelectedBy> 
    <TableControl>
      <TableHeaders>
        <TableColumnHeader>
          <Label>ServiceName</Label>
          <Width>12</Width>
          <Alignment>right</Alignment>
        </TableColumnHeader>      
      </TableHeaders>
      <TableRowEntries>
        <TableRowEntry>
          <TableColumnItems>
            <TableColumnItem>
              <PropertyName>ServiceName</PropertyName>
            </TableColumnItem>           
          </TableColumnItems>
        </TableRowEntry>
      </TableRowEntries>
    </TableControl>
  </View>  
  </ViewDefinitions>
</Configuration>

Everything goes fine, Format is successfully registering (I checked it using Get-FormatData command) with proper type. But when executing my commandlet it still uses default formatting. I even tried to force using my formatter by piping "| Format-Table -View abc" but it says - cannot find view with name abc! What is going on? I tried Get-FormatData and analyzed entries - my ViewDefinition is present there with proper view name!

Thanks for reading.

Was it helpful?

Solution

What does $x.GetType().FullName where $x is an instance of you type return? (Ie. this sounds like PSH is failing to match the type name.)

Note the type name will match the exact type of the object being formatted, or a base type of the object.

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