by Candee at 2013-04-16 08:56:17
I have a script that imports new users from a csv; creates their username, upn; then creates the users & mailboxes.by JeffH at 2013-04-16 10:02:05
I need a way to export the updated information - specifically the displayname, SAM, UPN, and the employeenumber
I’ve tried:$newusers |select name,displayname,email |export-csv "C]
but I can’t seem to get it right.
Any insight is appreciated.
Here is the script I’m using (many thanks to ArtB0514!)Import-Csv $newusers |foreach {
$preferredfirstname = $.preferredfirstname
$lastnamepreferred = $.lastnamepreferred
$SAM = $preferredfirstname.substring(0,1)+$lastnamepreferred
$UPN = $preferredfirstname +"."+$lastnamepreferred+$DNSROOT
$Displayname = $lastnamepreferred +" "+$preferredfirstname
$Email = $UPN
$testemail = get-recipient -identity $email -ErrorAction SilentlyContinue
$user = Get-QADUser -SamAccountName $SAM
if($user -ne $Null) {
"
**************************************************************************
$($User.name) already exists -
THIS USER NEEDS TO BE MANUALLY CREATED
"
} Elseif ($testemail -ne $Null) {
"
**************************************************************************
$($DISPLAYNAME) Email address already exists
THIS MAILBOX NEEDS TO BE MANUALLY CREATED
"
}ELSE{
"
**************************************************************************
Creating a new user account for $($DISPLAYNAME)"
$NewUser = New-qaduser -name $SAM<br> -parentcontainer $OU
-userprincipalname $UPN<br> -samaccountname $SAM
-displayname $displayname<br> -mail $email
-givenname $.preferredfirstname<br> -sn $_.lastnamepreferred
-userPassword $pass<br> -company $_.Company
-department $.department -title $.businesscardtitle -telephonenumber $.telephone<br> -city $_.city -postalcode $_.zip -state $_.state
-streetaddress $.street -manager $.manager<br> -oa @{ipphone=$_.ipphone;mobile=$_.mobile;employeeid=$_.employeeid;employeenumber=$_.employeegui}
start-sleep -s 10
if($_.mailenabled -eq 'true') {
"Creating a mailbox for $($Newuser.name)"
$Newuser |foreach-object {enable-mailbox -identity $newuser.email -database $userdb } `
}Else {
"User does not require Email
"
}#end of mailenabled
}#end of create new user
}
To me this looks like $newusers is the path to a CSV file. Or do you mean to $newuser without the S?by ArtB0514 at 2013-04-16 10:53:48
A couple of other thoughts…by Candee at 2013-04-16 11:31:08
Consider using New-Mailbox because it will create the user account and mailbox in a single command and you won’t need to waste time sleepling.
You might want to create a new variable [such as $CreatedUsers = @()] at the beginning of your script, then add the new user account to it after it has been created [$CreatedUsers += $NewUser] and export the $CreatedUsers array to the csv file.
Thanks!by Candee at 2013-04-16 11:44:07
I tried using "switch" in the script, but can’t get it to work.
This one works the way I want it to, although it’s kludgy.
I will try the new variable.
Thank you! It’s working!by mandy_ADM at 2013-05-01 03:32:22
thats the one i’m looking for.
@candy Could you pls be so kind and post the working script here. Thank you so much
mandy