Output that is written to the standard output stream will be written to the machine output file. If errors are detected by the Security Controls script engine, detailed error messages will be written to the machine error file.

We recommend that you explicitly format the output as you would like it to appear in the output file. If you do not explicitly format the output, the default formatter will be used. This will limit the fields that are output and the way in which they are presented.

It is particularly important to format output for scripts that are using PowerShell remoting. The default behavior for remote scripts is to serialize the script output objects on the target machine and deserialize then on the console. The deserialized objects are snapshots that have properties but no methods. You may get errors or unexpected results unless you explicitly format the output as strings.

There are several ways to format your output. Here are some of them.

  • Out-String: Outputs a series of strings
  • Format-List: Formats the output as a list of properties with each property on a new line
  • Format-Table: Formats the object as a table
  • Format-Wide: Formats objects as a wide table that displays only one property of each object
  • Select-Object: Select the properties you want to output and optionally change the property names. This allows you fine control over what is output.
  • Export-CSV: Save the output as a CSV file. You can output to a temporary file, then use Get Content to write it to the standard output.

The following example retrieves a list of services, and then creates CSV output of the computer name, status, service name, and display name.

$fn = [io.path]::GetTempFileName()

Get-Service -ComputerName "$ST_ComputerName" | select-object

@{Name="ComputerName"; Expression={$ST_ComputerName}}, Status, Name,

DisplayName | export-csv "$fn" -notype

get-content $fn

remove-item $fn