Solved

Cannot format Output with line continuation

Posted on 2011-09-05
1
1,095 Views
Last Modified: 2012-05-12
I have the following code:

clear

$computers = get-content servers.txt

Get-Date

foreach($i in $computers)
{ 
	write-host $i
	gwmi -query "SELECT Caption,VolumeName,Size,Freespace FROM win32_logicaldisk" -computer $i | 
        Select-Object `
            Caption,`
            VolumeName,`
            @{Name="Size(GB)"; Expression={"{0:N2}" -f ($_.Size/1GB)}},`
            @{Name="Freespace(GB)"; Expression={"{0:N2}" -f ($_.Freespace/1GB)}},`
            @{Name="Percent Free"; Expression={"{0:N2}" -f ($_.Freespace/$_.Size*100)}} |
        Format-Table
	
	Get-Eventlog System -EntryType Error -computerName $i -Newest 25 | Format-List


}

Open in new window


I get this error when I run it:


Tuesday, 06 September, 2011 08:28:03
SERVER NAME
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 th
e default formatting.
    + CategoryInfo          : InvalidData: (:) [out-lineoutput], InvalidOperationException
    + FullyQualifiedErrorId : ConsoleLineOutputOutOfSequencePacket,Microsoft.PowerShell.Commands.OutLineOutputCommand
[PS] F:\PowerShellScripts\SrvScripts>

It worked fine for me until I put in the ` marks for line continuation. I am sure this is simple, but I appreciate the help.
0
Comment
Question by:MarkhamLA1979
1 Comment
 
LVL 2

Accepted Solution

by:
gazm81 earned 500 total points
ID: 36486545
Quirk with the formatting cmdlets
clear

$computers = get-content servers.txt

Get-Date

foreach($i in $computers)
{ 
	write-host $i
	gwmi -query "SELECT Caption,VolumeName,Size,Freespace FROM win32_logicaldisk" -computer $i | 
        Select-Object `
            Caption,`
            VolumeName,`
            @{Name="Size(GB)"; Expression={"{0:N2}" -f ($_.Size/1GB)}},`
            @{Name="Freespace(GB)"; Expression={"{0:N2}" -f ($_.Freespace/1GB)}},`
            @{Name="Percent Free"; Expression={"{0:N2}" -f ($_.Freespace/$_.Size*100)}} |
        Format-Table | out-default
	
	Get-Eventlog System -EntryType Error -computerName $i -Newest 25 | Format-List | out-default


}

Open in new window

0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Join & Write a Comment

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now