?
Solved

Cannot format Output with line continuation

Posted on 2011-09-05
1
Medium Priority
?
1,217 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 2

Accepted Solution

by:
gazm81 earned 2000 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

Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

Question has a verified solution.

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

This article will help you understand what HashTables are and how to use them in PowerShell.
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

762 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