Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Thursday, May 9, 2013 5:07 PM
I'm having some issues writing a script to set the ipPhone attribute for users. This is what I have.
$username = read-host "Enter user name."
$ipphone = read-host "Enter IP Phone extension."
Get-ADUser -Filter {SamAccountName -eq $usernam2} | Set-ADUser -Add @{ipPhone=$ipphone}
It prompts properly but fails with.
Set-ADUser : Invalid type 'System.Management.Automation.PSObject'.
Parameter name: ipPhone
At C:\Windows\system32\ipphone.ps1:3 char:63
- Get-ADUser -Filter {SamAccountName -eq $username} | Set-ADUser <<<< -Add @{i
pPhone=$ipphone}
+ CategoryInfo : InvalidArgument: (CN=John Parker,...nergyllc,DC=
com:ADUser) [Set-ADUser], ArgumentException
+ FullyQualifiedErrorId : Invalid type 'System.Management.Automation.PSObj
ect'.
Parameter name: ipPhone,Microsoft.ActiveDirectory.Management.Commands.SetA
DUser
I would like it to set a value even if one exists. I think I need a -Remove first, then I can -ADD. Help is greatly appreciated.
All replies (9)
Thursday, May 9, 2013 5:41 PM ✅Answered | 4 votes
Got it working...
You have to use double quotes in the hash table for the key value.
$username = read-host "Enter user name."$ipphone = read-host "Enter IP Phone extension."Get-ADUser -Filter {SamAccountName -eq $username} | Set-ADUser -Add @{ipPhone="$ipphone"}
Boe Prox
Blog | PoshWSUS | PoshPAIG | PoshChat
Thursday, May 9, 2013 5:23 PM
The error states that you are supplying a different type that the attribute cannot accept (System.Management.Automation.PSObject) which has nothing to do with the attribute already having data. Is this the full code that you are providing to us to look at?
Boe Prox
Blog | PoshWSUS | PoshPAIG | PoshChat
Thursday, May 9, 2013 5:24 PM | 1 vote
is ipPhone a custom AD attribute?
Also, there is not reason to filter the sAMAccountName, you could just do:
Get-ADUser $usernam2
Now with the above command, it will only return a set of defualt properties, so anything that is not in the default you need to specify with the properties parameter
Get-ADUser $usernam2 -Properties ipPhone
If you find that my post has answered your question, please mark it as the answer. If you find my post to be helpful in anyway, please click vote as helpful.
Thursday, May 9, 2013 5:26 PM
The error states that you are supplying a different type that the attribute cannot accept (System.Management.Automation.PSObject) which has nothing to do with the attribute already having data. Is this the full code that you are providing to us to look at?
That is my full code. Just three lines in a script file.
I am 100% the attribute has no data when this error occurs. The -Remove and -Add comment was looking for confirmation that this is how I would go about that, not really having to do with the specific issue.
Thursday, May 9, 2013 5:34 PM
Try this:
$ipphone.GetType().Fullname
I'm curious as to the type that is being saved to this variable as the Set-ADUser believes it to be the System.Management.Automation.PSObject.
You won't actually see ipPhone even with the -Properties ipPhone on Get-ADUser unless there is actually data in it.
Boe Prox
Blog | PoshWSUS | PoshPAIG | PoshChat
Thursday, May 9, 2013 5:34 PM
is ipPhone a custom AD attribute?
Also, there is not reason to filter the sAMAccountName, you could just do:
Get-ADUser $usernam2
Now with the above command, it will only return a set of defualt properties, so anything that is not in the default you need to specify with the properties parameter
Get-ADUser $usernam2 -Properties ipPhone
If you find that my post has answered your question, please mark it as the answer. If you find my post to be helpful in anyway, please click vote as helpful.
ipPhone is a default property. It is only visible in Advanced mode though. With your example, I see how to call the property, but setting it is different. Most of the properties I see set can be set as Set-ADUser -Address "3000 West 8th St"
I'm not sure why this property is treated differently.
Thursday, May 9, 2013 5:38 PM
Lets take it down to the bare bones code and work up from that. Try running this and see if it works:
Set-ADUser <username>-Add @{ipPhone='<IPAddress>'}
Boe Prox
Blog | PoshWSUS | PoshPAIG | PoshChat
Thursday, May 9, 2013 5:41 PM | 1 vote
is ipPhone a custom AD attribute?
Also, there is not reason to filter the sAMAccountName, you could just do:
Get-ADUser $usernam2
Now with the above command, it will only return a set of defualt properties, so anything that is not in the default you need to specify with the properties parameter
Get-ADUser $usernam2 -Properties ipPhone
If you find that my post has answered your question, please mark it as the answer. If you find my post to be helpful in anyway, please click vote as helpful.
ipPhone is a default property. It is only visible in Advanced mode though. With your example, I see how to call the property, but setting it is different. Most of the properties I see set can be set as Set-ADUser -Address "3000 West 8th St"
I'm not sure why this property is treated differently.
Ah, that's probably why I don't see that attribute. Like Boe said, we need to see what type of data it is expecting and what you are sending it. Is $ipPhone a string?
If you find that my post has answered your question, please mark it as the answer. If you find my post to be helpful in anyway, please click vote as helpful.
Thursday, May 9, 2013 5:43 PM
Thanks a ton! Out of curiosity, how would one go about changing it the value instead of setting it? I don't see a -Change, so it must be -Remove and -Add.