Hi,<\/p>\n
I have a powershell script where i first do a invoke rest method to query an API, and then i convert the results to a data result, to finally create variables for the different values<\/p>\n
$response = Invoke-RestMethod 'https:…<\/p>\n
$response | ConvertTo-Json<\/p>\n
$response.Data.result<\/p>\n
Then the variables creation:<\/p>\n
foreach ($responses in $response )<\/p>\n
{ $task=$response.Data.result.task<\/p>\n
$user=$response.Data.result.user<\/p>\n
$group=$group }<\/p>\n
The variables result is:<\/p>\n
$task $user $group<\/p>\n
task1 user1;user2 group1<\/p>\n
task2 user3 group2<\/p>\n
The goal is for each task to add users as members of Active Directory groups. (ex: add user 1 and user2 to group1 and user 3 to group 2) What would be the appropriate for each loop to have it working as desired?<\/p>\n
Thanks, i am really blocked at the moment<\/p>","upvoteCount":3,"answerCount":5,"datePublished":"2021-08-17T05:45:16.000Z","author":{"@type":"Person","name":"spiceuser-jr5f9","url":"https://community.spiceworks.com/u/spiceuser-jr5f9"},"suggestedAnswer":[{"@type":"Answer","text":"
Hi,<\/p>\n
I have a powershell script where i first do a invoke rest method to query an API, and then i convert the results to a data result, to finally create variables for the different values<\/p>\n
$response = Invoke-RestMethod 'https:…<\/p>\n
$response | ConvertTo-Json<\/p>\n
$response.Data.result<\/p>\n
Then the variables creation:<\/p>\n
foreach ($responses in $response )<\/p>\n
{ $task=$response.Data.result.task<\/p>\n
$user=$response.Data.result.user<\/p>\n
$group=$group }<\/p>\n
The variables result is:<\/p>\n
$task $user $group<\/p>\n
task1 user1;user2 group1<\/p>\n
task2 user3 group2<\/p>\n
The goal is for each task to add users as members of Active Directory groups. (ex: add user 1 and user2 to group1 and user 3 to group 2) What would be the appropriate for each loop to have it working as desired?<\/p>\n
Thanks, i am really blocked at the moment<\/p>","upvoteCount":3,"datePublished":"2021-08-17T05:45:16.000Z","url":"https://community.spiceworks.com/t/for-each-loop/808606/1","author":{"@type":"Person","name":"spiceuser-jr5f9","url":"https://community.spiceworks.com/u/spiceuser-jr5f9"}},{"@type":"Answer","text":"
Welcome<\/p>\n
If you post code, please use the ‘Insert Code’ button. Please and thank you!<\/p>\n