0

I am developing my first PowerShell binary module using C#. The cmdlet is basic, it will connect to our production servers and list the status of the services.

I would like to output the MachineName property along with the default Status, Name and DisplayName properties. (I can do Get-AppService | select MachineName,Status,Name to accomplish this.)

I have read about using a .format.ps1xml file, which I have written:

<?xml version="1.0" encoding="utf-8" ?>
<Configuration>
  <ViewDefinitions>
    <View>
      <Name>service</Name>
      <ViewSelectedBy>
        <TypeName>System.ServiceProcess.ServiceController</TypeName>
      </ViewSelectedBy>
      <TableControl>
        <TableHeaders>
          <TableColumnHeader>
            <Width>20</Width>
          </TableColumnHeader>
          <TableColumnHeader>
            <Width>8</Width>
          </TableColumnHeader>
          <TableColumnHeader>
            <Width>18</Width>
          </TableColumnHeader>
          <TableColumnHeader>
            <Width>38</Width>
          </TableColumnHeader>
        </TableHeaders>
        <TableRowEntries>
          <TableRowEntry>
            <TableColumnItems>
              <TableColumnItem>
                <PropertyName>MachineName</PropertyName>
              </TableColumnItem>
              <TableColumnItem>
                <PropertyName>Status</PropertyName>
              </TableColumnItem>
              <TableColumnItem>
                <PropertyName>Name</PropertyName>
              </TableColumnItem>
              <TableColumnItem>
                <PropertyName>DisplayName</PropertyName>
              </TableColumnItem>
            </TableColumnItems>
          </TableRowEntry>
        </TableRowEntries>
      </TableControl>
    </View>
  </ViewDefinitions>
</Configuration>

I don't know where to put this so that it applies to only my cmdlet. Right now I am using Import-Module to pull in my DLL from Visual Studio's bin\Debug folder.

1 Answer 1

1

You can use Update-FormatData and point it to your .format.ps1xml file. Link to TechNet

Update: In this answer he explains how to run a script when your c# module is loaded.

Sign up to request clarification or add additional context in comments.

1 Comment

Legend, that's exactly what I needed to know. Thank you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.