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
|
|
0
|
|
|
|
Reply
|
Utf
|
6/23/2010 3:17:04 AM |
|
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
__________
"Paul B. (USAF)" wrote:
> 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
|
|
0
|
|
|
|
Reply
|
Utf
|
6/23/2010 11:52:55 AM
|
|
|
1 Replies
775 Views
(page loaded in 0.494 seconds)
Similiar Articles: Error: $customObjectI 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 ... import-pssession error - microsoft.public.windows.powershell ...microsoft.public.windows.powershell - page 3 Error: $customObject | format-table Utf 1 589 I see this problem all over but have tried ... Bottom line, I am creating a ... microsoft.public.windows.powershell - page 3Error: $customObject | format-table Utf 1 591 I see this problem all over but have tried every proposed solution but nothing provided works for me. How to read "noteproperty" ? - microsoft.public.windows ...Hash Table not returning properly in Function - microsoft.public ... How to read ... How to format Windows PowerShell output - Microsoft Corporation ..... the formatting ... Convertto-HTML appending more information - microsoft.public ...How about building up a custom object for each server, then ... what you really want to do is pull just the table ... so in your example you would do: foreach server ... Error: $customObject | format-table - microsoft.public.windows ...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 ... Error: $customObject | format-table - microsoft.public.windows ...The old Google Groups will be going away soon, but your browser is incompatible with the new version. Format-Table - Powershell CmdLet - Network Monitor software and ...Format-Table - Powershell CmdLet. Microsoft Windows PowerShell is a command-line shell and scripting tool based on the Microsoft .NET Framework. Custom Objects - CRM, the cloud, and the social enterprise ...Custom objects are custom database tables that ... For example, a custom object labeled “Issue” in the Salesforce ... not have a specified or default value, an error ... Windows PowerShell Format-table ft | Output Formatting CmdletWindows PowerShell Format-Table Cmdlet Windows PowerShell Scripting - Format-Table (ft) ... Performance LTD All rights reserved. Please report a broken link, or an error to ... 7/29/2012 10:00:50 PM
|