Powershell scripting Active Directory select-object
Posted on 2010-11-15
I am trying to write a powershell script that will grab the users telephone number from active directory, select a portion of it (last 4 numbers), concatenate some numbers onto that, and then add that back into Active directory as the IP phone attribute.
I was able to do this successfully by exporting data to a csv modifying and then re-importing but I know there is a way of doing this all from the command line.
The command I used to dump the telephone number was
get-qaduser -phonenumber xxx-xxx-xxxx | select-object phonenumber
I am not sure how to actually get and manipulate the value that is returned from that command. I tried
$phone = get-qaduser -phonenumber xxx-xxx-xxxx | select-object phonenumber
Which seems to work but it stores the whole output not just the telelphone number.
So I guess my first two questions are
1. How can i capture only the 10 digit telephone number
2. How can I manipulate that in powershell