r/PowerShell • u/Nisamu94 • Nov 26 '25
Solved PowerShell script not filling in the EMail field for new users.
Hello,
I'm fairly new to Powershell and I'm trying to make a few scripts for user management. Below is a section of my script that has the user properties and a corresponding csv file to pull from. However, it doesn't seem to fill in the Email field when looking at the General properties for the user in AD DS. Am I wrong to assume that the EmailAddress property should fill that in? I receive zero errors when executing the script.
if (Get-ADUser -F {SamAccountName -eq $Username}) {
#If user does exist, give a warning
Write-Warning "A user account with username $Username already exist in Active Directory."
}
else {
# User does not exist then proceed to create the new user account
# create a hashtable for splatting the parameters
$userProps = @{
SamAccountName = $User.SamAccountName
Path = $User.Path
GivenName = $User.GivenName
Surname = $User.Surname
Initials = $User.Initials
Name = $User.Name
DisplayName = $User.DisplayName
UserPrincipalName = $user.UserPrincipalName
Description = $User.Description
Office = $User.Office
Title = $User.Title
EmailAddress = $User.Email
AccountPassword = (ConvertTo-SecureString $User.Password -AsPlainText -Force)
Enabled = $true
ChangePasswordAtLogon = $true
} #end userprops
New-ADUser @userProps
1
Upvotes
5
u/HeyDude378 Nov 26 '25
We need to see the section of your code where the CSV file is pulled in and where the $user variable is defined. If everything else is working properly, then most likely your CSV file doesn't have a column named Email.
1
u/gramsaran Nov 26 '25
Pretty sure the AD Attribute is "mail".
1
u/Adam_Kearn Nov 26 '25 edited Nov 26 '25
The attribute you are looking for is “mail” On the docs it provides an example of setting this value.
Some attributes have to be set this way as the normal properties are limited within the standard way of adding users
See example 2 on this link
https://learn.microsoft.com/en-us/powershell/module/activedirectory/new-aduser?view=windowsserver2025-ps#example-2-create-a-user-and-set-properties
I would also recommend including the object location to allow you to store the user within a specific OU instead of just dumping it in the default users OU
-7
u/Ok_Mathematician6075 Nov 26 '25
Bro Azure Module is deprecated, you need to be using MSGraph
-11
u/Ok_Mathematician6075 Nov 26 '25