Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

For example:

Lets say i have 10 servers (Server 1-Server10) and a csv list where i have the servernames and a individual Foldername/Path for each server.

How would i create these Folders on each machine?

a) Open all 10 connections and run a command based on the csv ? b) stepping through 1by1

Please point me to the most effective way

share|improve this question

3 Answers 3

up vote 3 down vote accepted

This is very naive in that there is no error checking/etc., but it does what you want. I'm assuming here that you are using Powershell 2.0 with WinRM.

Assuming you have a CSV setup like this:

server,path
server1,c:\path1
server2,c:\path2
server3,c:\path3

The solution would be like so:

$csvdata = import-csv .\test.csv
foreach ($row in $csvdata) {
    invoke-command $row.server { param($path) mkdir $path } -argumentlist $row.path
}

The only really weird part here is how you get the path passed in. Typically, the script in invoke-command cannot read your local variables. You setup a param for it (called $path) and then put the local variable $row.path into the argument list - this allows the mkdir command on the remote servers to use the $path variable and it sees what was passed in from the CSV file.

share|improve this answer

if your doing something thats wmi based then you can utilize async calls!

share|improve this answer

my answer was completely off base, anyway if you don't have psv2 or don't implement winrm.

$csvdata = import-csv .\test.csv

foreach ($row in $csvdata) {

md  \\$row.server\c$\$row.path 

}

I'm doing this off the top of my head so please test this first!

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.