How to iterate through "pairs" of user and computer variables in PowerShell?

I've got a PowerShell deployment script that is meant to automate the spinning up of a domain environment. I have 5 user accounts and 5 machines "pairs" like so:

Machines: DT01 DT02 DT03 DT04 DT05

User accounts: student1 student2 student3 student4 student5

student1 is the primary user of DT01, student2 is the primary user of DT02, and so on.

I have a snippet of code that runs each machine through a series of commands like so:

invoke-command -computername DT01{
do this
do that
do another thing
net localgroup "Remote Desktop Users" "DOMAIN\$using:student1"
do another thing
icacls "c:\somefolder" /grant DOMAIN\"$using:student1:w

Then I'd like this process to go through the next pair, so...

invoke-command -computername DT02{
do this
do that
do another thing
net localgroup "Remote Desktop Users" "DOMAIN\$using:student2"
do another thing
icacls "c:\somefolder" /grant DOMAIN\"$using:student2":w

....and eventually go through ALL the pairs.

I'm not sure how to write the array portion to get these students and PCs paired with each other and then iterate through the deployment commands.

Help please?

I tried Googling a lot, and chatgpt :-)



Comments

Popular posts from this blog

Today Walkin 14th-Sept

Spring Elasticsearch Operations

Hibernate Search - Elasticsearch with JSON manipulation