Q. How can I read computer names from a text file in PowerShell?Q. How can I read computer names from a text file in PowerShell?
To read computer names from a text file, you use the Get-Content cmdlet, which will expect to see one computer name per line.
Don Jones
July 26, 2010
1 Min Read
Q. How can I read computer names from a text file in PowerShell?
A. To read computer names from a text file, you use the Get-Content cmdlet, which will expect to see one computer name per line. That enables usage like this:
Get-EventLog -Log Security -Newest 20 -ComputerName (gc names.txt)
Note that gc is an alias for Get-Content. The parentheses force that command to execute first, and return its output to the -computerName parameter.
Do you have a Windows PowerShell question? Find more PowerShell FAQs, articles, and other resources at windowsitpro.com/go/DonJonesPowerShell.
About the Author
Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.
You May Also Like