StevensNet.com

...Because someone's gotta tell the story...

Blogs

To return to the main Blog List, click Full Blog Listing.

Tags

PowerShell

Sample PS to Read a fle and execute a command

Friday, April 3, 2015 in Powershell (Views: 1244)
So a simple blog, friend asked for it, so why not...

All you need to do is run a command against a list of systems in a text file, like such:
CLIENT1
CLIENT2
CLIENT3

To do this, simply run this PowerShell and add any commands within the {} brackets. Say, just to ping these systems, I'll use a local echo.

$FileName="c:\temp\text.txt"
foreach ($SysName in get-content $FileName){
Write-Host "ping -t "$SysName
}


Your output would be:
ping -t CLIENT1
ping -t CLIENT2
ping -t CLIENT3

Happy scripting...

 

Related Blogs You May Be Interested In:


To leave a comment, please log in and/or register.