T
T
the Alekhnovich2021-08-18 17:53:04
PowerShell
the Alekhnovich, 2021-08-18 17:53:04

How to populate the Division field based on the SAMAccountName from the list?

There is a list (example below) containing the SAMAccountName of the users and a value that needs to be entered in the Division field in Active Directory. I don't know how to correctly create a loop that will match the SAMAccountName from the list with the desired user in Active Directory and enter the value in the Division field

SAMAccountName Group
derek.aik OPS
sandy.bruks BON
alex.gone GET
sten.ports OPS
abby.kaily ROAD

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
MaxKozlov, 2021-08-18
@Uladz

There are two main types of object loops in ps:

#классический цикл
foreach ($obj in $list) {
  # сделать что-нибудь с переменной $obj
   Set-something -name $obj.name -value $obj.value
}

#цикл с использованием  pipeline
$list | foreach-object {
  # сделать что-нибудь с переменной $_
   Set-something -name $_.name -value $_.value
}

Choose what you like and substitute your installation commands.
In combination with import from csv, the second option will be shorter

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question