erwin_miranda
asked on
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
The code runs but there in no output or appending.
The line that is giving me problems is } | Export-Csv
ASKER
So you are saying my new ps1 will look like this
$machines=Get-Content "D:\Scripts\McAfeeVersion\ ComputerLi st.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\o utput_data .txt -NoTypeInfo
$machines=Get-Content "D:\Scripts\McAfeeVersion\
$ (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\o
ASKER
Missing closing ')' in expression.
Unexpected token 'in' in expression or statement
I get this error in ($machine in $machines)
Unexpected token 'in' in expression or statement
I get this error in ($machine in $machines)
$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
ASKER
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
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
Computers 5,6 and 7 could not be connected since they might be offline. Make sure they are powered ON and are on network.
ASKER
okay
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
You are the man Qlemo...:-)
ASKER
$machines=Get-Content "D:\Scripts\McAfeeVersion\ ComputerLi st.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\o utput_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","",""
$(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\o
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","",""
The property containing the machine name is __Server, not _Server. My code is correctly using two underscores.
ASKER
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
v.r
E
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.
ASKER
Thank you sir....
You can either switch to using the latter:
Open in new window
or you make the statement part of a subexpression:Open in new window