header1   header
header
header Register : : Login header
header
connector   connector
menuleft menuright
submenu   submenu
left
An empty pipe element is not allowed when writing to an output file
Last Post 04 Feb 2011 12:57 PM by RiffyRiot. 4 Replies.
Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages Not Resolved
BikeBoyUser is Offline
New Member
New Member
Posts:25
Avatar

--
31 Jan 2011 02:31 PM
    Ok, what I want is to feed the script a computer list, then check path for specific file existance on each machine, and write results to Output.txt

    The following script is erroring out when I try to pipe out empty $i when path does not exist.
    An empty pipe element is not allowed

    I can write to command window with write-host command, but can't pipe out to Out-File Output.txt
    Any suggestions greatly appreciated

    ## script here
    $colItems = Get-Content -Path D:\Computers.txt
    foreach($i in $colItems)

    { if (Test-Path "\\$i\Blah\Blah\Blah\*" -include ExchangeInfo*.exe) 
       {"$i has the file ExchangeInfo*.exe"} | Out-File Output.txt 
          else
    {write-host "$i DOES NOT HAVE the file ExchangeInfo*.exe"} | Out-File Output.txt }
    RiffyRiotUser is Offline
    Basic Member
    Basic Member
    Posts:135
    Avatar

    --
    31 Jan 2011 06:46 PM
    Here's something I use, probably more than you need.

    [int]$installed=0
    [int]$notinstalled=0
    [int]$notonline=0
    [int]$mytotal=0
    [array]$myresults=@()

    d:\computers.txt | %{if (test-connection $_ -count 1 -q)
    {
    if (test-path "\\$_\c$\Program Files\Microsoft Office\Office12\EXCEL.EXE")
    {
    $myresults+= "$_ : Office 2007 Installed"
    $installed++
    }
    else
    {
    $myresult+= "$_ : Office 2007 not Installed"
    $notinstalled++
    }
    }
    else
    {
    $myresults+= "$_ : Not Online"
    $notonline++
    }
    $mytotal++
    }

    write-host Installed $installed `nNot Installed $notinstalled `nOffline $notonline `nTotal $mytotal
    $myresults | out-file d:\test3.txt
    Riffy
    PoSherLifeUser is Offline
    Basic Member
    Basic Member
    Posts:364
    Avatar

    --
    31 Jan 2011 06:54 PM
    First off: Write-Host only does just that. Write to the host. It will not send anything through the pipe. Instead, use Tee-Object to write to a file and output to the console. Tee-Object is one way out of several, for simple operations like this, it should work just fine.

    Second: Watch placement of brackets {}. Your If and Else statements won't pipe through either. the pipe must be done inside the statment.

    $colItems = Get-Content -Path D:\Computers.txt

    foreach($i in $colItems) {
    if (Test-Path "\\$i\Blah\Blah\Blah\*" -include ExchangeInfo*.exe) {
    "$i has the file ExchangeInfo*.exe" | Tee-Obect Output.txt
    }
    else {
    "$i DOES NOT HAVE the file ExchangeInfo*.exe" | Tee-Obect Output.txt
    }
    }
    When at first you don't succeed Step-Into

    http://theposherlife.blogspot.com
    http://www.jandctravels.com

    BikeBoyUser is Offline
    New Member
    New Member
    Posts:25
    Avatar

    --
    04 Feb 2011 07:22 AM
    Thanks guys,

    DiffyRiot - looks like you need Get-Content -Path d:\computers.txt Otherwise I got an error: "Cannot execute a document in the middle of a pipeline"
    But it works, thanks


    Cruisader03 - tee-object instead of Out-File is nice, thanks
    RiffyRiotUser is Offline
    Basic Member
    Basic Member
    Posts:135
    Avatar

    --
    04 Feb 2011 12:57 PM
    Yep, you're right... My bad :-)
    Riffy
    You are not authorized to post a reply.


    Active Forums 4.3
    right
    footer   footer
    footer Sponsored by Quest Software • SAPIEN Technologies • Compellent • Microsoft Windows Server 2008 R2 footer
    footer   footer