computer screen showing blue sky and ocean

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?

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.

 

Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish