Read txt file using powershell to feed a command

John Darby
John Darby used Ask the Experts™
on
Greetings!

I have a command I want to feed a variable from a txt file. The command is...

kerblist get ldap/$variablename

The textfile is named  .\sitedcs.txt

The txt file will have 3-8 entries which are hostnames for the local site DCs.

I remember the FOR loop from the CMD shell days, but am sure there is a better way within native PS.

TIA!
JohnD
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Senior Systems Admin
Top Expert 2010
Commented:
If you turn it into a CSV file by putting in a header line (Like computername or something) you can pipe the info in by using:
import-csv <filename> | foreach {<commands>}

Author

Commented:
Thanks acbrown2010!

Here is your suggestion in txt...

import-csv .\sitedcs.csv | foreach {kerblist get ldap/???}

My question is how I populate the ??? part which should hold the hostname which is derived from the CSV list? There are 3-8 of these values.

Author

Commented:
Thanks!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial