Assistance updating user attributes in AD

I have about 1500 users i need to modify attributes for, so we can merge them with Office 365. I want to use the powershell to do this. I need assistance creating the proper csv file and help with commands to run in order to update the following:


MailNickName = user@domain.com
proxyAddresses = user@domain.com
UserPrincipalName= user@domain.com


I am not sure I have the proper field names, so feel free to correct.

I would like to experiment with a single sub OU before applying it to all users.
tamray_techAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Will SzymkowskiSenior Solution ArchitectCommented:
I have created a script below to do what you are looking for see below...
Note: Construct the CSV with 3 headings NickName, ProxyAddress and UPN. Have all of your entries below these headings. Also, if you are running this from the EMS you can remove the Import-module and Add-PSSnapin lines.
Import-Module activedirectory
Add-PSSnapin Microsoft.Exchange.Management.Powershell.Admin
$UserSet = Import-Csv "c:\youCSVhere.csv"
foreach ($User in $UserSet) {
$User.NickName
$User.ProxyAddress
$User.UPN
Get-Mailbox -OrganizationalUnit "OU=test,DC=YourDomain,DC=com" | Set-Mailbox -Alias $User.NickName -EmailAddresses $User.ProxyAddress -UserPrincipalName $User.UPN
}

Open in new window


Thanks

Will.
0
tamray_techAuthor Commented:
Do I name the script with a specific extension, or run line by line?
0
tamray_techAuthor Commented:
Is this how the csv file should look:

NickName, ProxyAddress, UPN
user1
user2
user3
0
Introducing the "443 Security Simplified" Podcast

This new podcast puts you inside the minds of leading white-hat hackers and security researchers. Hosts Marc Laliberte and Corey Nachreiner turn complex security concepts into easily understood and actionable insights on the latest cyber security headlines and trends.

Will SzymkowskiSenior Solution ArchitectCommented:
copy and paste the script into a txt file. From there change the file extension from txt to .ps1. That is correct CSV file should have the 3 headings you have illustrated with all of the values you want to update.

The last line of code needs get-mailbox -OrganizationalUnit you will need to specify the path to your testing OU. so you will also need to replace that info with yours as well.
0
tamray_techAuthor Commented:
I get the following error when running the script:

The Windows PowerShell snap-in 'Microsoft.Exchange.Management.Powershell.Admin' is not installed on this machine.
0
Will SzymkowskiSenior Solution ArchitectCommented:
Are you running this command on the Exchange Server using the Exchange Management Shell? If you are you do not need this. Based on the error it appears you are running this from a server does not not have Exchange installed or does not have the Exchange Tools installed either?

You need to have the Exchange Management Tools installed to run this script on a server/workstation other than the actual Exchange server.
0
tamray_techAuthor Commented:
I am running it from a 2010 Exchange server powershell
0
Will SzymkowskiSenior Solution ArchitectCommented:
If you are running it from the Exchange Server you can remove that line from the script. But based on the error message it looks the same as if you were running this command from a workstation/server without Exchange Tools installed.

So it should look like this...
$UserSet = Import-Csv "c:\youCSVhere.csv"
foreach ($User in $UserSet) {
$User.NickName
$User.ProxyAddress
$User.UPN
Get-Mailbox -OrganizationalUnit "OU=test,DC=YourDomain,DC=com" | Set-Mailbox -Alias $User.NickName -EmailAddresses $User.ProxyAddress -UserPrincipalName $User.UPN
} 

Open in new window


Do the following...
- Save the command to a txt file
- rename the file extension from txt to ps1
- Open the EMS
- type: .\scriptname.ps1 (type your script name in replace of what i have got)
0
tamray_techAuthor Commented:
I found the answer:

add-pssnapin Microsoft.Exchange.Management.PowerShell.E2010

However, my needs are different than I first thought. The script errors out with the following:
PS C:\Users\administrator.domain> C:\updateuser.ps1
AWright95
Couldn't find organizational unit "OU=2013,OU=Students,DC=domain,DC=k12,dc=mn, dc=us". Make sure you have typed the name c
orrectly.
At C:\updateuser.ps1:6 char:1
+  <<<< Get-Mailbox -OrganizationalUnit "OU=2013,OU=Students,DC=domain,DC=k12,dc=mn, dc=us" | Set-Mailbox -Alias $User.Nic
kName -EmailAddresses $User.ProxyAddress -UserPrincipalName $User.UPN
    + CategoryInfo          : NotSpecified: (:) [], ManagementObjectNotFoundException
    + FullyQualifiedErrorId : 784C9312

The script info is correct. Properties from the OU are as follows:
OU=2013,OU=Students,DC=domain,DC=k12,DC=mn,DC=us

Another issue is that the logon name field is blank. However the pre 2000 logon name is there. That is the info I need to show up in the user logon field, along with the other 2 updates.
0
Will SzymkowskiSenior Solution ArchitectCommented:
The Logon name should be the UPN (Universal Principal Name user@domain.com). This is part of the CSV file that you need to fill in, to update the entries for each user in Exchange/ActiveDirectory. As for the OU you have the correct syntax OU=test,DC=domain,DC=com. Make sure that you have the correct path for the OU in question.
0
tamray_techAuthor Commented:
OK... It must have been a space in the script that caused the problem. The script now runs without errors, with the user file as is:

NickName,ProxyAddress,UPN
AWright95

However, none of the attributes are updated.
0
Will SzymkowskiSenior Solution ArchitectCommented:
Did you add all of the info in the CSV file? You need to have all of the info in the CSV file. The script reads the CSV file and update each user in Active Directory with the data. If you dont put anything in there nothing will update.
0
tamray_techAuthor Commented:
Maybe I misunderstood your instructions.  I posted what I had in my csv file.

Here it is again:

NickName,ProxyAddress,UPN
AWright95 (single user)
0
Will SzymkowskiSenior Solution ArchitectCommented:
You need to add all of the information to the CSV file that you want updated in Active Directory. See below example...

NickName      ProxyAddress                UPN
User1                 User1@domain.com      User1@domain.com
User2                 User2@domain.com      User2@domain.com
User3                 User3@domain.com      User3@domain.com

ProxyAddress is a secondary address that the user can receive mail on. This does not need to be user1@domain.com it can be alias1@domain.com as long as this address is not in use you can make it whatever you want.
0
tamray_techAuthor Commented:
I just opened a new question, thinking I would need the username  in order to update the necessary attributes. I am attaching the screen shot here, so you can see what I need to accomplish.

I did misunderstand your solution. Thank you for clarifying. I will be able to complete the task, once I am able to export the logon names.
Screenshot-7.png
0
Will SzymkowskiSenior Solution ArchitectCommented:
To export the logon names is pretty easy. User the below powershell command to get the logon names (sAMAccountName)...

This will get all of the sAMAccountName's for all users in a specific OU.
Get-Aduser -Filter * -Searchbase "OU=test,DC=domain,DC=com" -Properties * | select samaccountname | export-csv "c:\samaccountexport.csv"
0
tamray_techAuthor Commented:
I successfully created the csv file, but attributes are not updated when running updateuser.ps1.

Here is what I have:

2012Fsamaccountexport.csv:

 NickName      ProxyAddress      UPN                  
RHanson93      RHanson93@domain.com      RHanson93@domain.com                  
HHawkenson93      HHawkenson93@domain.com      HHawkenson93@domain.com                  
CHedman94      CHedman94@domain.com      CHedman94@domain.com                  
JHendrickso94      JHendrickso94@domain.com      JHendrickso94@domain.com      

updateuser.ps1:
$UserSet = Import-Csv "c:\2012Fsamaccountexport.csv"
foreach ($User in $UserSet) {
$User.NickName
$User.ProxyAddress
$User.UPN
Get-Mailbox -OrganizationalUnit "OU=2012,OU=Students,DC=domain,DC=k12,DC=mn,DC=us" | Set-Mailbox -Alias $User.NickName -EmailAddresses $User.ProxyAddress -UserPrincipalName $User.UPN
}
0
Will SzymkowskiSenior Solution ArchitectCommented:
The script is pointing to a specific OU. If those users listed in the CSV file are not in the OU you are searching then nothing will be updated. Does this make sense?

If you do not want to specify a specific OU just remove the OU switch entirely.

$UserSet = Import-Csv "c:\2012Fsamaccountexport.csv"
foreach ($User in $UserSet) {
$User.NickName
$User.ProxyAddress
$User.UPN
Get-Mailbox | Set-Mailbox -Alias $User.NickName -EmailAddresses $User.ProxyAddress -UserPrincipalName $User.UPN
}
0
tamray_techAuthor Commented:
I went with your most recent script.

The csv file contains a single user:

NickName ProxyAddress UPN                  
RHanson93 RHanson93@domain.com RHanson93@domain.com      


I started with a new powershell instance:

PS C:\Users\administrator.NLS> Import-Module activedirectory
PS C:\Users\administrator.NLS> add-pssnapin Microsoft.Exchange.Management.PowerShell.E2010
PS C:\Users\administrator.NLS> C:\updateuser.ps1


Results: I get many instances of this error:

Set-Mailbox : The property can't be empty. Property Name: Alias
At C:\updateuser.ps1:6 char:26
+ Get-Mailbox | Set-Mailbox <<<<  -Alias $User.NickName -EmailAddresses $User.ProxyAddress -UserPrincipalName $User.U
    + CategoryInfo          : NotSpecified: (0:Int32) [Set-Mailbox], DataValidationException
    + FullyQualifiedErrorId : 5941D35C,Microsoft.Exchange.Management.RecipientTasks.SetMailbox
0
Will SzymkowskiSenior Solution ArchitectCommented:
Try this...

$UserSet = Import-Csv "c:\2012Fsamaccountexport.csv"
foreach ($User in $UserSet) {
$User.NickName
$User.ProxyAddress
$User.UPN
Get-Mailbox -idendity $User.UPN | Set-Mailbox -Alias $User.NickName -EmailAddresses $User.ProxyAddress -UserPrincipalName $User.UPN
}

Because the OU has been removed we need to specify the users you want to modify. I have added the -identity switch in the command above try that.


CSV file should still represent what you see below...
NickName                  ProxyAddress                        UPN                  
RHanson93             RHanson93@domain.com      RHanson93@domain.com                  
HHawkenson93     HHawkenson93@domain.com HHawkenson93@domain.com                  
CHedman94            CHedman94@domain.com      CHedman94@domain.com                  
JHendrickso94      JHendrickso94@domain.com      JHendrickso94@domain.com
0
tamray_techAuthor Commented:
I ran it exactly as you have listed, but corrected idendity to identity.

Here are the results:


Set-Mailbox : The property can't be empty. Property Name: Alias
At C:\updateuser.ps1:6 char:46
+ Get-Mailbox -identity $User.UPN | Set-Mailbox <<<<  -Alias $User.NickName -EmailAddresses $User.ProxyAddress -UserPri
ncipalName $User.UPN
    + CategoryInfo          : NotSpecified: (310:Int32) [Set-Mailbox], DataValidationException
    + FullyQualifiedErrorId : 5941D35C,Microsoft.Exchange.Management.RecipientTasks.SetMailbox
0
Will SzymkowskiSenior Solution ArchitectCommented:
Ok lets try doing a 1 command to ensure that it works. Once that is confirmed we can check out the script. Use the command below for 1 user.

Get-mailbox -identity RHanson93@domain.com | set-mailbox -Alisa RHanson93 -EmailAddreses RHanson93@emaildomain.com -UserPrincipalName RHanson93@domain.com

Let me know what the results are.
0
tamray_techAuthor Commented:
Object cannot be found....

I think the issue is that the user does not actually have a current mailbox, so that is why things are not working.

The school originally did not want to provide email accounts to students, so that info is empty in their account settings.
0
Will SzymkowskiSenior Solution ArchitectCommented:
Rofl, that might be why!!!! I was starting to wonder why it was not working when I have had it working on my end. The attributes you want to update are exchange attributes so unless the users have a mailbox the above commands will not work as you have experienced.


Cheers
0
tamray_techAuthor Commented:
Correct.. The attributes needed are for Exchange, specifically for Office 365, as I covered when I opened the question. Is there another variable we can use to query the user, so these attributes can be added. I need each account to be configured with these variables in order to merge them with existing Office 365 accounts. Without this, the accounts will be added, rather than merged.
0
Will SzymkowskiSenior Solution ArchitectCommented:
I am assuming that you want to use AD attributes for this considering the accounts do not have an Exchange mailbox currently. I am not sure what attributes you require for this but if you do the following command below it will provide a list of AD attributes for a user without a mailbox...

get-aduser -identity "sAMAccountName" -Properties * | get-member

This will populate a list of attributes you can update/modify with a script. Only select the attribute MemberType that are "Property" value.

Once you know that information I can correct the script above to achieve this.
0
tamray_techAuthor Commented:
All of the users that need to be modified are part of the "Students" group. Would it work to use that membership against specific OUs to get the needed updates?
0
Will SzymkowskiSenior Solution ArchitectCommented:
It does not matter the location (OU) or Group they are part of. I only need to know what attributes need to be modified to existing users in your environment. The location of the users can be done later. If we need to modify attributes to match the office 365 mailboxes this is more important.
0
tamray_techAuthor Commented:
The attributes I opened the question with are the same I still need created for each account, per Microsoft.

Maybe it would be just as simple to bulk create the missing email accounts and run your script again??
0
Will SzymkowskiSenior Solution ArchitectCommented:
Well are the requirements Per Microsoft to have the mailboxes created prior to Office 365 migration? If this is the case then you need to create them. ProxyAddresses and MailNickName are Exchange attributes, so if you are looking to update those field i would assume that the mailboxes should already be present.
0
tamray_techAuthor Commented:
I think, like you, they just assume the mailboxes would be there. I only know I have to have those attributes populated in order for the merge to work
0
Will SzymkowskiSenior Solution ArchitectCommented:
Then the only thing you can do is create new mailboxes for the accounts that do not already have one. If you can confirm this I can assist with the script.
0
tamray_techAuthor Commented:
That is  what I think we need to do.
0
Will SzymkowskiSenior Solution ArchitectCommented:
Script to enabled mailboxes of Currently created AD users.

CSV file needed for this looks like below...

UserPrincipalName         Database
user1@domain.com        ServerName\StorageGroup\DatabaseName
user2@domain.com        ServerName\StorageGroup\DatabaseName
So on....

Add-PSSnapin Microsoft.Exchange.Management.Powershell.Admin
$UserList = Import-Csv "c:\yourCSVhere.csv"
$UserList = foreach ($Mailbox in $UserList) {
$Mailbox.UserPrincipalName
$Mailbox.Database
Enable-mailbox -Identity $Mailbox.UserPrincipalName -Database $Mailbox.Database
}

Open in new window


Hopefully this is what you are looking for...
0
tamray_techAuthor Commented:
I believe so.. I will work on this today. Thank you for your help and patience. Sorry for the confusion.
0
tamray_techAuthor Commented:
I'm getting the following error:

Enable-Mailbox : Cannot bind argument to parameter 'Identity' because it is null.
At C:\updateuser2.ps1:6 char:25
+ Enable-mailbox -Identity <<<<  $Mailbox.UserPrincipalName -Database $Mailbox.Database
    + CategoryInfo          : InvalidData: (:) [Enable-Mailbox], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.Exchange.Management.RecipientTa
   sks.EnableMailbox





Here is what I have for the ps1 and csv (I could not find any storage groups on 2010 and believe they are not used )

ps1:

add-pssnapin Microsoft.Exchange.Management.PowerShell.E2010
$UserList = Import-Csv "c:\nls2012OUUPNwithmail.csv"
$UserList = foreach ($Mailbox in $UserList) {
$Mailbox.UserPrincipalName
$Mailbox.Database
Enable-mailbox -Identity $Mailbox.UserPrincipalName -Database $Mailbox.Database
}


csv:

UserPrincipalName       Database            
RHanson93@domain.com      Exchange.domain.com\021213            
HHawkenson93@domain.com      Exchange.domain.com\021213            
CHedman94@domain.com      Exchange.domain.com\021213
0
Will SzymkowskiSenior Solution ArchitectCommented:
Your CSV file should be servername\database. The UserPrincipalName needs to be one that actually exists in AD and it has to be exact.

Also using the script below. The one i originally gave you works for me but I have modified this one slightly.

$UserList = Import-Csv "c:\nls2012OUUPNwithmail.csv"
foreach ($Mailbox in $UserList) {
$Mailbox.UserPrincipalName
$Mailbox.Database
Enable-mailbox -Identity $Mailbox.UserPrincipalName -Database $Mailbox.Database
}
0
tamray_techAuthor Commented:
Here are my latest findings.

As stated before, most of the accounts do not have anything populating the "User Logon name" field, but do have the UPN suffix populated. I ran the following command to be sure I indeed had the UPN correct. Specifically, I am using the Rhanson93 user for testing:

PS C:\Users\administrator.NLS> dsquery user -name Rebecca* | dsget user -display -upn
  upn                         display
  carlsonraATnls.k12.mn.us     Rebecca A. Carlson
  @nlswildcats.com

  carlsonrmATnls.k12.mn.us     Rebecca M. Carlson
  RSchmidt00@nls.k12.mn.us    Rebecca Schmidt
dsget succeeded

As you can see, I end up with an entry of @nlswildcats.com. I then modified the account by adding the correct information to the User Logon field and ran the command again. This time the users upn was there.

PS C:\Users\administrator.NLS> dsquery user -name Rebecca* | dsget user -display -upn
  upn                          display
  carlsonraATnls.k12.mn.us      Rebecca A. Carlson
  Rhanson93ATnlswildcats.com

  carlsonrmATnls.k12.mn.us      Rebecca M. Carlson
  RSchmidt00ATnls.k12.mn.us     Rebecca Schmidt
dsget succeeded

Now, I made only a single entry in the csv file, as follows:

UserPrincipalName       Database            
RHanson93@nlswildcats.com      Exchange\021213      
      
(also changed the sever name to its fqdn for a 2nd test)

I am using the latest script you provided, but end up with the following error:

PS C:\Users\administrator.NLS> C:\updateuser2.ps1


Enable-Mailbox : Cannot bind argument to parameter 'Identity' because it is null.
At C:\updateuser2.ps1:5 char:26
+  Enable-mailbox -Identity <<<<  $Mailbox.UserPrincipalName -Database $Mailbox.Database
    + CategoryInfo          : InvalidData: (:) [Enable-Mailbox], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.Exchange.Management.RecipientTa
   sks.EnableMailbox
0
Will SzymkowskiSenior Solution ArchitectCommented:
I have used this script in my environment for many AD/Exchange modificaitons, and it works with no issues. At this point i am not sure what is happening on your side. You might want to close this question and re-open a new one.

Will.
0
footechCommented:
I'm wondering if your .CSV is actually in the correct format.  All the posts show pretty much what what you would see when opening the file in Excel, but in Notepad it would look like below.
NickName,ProxyAddress,UPN
User1,User1@domain.com,User1@domain.com
User2,User2@domain.com,User2@domain.com
User3,User3@domain.com,User3@domain.com

Open in new window

It's a bit basic, but it's good to verify...
0
tamray_techAuthor Commented:
I opened a new question, as advised. Here is the script that worked to populate the attributes:

Get-ADUser -filter * -searchbase "OU=2012,OU=Students,DC=domain,DC=k12,DC=mn,DC=us" | ForEach `
{
    $upn = "$($_.samaccountname)@domain.com"
    Set-ADUser -Identity $_.samaccountname -UserPrincipalName $upn -Add @{ Mail = $upn; proxyAddresses = "SMTP:$upn" }
}

I am not sure about the format being incorrect for the csv file, but believe the key was that the users had incomplete upns. If one of your answers would have accomplished the same thing for me, I would like to accept that as a solution
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
tamray_techAuthor Commented:
Worked, as needed
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.