An empty pipe element is not allowed.

$machines=Get-Content "D:\Scripts\McAfeeVersion\ComputerList.txt"   

foreach ($machine in $machines)
{
     if(Test-Connection $machine -q -count 1)
     {

          Write-Host "Querying $machine for software" -fore green
          Get-WmiObject win32_product -filter 'Name like "McAfee Agent%"' -computer $machine |
           
          Select-Object __SERVER, Name, Version

     }else

     {

          Write-Host "No response from $machine" -fore red
     }

     
} | Export-Csv  "D:\Scripts\McAfeeVersion\output_data.txt"  -NoTypeInformation

Open in new window


The code runs but there in no output or appending.

The line that is giving me problems is } | Export-Csv
erwin_mirandaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

QlemoBatchelor, Developer and EE Topic AdvisorCommented:
The foreach statement is not expected to deliver any output to a pipe.  That is different from using foreach-object, which is deigned to consume and provide pipeline data.
You can either switch to using the latter:
$machines | % {
  $machine = $_
  # remainder of code
} | Export-CSV ...

Open in new window

or you make the statement part of a subexpression:
$(foreach ($machine in $machines)
{
# ...
})| Export-Csv ...

Open in new window

0
erwin_mirandaAuthor Commented:
So you are saying my new ps1 will look like this

$machines=Get-Content "D:\Scripts\McAfeeVersion\ComputerList.txt"
$ (foreach ($machine in $machines){
     if(Test-Connection $machine -q -count 1){
          Write-Host "Querying $machine for software" -fore green
          Get-WmiObject win32_product -filter 'Name like "McAfee Agent%"' -computer $machine |
            Select-Object __SERVER, Name, Version
     }else{
          Write-Host "No response from $machine" -fore red
     }
} | Export-Csv D:\Scripts\McAfeeVersion\output_data.txt -NoTypeInfo
0
erwin_mirandaAuthor Commented:
Missing closing ')' in expression.
Unexpected token 'in' in expression or statement
I get this error in ($machine in $machines)
0
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

QlemoBatchelor, Developer and EE Topic AdvisorCommented:
$machines=Get-Content "D:\Scripts\McAfeeVersion\ComputerList.txt"
$(foreach ($machine in $machines){
     if(Test-Connection $machine -q -count 1){
          Write-Host "Querying $machine for software" -fore green
          Get-WmiObject win32_product -filter 'Name like "McAfee Agent%"' -computer $machine | 
            Select-Object __SERVER, Name, Version
     }else{
          Write-Host "No response from $machine" -fore red
     }
}) | Export-Csv D:\Scripts\McAfeeVersion\output_data.txt -NoTypeInfo

Open in new window

0
erwin_mirandaAuthor Commented:
Okay...cool it woks what about the no response from the ones that are not there...this was the output. on the powershell console

Querying Computer1 for software
Querying Computer2 for software
Querying Computer3 for software
Querying Computer4 for software
No response from Computer5
No response from Computer6
No response from Computer7

and this was the output on the txt

"__SERVER","Name","Version"
"Computer1","McAfee Agent","4.8.2003"
"Computer2","McAfee Agent","4.8.2003"
"Computer3","McAfee Agent","4.8.2003"
"Computer4","McAfee Agent","4.8.2003"

as you can see there are no response from Computer5,6,7 on the output txt
0
Raheman M. AbdulSenior Infrastructure Support Analyst & Systems DeveloperCommented:
Computers 5,6 and 7 could not be connected since they might be offline. Make sure they are powered ON and are on network.
0
erwin_mirandaAuthor Commented:
okay
0
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
The script is intended to work that way. "No response" is shown only in the console window.
It could be changed to generate a special record, of course.
$machines=Get-Content "D:\Scripts\McAfeeVersion\ComputerList.txt"
$(foreach ($machine in $machines){
     if(Test-Connection $machine -q -count 1){
          Write-Host "Querying $machine for software" -fore green
          Get-WmiObject win32_product -filter 'Name like "McAfee Agent%"' -computer $machine | 
            Select-Object __SERVER, Name, Version
     }else{
          Write-Host "No response from $machine" -fore red
          New-Object PsObject -Property @{ "__Server" = $machine; Name = ""; Version = "" }
     }
}) | Export-Csv D:\Scripts\McAfeeVersion\output_data.txt -NoTypeInfo

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
erwin_mirandaAuthor Commented:
You are the man Qlemo...:-)
0
erwin_mirandaAuthor Commented:
$machines=Get-Content "D:\Scripts\McAfeeVersion\ComputerList.txt"
$(foreach ($machine in $machines){
     if(Test-Connection $machine -q -count 1){
          Write-Host "Querying $machine for software" -fore green
          Get-WmiObject win32_product -filter 'Name like "McAfee Agent%"' -computer $machine |
            Select-Object _SERVER, Name, Version
     }else{
          Write-Host "No response from $machine" -fore red
          New-Object PsObject -Property @{ "_Server" = $machine; Name = ""; Version = "" }
     }
}) | Export-Csv D:\Scripts\McAfeeVersion\output_data.txt -NoTypeInfo

there is an issue...the green information is not displaying the machine name only the red
,"McAfee Agent","4.8.2003"
,"McAfee Agent","4.8.2003"
,"McAfee Agent","4.8.2003"
"N007S07HC","",""
0
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
The property containing the machine name is __Server, not _Server. My code is correctly using two underscores.
0
erwin_mirandaAuthor Commented:
oh okay...just saying cause I copied verbatim from code you posted and after I run it again and then again..it stops writing the green output...but I will take your word sir, thank you very much for helping me.
v.r
E
0
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
You can see that yourself. Your code in http:#a40821629 differs from my code in http:#a40815867 - and I checked the question history to make sure I did not edit the comment after posting it.
0
erwin_mirandaAuthor Commented:
Thank you sir....
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.