Let's say I have an CSV sheet, first line with the usernames and the second with the emailadresses.
Example:
Username Emailadress
jhornet jhornet@mail.com
How can I import this info to the AD within a safe and nice way, maybe with a check in it?
This is what I have till now (without CSV):
Import-Module activedirectory
$company = "International"
$username = Get-Content c:\users.txt
$emailadress = Get-Content c:\mail.txt
foreach($user in $username)
{
Set-ADuser -Identity $user -Company $company
}
#second
foreach($emailadress in $username)
{
Set-ADuser -Identity $user -EmailAddress $emailadress
}
Still learning a lot with powershell, some things are just hard to understand and better to see :)
Thanks in advance!
Gr,
JPA
I'm going out on a shaky limb here because I've never used the AD commands before but it should go something like this:
Import-Module activedirectory
$company = "International"
$users = Import-Csv c:\user.csv
$users # dumps users to allow visual inspection
read-host "press Enter to continue or Ctrl+C to abort"
$users | Foreach {Set-ADUser -Identity $_.username -Company $company -whatif}
$users | Foreach {Set-ADUser -Identity $_.username -EmailAddress $_.emailaddress -whatif}
Remove the -WhatIf
parameter when you think the commands are going to work correctly.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.