Solved

Cannot format Output with line continuation

Posted on 2011-09-05
1
1,141 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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

How to sign a powershell script so you can prevent tampering, and only allow users to run authorised Powershell scripts
This article will help you understand what HashTables are and how to use them in PowerShell.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa‚Ķ

791 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