![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Help with foreach-object and passing parameters I'm new to powershell and I'm not quite getting the syntax to pass parameters. I want to ping a list of servers that are listed in a text file, and output the results to html...What I've figured out so far is: import-csv servers.csv | foreach-object -process {get-wmiobject win32_pingstatus -filter "address='www.yahoo.com'" | select-object -property address,statuscode,responsetime} | convertto-html That runs and loops the correct amount of times, and pings the hard-coded www.yahoo.com. How do I replace the www.yahoo.com with the values from my file? Servers.csv contains: Server www.yahoo.com www.google.com www.lycos.com I tried: import-csv servers.txt | foreach-object -process {get-wmiobject win32_pingstatus -filter "address='www.yahoo.com'" | select-object -property address,statuscode,responsetime} But that tried to ping @{Server=www.yahoo.com}, for example. I did search pretty extensively and have suprisingly not found anyone else posting about this same exact question. Any help greatly appreciated!!! |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Help with foreach-object and passing parameters "Xanbar" <darren@hackandchop.com> wrote in message news:1163577149.624753.246340@h54g2000cwb.googlegroups.com... > I'm new to powershell and I'm not quite getting the syntax to pass > parameters. I want to ping a list of servers that are listed in a text > file, and output the results to html...What I've figured out so far is: > > import-csv servers.csv | foreach-object -process {get-wmiobject > win32_pingstatus -filter "address='www.yahoo.com'" | select-object > -property address,statuscode,responsetime} | convertto-html > > That runs and loops the correct amount of times, and pings the > hard-coded www.yahoo.com. How do I replace the www.yahoo.com with the > values from my file? Try this: import-csv servers.csv | foreach {gwmi Win32_PingStatus -filter "Address='$($_.Server)'"} | select address,statuscode,responsetime address statuscode responsetime ------- ---------- ------------ www.yahoo.com 0 37 www.google.com 0 36 www.lycos.com 0 120 -- Keith |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Passing parameters to a PS script | PowerShell | |||
| passing [switch] parameters | PowerShell | |||
| foreach, foreach-object & begin/process/end scriptblock clauses... | PowerShell | |||
| Difference in semantics of for, foreach and foreach-object | PowerShell | |||
| passing parameters to script (ps1) | PowerShell | |||