SOLVED

Script from 2 csv - URL list and Folder list

Brass Contributor

Hello there!

I have 2 csv files. 

one has 82 rows with unique site address. like below

rjack_0-1627678486711.png

 

 

the other has 1314ish folder names with path. like below

rjack_1-1627678486799.png

 

Previously, I used to create 1000s of folder per site per script and now I have to create the same set of folders on 82 sites. so was trying to improvise the script by importing a csv and added 'for each'. the script works but skips all sites and goes to the last site in the list and creates the 1314 folders with correct permission. 

 

below is what I added to the script trying to trigger the loop.  Please help!

I have attached the full script as well. 

 

$csvs= Import-CSV $csvfilepathsite
foreach ($row in $csvs)
{
$url = $row.siteurl
$GroupNames=$row.GroupNames

 

2 Replies
best response confirmed by rjack (Brass Contributor)
Solution

I took a quick sneak peek at your code and I don't think it will work.

Your code is structure like this

 

Foreach{

  Variable

     Function DoSomething{

         Function DoSomethingMore{

        }

      }

}

This is not correct,

- Don't place the Function inside the Foreach, Foreach should be inside the function.

- If you need the Function to respone to a value, you need to set parameter to the function, something like DoSomething -FolderName $URL, and define the FolderName in the Function.

 

If the function are not needed, just remove them and keep the code of the function inside the foreach.

 

also you can use ISE and debug your code and you will see that the function block is not actually executed.

 

-------------------

Hope this help, if this answer help, please mark this answer as Best Reponse.

 

@farismalaeb Thank you for pointing the issue. moved the foreach into the function and its working like clockwork. 

 

Only problem is intermittently I get 429 but what can we do if server stops responding. or can we add something like 'wait until response' (if it exists)? 

 

warning! I have zero knowledge in coding and scripts. 

1 best response

Accepted Solutions
best response confirmed by rjack (Brass Contributor)
Solution

I took a quick sneak peek at your code and I don't think it will work.

Your code is structure like this

 

Foreach{

  Variable

     Function DoSomething{

         Function DoSomethingMore{

        }

      }

}

This is not correct,

- Don't place the Function inside the Foreach, Foreach should be inside the function.

- If you need the Function to respone to a value, you need to set parameter to the function, something like DoSomething -FolderName $URL, and define the FolderName in the Function.

 

If the function are not needed, just remove them and keep the code of the function inside the foreach.

 

also you can use ISE and debug your code and you will see that the function block is not actually executed.

 

-------------------

Hope this help, if this answer help, please mark this answer as Best Reponse.

 

View solution in original post