0

If I have two rows in a CSV file like below (but 200 entries or so).

$Username        $Phone
Example.A        911
Example.B        123

How would I get PowerShell to take each row and enter it into a command?

I know how to do it if the phonenumber (Using a for each loop) is the same for everyone, but if everyone has a different phonenumber, how would I go about it then? Can I use a for each loop fetching two rows instead of 1 row from the csv file?

Foreach $Username, $Phonenumber in $CSV
Set-ADuser -identity $Username -PhoneNumber $Phonenumber

Above is how I would like it to be, but that doesn't work.

1 Answer 1

1

To do what you're attempting, you just need a couple of slight modifications as follows:

$CSV = Import-Csv -Delimiter "," -Path "\\your\file\path" 
foreach ($user in $CSV) {
    Set-ADuser -identity $user.Username -PhoneNumber $user.Phonenumber
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, exactly what I was looking for.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.