Starting Code Block to Access Many Servers in Powershell

I always start with this block of code when I need to perform a task on multiple servers. This code snippet reads a list of servers from a .csv file into memory and then cycles through each server to run a task.

Here is an example ServerList.csv file…

When the above file is loaded into memory, I will have a collection of objects. Each object has the following properties…


In the “Selected” column (the first column), I place an “x” to indicate that server is selected. In the above .csv file I have six servers selected as indicated on lines 17 to 22.

If you look at the code below, I loop through all of the $Server objects and only act on those that have been selected.

In the example below. I write out the properties of the selected servers.

Here are the results when the above code is run…


This entry was posted in PowerShell. Bookmark the permalink.