Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Error: $customObject | format-table

41 views
Skip to first unread message

Paul B. (USAF)

unread,
Jun 22, 2010, 11:17:04 PM6/22/10
to
I see this problem all over but have tried every proposed solution but
nothing provided works for me. Bottom line, I am creating a custom object
via .csv import but when trying to format-(to anything), I get the error
shown below the script. Sorry if this is a dead-horse. BTW...using v2 on
W2K8R2. Everything works except the last line. If the "ft" is not there,
the results are listed in "format-list" by default...but I want a table
format. (Script below is word-wrapped of course".

###Beginning of script
param([SWITCH]$help, [STRING]$ouDN, [STRING]$file)


###################################################### Functions
#####################################################
Function get_help()
{
$helpText=@"
"@
write-host $helpText -ForegroundColor Yellow
exit
}

###################################################### Validate parameters
and combinations
#####################################################
if ($help -or $param.count -eq 0) {get_help}

###################################################### Functions
###################################################### Function to verify
the passed OU exists
#####################################################
function verify_OU
{
$ErrorActionPreference = "SilentlyContinue"

$ouExist = [ADSI]::Exists("LDAP://" + $ouDN)
while ($ouExist -ne $TRUE)
{
Write-Warning "Specified OU does not exist: $ouPath"
$ouDN = Read-Host "Retype target OU distinguishedName path"
$ouExist = [ADSI]::Exists("LDAP://" + $ouDN)
set-variable -name ouDN -value "$ouDN" -scope 1
}
}

###################################################### Function to collect
computer object information from AD
#####################################################
function get_computerObjectInfo
{
#set variable values to default of NULL
$computerDnsHostName = "NULL"
$computerOS = "NULL"
$computerLLTS = "NULL"

#collect computer dnsHostName
if ($computer.dnshostname -ne $null)
{
$computerDnsHostName = $computer.dnshostname
}
#collect computer operatingSystem
if ($computer.operatingsystem -ne $null)
{
$computerOS = $computer.operatingsystem
}
#collect computer lastLogonTimeStamp
if ($computer.lastLogonTimeStamp -ne $null)
{
$computerLLTS = Get-Date -Date
([DateTime]::FromFileTime([Int64]::Parse($computer.lastLogonTimeStamp)))`
-Format MM/dd/yyyy
}
$SCRIPT:adResults =
"$computerName,$computerDnsHostName,$computerOS,$computerLLTS"
}

###################################################### Function to ping
computer
#####################################################
function ping_computer
{
PROCESS
{
trap { continue }
$pingStatus = $ping.send($computerName).status
if ($pingStatus -eq "Success")
{
$pingResponse = ("Online")
}
else
{
$pingResponse = ("Offline")
}
}
END
{
$SCRIPT:pingResults = $pingResponse
}
}

###################################################### Verifty script
execution pre-requisits
#####################################################
verify_ou

Import-Module activedirectory

###################################################### Create .csv files
#####################################################$csvPath = Get-Location
$csvFile = $csvPath.Path + "\computerInfo.csv"

New-Item $csvFile -type file -Force
Set-Content $csvFile
"name,dnsHostName,operatingSystem,lastLogonTimeStamp,pingStatus"
#Clear-Host

#####################################################
# Main
#####################################################
$ping = new-object System.Net.NetworkInformation.Ping

$computers = get-adcomputer -filter * -searchBase $ouDN -resultpagesize 1000
-searchScope subtree -Properties
lastLogonTimeStamp,name,operatingsystem,dnshostname

foreach ($computer in $computers)
{
$computerName = $computer.name
get_computerObjectInfo
ping_computer
"$adResults,$pingResults"
Add-Content $csvFile "$adResults,$pingResults"
}

$colComputers = @()

$colComputerInput = Import-Csv -Path $csvFile

foreach ($objComputer in $colComputerInput)
{
$objComputerInfo = New-Object System.Object
$objComputerInfo | Add-Member -MemberType NoteProperty -name
computername -value $objComputer.name
$objComputerInfo | Add-Member -MemberType NoteProperty -name dnsHostName
-value $objComputer.dnsHostName
$objComputerInfo | Add-Member -MemberType NoteProperty -name
operatingSystem -value $objComputer.operatingSystem
$objComputerInfo | Add-Member -MemberType NoteProperty -name
lastLogonTimeStamp -value $objComputer.lastLogonTimeStamp
$objComputerInfo | Add-Member -MemberType NoteProperty -name pingStatus
-value $objComputer.pingStatus
$colComputers += $objComputerInfo
}

$colComputers | ft ###<---This is causing the below error
###End of script


##########
out-linoutput : 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 the default formatting.

+ CategoryInfo : InvalidData: (:) [out-lineoutput], InvalidOperationException
+ FullyQualifiedErrorId :
ConsoleLineOutputOutOfSequencePacket,Microsoft.PowerShell.Commands.OutLineOutputCommand
##########

Help...why? and how can easily resolve. Thanks.

Paul

Paul B. (USAF)

unread,
Jun 23, 2010, 7:52:55 AM6/23/10
to
UPDATE: This error only appears if I write to the file first. I commented
out all the logic to create/write to "computerInfo.csv" and just left the
script to read from the data that was already in there. Voila...out put was
returned as desired using format-*.

Is it possible I have a streaming or "file-state" conflict where the file
must be explicitly closed prior to reading the contents back in? If so, how
do I explicitly close? Thanks!

Paul

__________

0 new messages