BikeBoy
 New Member Posts:25

 |
| 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 } |
|
|
|
|
RiffyRiot
 Basic Member Posts:135

 |
| 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 |
|
|
PoSherLife
 Basic Member Posts:364

 |
| 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 |
|
|
BikeBoy
 New Member Posts:25

 |
| 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 |
|
|
|
|
RiffyRiot
 Basic Member Posts:135

 |
| 04 Feb 2011 12:57 PM |
|
Yep, you're right... My bad :-) |
|
| Riffy |
|
|