Hello,
Can someone help me out I want to be able to have a powershell script (very simple) that can take a users SAMACCOUNT and add the mobile number to that account via CSV.
The field I want to populate would be the field under Telephones “Mobile”
Can anyone help me out.
I believe it would need to look something like this
PS1 file
set-aduser -Identity $user.samaccount -officephone $user.ADNumber
CSV File
1 column $user.samaccount (with my usernames there)
1 column $user.ADNumber (with the phone numbers) but I’m not sure that this is the correct setting
My issue is I’m not sure -officephone is the correct field, I think that -office phone will populate what is under the “general” tab correct?
Why don’t you figure that out by yourself? You should set up a user where this attribute is populated. Then you simply read this user with PowerShell and inspect the output. With
And BTW: When you post code, sample data, console output or error messages please format it as code using the preformatted text button ( </> ). Simply place your cursor on an empty line, click the button and paste your code.
I am Costanza, Lord of the idiots. I cannot believe I forgot to put the import switch.
I run it now I get an output and this is what I get
Set-ADUser : Cannot validate argument on parameter 'Identity'. The argument is
null. Provide a valid value for the argument, and then try running the command
again.
At c:\AddMobileAD.ps1:4 char:22
+ set-aduser -Identity $User.SamAccountName -Mobile $User.MobilePhone
+ ~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Set-ADUser], ParameterBindingV
alidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.Activ
eDirectory.Management.Commands.SetADUser
Set-ADUser : Cannot validate argument on parameter 'Identity'. The argument is
null. Provide a valid value for the argument, and then try running the command
again.
At c:\AddMobileAD.ps1:4 char:22
+ set-aduser -Identity $User.SamAccountName -Mobile $User.MobilePhone
+ ~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Set-ADUser], ParameterBindingV
alidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.Activ
eDirectory.Management.Commands.SetADUser
Set-ADUser : Cannot validate argument on parameter 'Identity'. The argument is
null. Provide a valid value for the argument, and then try running the command
again.
At C:\AddMobileAD.ps1:4 char:22
+ set-aduser -Identity $User.SamAccountName -Mobile $User.MobilePhone
+ ~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Set-ADUser], ParameterBindingV
alidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.Activ
eDirectory.Management.Commands.SetADUser
Set-ADUser : Cannot validate argument on parameter 'Identity'. The argument is
null. Provide a valid value for the argument, and then try running the command
again.
At C:\AddMobileAD.ps1:4 char:22
+ set-aduser -Identity $User.SamAccountName -Mobile $User.MobilePhone
+ ~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Set-ADUser], ParameterBindingV
alidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.Activ
eDirectory.Management.Commands.SetADUser
My CSV has the headers like this
A B
$User.SamAccountName $User.MobilePhone
Firstname.Lastname 555-555-5555
Hello, I tried SamAccountName and MobilePhone as the columns in the CSV, still same error
Set-ADUser : Cannot validate argument on parameter 'Identity'. The argument is
null. Provide a valid value for the argument, and then try running the command
again.
At c:\AddMobileAD.ps1:4 char:22
+ set-aduser -Identity $User.SamAccountName -Mobile $User.MobilePhone
+ ~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Set-ADUser], ParameterBindingV
alidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.Activ
eDirectory.Management.Commands.SetADUser
Set-ADUser : Cannot validate argument on parameter 'Identity'. The argument is
null. Provide a valid value for the argument, and then try running the command
again.
At c:\AddMobileAD.ps1:4 char:22
+ set-aduser -Identity $User.SamAccountName -Mobile $User.MobilePhone
+ ~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Set-ADUser], ParameterBindingV
alidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.Activ
eDirectory.Management.Commands.SetADUser
Set-ADUser : Cannot validate argument on parameter 'Identity'. The argument is
null. Provide a valid value for the argument, and then try running the command
again.
At c:\AddMobileAD.ps1:4 char:22
+ set-aduser -Identity $User.SamAccountName -Mobile $User.MobilePhone
+ ~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Set-ADUser], ParameterBindingV
alidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.Activ
eDirectory.Management.Commands.SetADUser
Set-ADUser : Cannot validate argument on parameter 'Identity'. The argument is
null. Provide a valid value for the argument, and then try running the command
again.
At c:\AddMobileAD.ps1:4 char:22
+ set-aduser -Identity $User.SamAccountName -Mobile $User.MobilePhone
+ ~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Set-ADUser], ParameterBindingV
alidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.Activ
eDirectory.Management.Commands.SetADUser
$csv = import-csv “C:\AddMobileAD.ps1”
##Loop through all users in CSV
foreach ($user in $csv) {
set-aduser -Identity $User.SamAccountName -Mobile $User.MobilePhone
}
c:\addmobilead.ps1 contents
A B
$User.SamAccountName $User.MobilePhone
First.Last 555-555-5555
Im not really sure why it’s not working, I even did
Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass
Hello,
I tried your suggestion I still get the same error.
tySet-ADUser : Cannot validate argument on parameter 'Identity'. The argument is
null. Provide a valid value for the argument, and then try running the command
again.
At c:\AddMobileAD.ps1:4 char:22
+ set-aduser -Identity $User.SamAccountName -Mobile $User.MobilePhone
+ ~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Set-ADUser], ParameterBindingV
alidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.Activ
eDirectory.Management.Commands.SetADUser
Set-ADUser : Cannot validate argument on parameter 'Identity'. The argument is
null. Provide a valid value for the argument, and then try running the command
again.
At c:\AddMobileAD.ps1:4 char:22
+ set-aduser -Identity $User.SamAccountName -Mobile $User.MobilePhone
+ ~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Set-ADUser], ParameterBindingV
alidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.Activ
eDirectory.Management.Commands.SetADUser
Set-ADUser : Cannot validate argument on parameter 'Identity'. The argument is
null. Provide a valid value for the argument, and then try running the command
again.
At c:\AddMobileAD.ps1:4 char:22
+ set-aduser -Identity $User.SamAccountName -Mobile $User.MobilePhone
+ ~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Set-ADUser], ParameterBindingV
alidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.Activ
eDirectory.Management.Commands.SetADUser
Set-ADUser : Cannot validate argument on parameter 'Identity'. The argument is
null. Provide a valid value for the argument, and then try running the command
again.
At c:\AddMobileAD.ps1:4 char:22
+ set-aduser -Identity $User.SamAccountName -Mobile $User.MobilePhone
+ ~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Set-ADUser], ParameterBindingV
alidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.Activ
eDirectory.Management.Commands.SetADUserpe or paste code here
$csv = import-csv “C:\AddMobileAD.ps1”
##Loop through all users in CSV
foreach ($user in $csv) {
set-aduser -Identity $User.SamAccountName -Mobile $User.MobilePhone
}
Contents of my CSV
Column A Column B
$User.SamAccountName $User.MobilePhone
FirstName.LastName 555-555-5555
I’m not really sure what I am doing wrong, I even put
Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass
Nothing changed
Thank you again!
PS I apologize for this very beginner question.
Hello!
So I tried that also I still get an identity error.
Maybe I am not explaining it correct or maybe (most likely) I’m not understanding the replies.
I want to be able to have my CSV have the following lines
Column A in Excel CSV Column B in Excel CSV
SamAccountName MobilePhone
Username1 Mobile#1
Username2 Mobile#2
Username3 Mobile#3
Etc Etc
My PS1 file that I run in Powershell looks like this
$csv = import-csv “C:\AddMobileAD.csv”
##Loop through all users in CSV
foreach ($user in $csv) {
set-aduser -Identity $User.SamAccountName -Mobile $User.MobilePhone
}
When I run my script it spits out this error which as far as I can understand it is saying something is wrong after the -Identity switch
Set-ADUser : Cannot validate argument on parameter 'Identity'. The argument is null. Provide a valid value for the argument, and
then try running the command again.
At C:\AddMobileAD.ps1:4 char:22
+ set-aduser -Identity $User.SamAccountName -Mobile $User.MobilePhone
+ ~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Set-ADUser], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.ActiveDirectory.Management.Commands.SetADUser
Is your CSV file a valid CSV file? You should open it with a text editor - not Excel - and it should look something like I showed before. Plain text with cells wrapped in quotes separated by comma.
To debug your code you could simply output the variables you’re using to the console to check if they are what you expect them to be.
I figured it out, the problem seems to be the username I was using!
I tried two other usernames and it was working fine, very strange I’ll have to see why my username is not working, I triple checked the sam account name and it’s correct.
In any case, it’s working now as expected about 4 posts ago
Thank you VVVVVVEEEEEEERRRRRRRRYYYYYYYY much everyone for your support, I have to say this is now my favorite PS forum!