Solved

Cannot format Output with line continuation

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
powershell add exchange property to a report 12 50
powershell query 2 23
Help needed with Powershell  XML to MySQL 5 38
PowerShell .lastLogonTimestamp off 11 25
Create and license users in Office 365 in bulk based on a CSV file. A step-by-step guide with PowerShell script examples.
This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

785 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