Tuesday, December 6, 2011

What to do when AD phone property is formatted wrong.

In my previous post, I just showed you how to search for a security group in AD, and set cs-user properties based on the selection of users.

My script is based on these users having 100% correct formatted phone attribute in Active Directory. But as some of you already know, that might not be the case. Some have formatted their phone numbers with spaces like this: +47 22 22 22 22, some might have used other characters like this +1 (454) 123 4567 and others might not have the proper E.164 international formatting and have left out their international code: (202) 123 4567.

Fear not, I will tell you how to handle this (as long as they all have the same "error" in their syntax).

If you look at the following command:

Get-ADGroup -Identity TestGroup | Get-ADGroupMember -verbose | foreach {get-csaduser -identity $_.Name | foreach {
$sipit = $_.phone
$sipit = "tel:" + $sipit
Set-CsUser -Identity $_.Name -EnterpriseVoiceEnabled $true -LineURI $sipit -PassThru | Grant-CsClientPolicy -PolicyName restrict}}

You can see we grab the "phone" attribute and populate it into a variable I have called $sipit. Then I add the "tel:" to the already existing $sipit variable. After this, the output of $sipit is "tel:-whateverwasinthephoneattrib". If the phone attrib is wrongly formatted, we need to alter this before we add the "tel:". We can do this using the -replace command. And I will sow you two examples of how to do this.

1)

Get-ADGroup -Identity $groupfetch | Get-ADGroupMember -verbose | foreach {get-csaduser -identity $_.Name | foreach {
$sipit = $_.phone
## Next line will remover anythin in the string that is not a number (including +, spaces, () and more)
$sipit = $sipit -rplace "[^0-9]"
## Next line is slightly modified to add the + back into the phone number
$sipit = "tel:+" + $sipit
Set-CsUser -Identity $_.Name -EnterpriseVoiceEnabled $true -LineURI $sipit -PassThru | Grant-CsClientPolicy -PolicyName restrict}}

Given the command above you would take a number like this +1 (234) 567 8900, or this: +1 234 5678900 and turn them into the correct lineURI format tel:+12345678900.

2)
Just as an example, I'll show how to add the national prefix if this is not present in the AD property:

Get-ADGroup -Identity $groupfetch | Get-ADGroupMember -verbose | foreach {get-csaduser -identity $_.Name | foreach {
$sipit = $_.phone
## Next line will remover anythin in the string that is not a number (including +, spaces, () and more)
$sipit = $sipit -rplace "[^0-9]"
## Next line is slightly modified to add the + and the international prefix into the phone number
## I used the North American code +1 in the example. You use whatever you need to in your deployment.
$sipit = "tel:+1" + $sipit
Set-CsUser -Identity $_.Name -EnterpriseVoiceEnabled $true -LineURI $sipit -PassThru | Grant-CsClientPolicy -PolicyName restrict}}

Quite simple, and a very quick way to enable telephony for your users. have fun labbing, and please let me know what you think about these posts.

If you need more power shell commands for Lync, I can really recommend the Lync Powershell Blog  They have a great collection of examples.


0 comments:

Labels

Lync (15) Microfoft Lync Server 2010 (15) Microsoft (14) Windows (12) Cisco (11) Voice (11) OCS 2007 (9) CCIE (8) CUCM (8) OCS 2007 R2 (8) Windows Server 2008 (8) Powershell (7) Certifications (5) Internetworkexpert (5) Lab (5) Server (5) Beta (4) CUCM 7 (4) CUCM 8 (4) Freeware (4) MS Exchange (4) Mediation Server (4) Microsoft Office Communicator 2007 R2 (4) Software (4) Unified Messaging (4) Virtual Machine (4) Windows Live (4) Browser (3) CAC (3) Call Manager (3) Chrome (3) Google (3) Graded Labs (3) IPT (3) Iewb-vo-vol1 (3) Install (3) Internet (3) SQL 2008 (3) Upgrading (3) Virtual PC (3) Windows 7 (3) Windows Server 2008 R2 (3) enable-csuser (3) import-csv (3) set-csuser (3) Active Directory (2) Address Book (2) Bandwidth Management (2) Blog tool (2) CUCILYNC (2) Certificate (2) Exchange 2010 (2) Exchange Roles (2) HYPER-V (2) IIS (2) MTP (2) New-aduser (2) R2 (2) Remote control (2) SIP (2) SIP Trunk (2) SQL (2) SSL (2) UC (2) USB (2) User (2) VMWare (2) Virtual Server (2) Voice policies (2) get-adgroup (2) get-adgroupmember (2) 074-924 (1) 0x80070534 (1) 0xC3EC796C (1) 32bit (1) 350-030 (1) 443 (1) 5062 (1) 64bit (1) A/V authentication (1) ADDS (1) Application server (1) Assigned (1) Attendant (1) Brussels (1) CD (1) COMMUNICATIONS MANAGER (1) CUCIMOC (1) CUPS (1) CWA (1) Certificate Authority (1) Certification (1) Charter Member (1) Cisco Presence (1) Communicator Web Access (1) Conference (1) DL360 (1) DNS (1) Deployment (1) Desktop (1) Digit manipulation (1) Domain (1) Dual-boot (1) ESX (1) EWS (1) Edge (1) Encryption (1) Enterprise Voice (1) Error 3221684226 (1) Error 404 (1) Error 503 (1) Event ID 32018 (1) Exchange (1) Exchange 2007 (1) FTP (1) Fail (1) Filemerge (1) Front-end server (1) General network (1) Global Knowledge (1) HCL (1) HD (1) HP (1) HTC Touch (1) INVITE (1) Just for fun (1) Limited External Calling (1) LineURI (1) Linux (1) Livemeeting (1) Lync Server SDK 2010 (1) Lync client (1) MAPI (1) Microsoft Communications Server R2 Attendant (1) Microsoft® Community Contributor Award (1) NTP (1) Netwise CMG (1) Netwise CMGVoice (1) New-CsNetworkBandwidthPolicyProfile (1) New-CsNetworkRegion (1) New-CsNetworkSite (1) New-CsNetworkSubnet (1) Normalization (1) OCS validation (1) Office 2007 (1) Office 2010 (1) PSTN GW (1) Planning Tool (1) RC (1) RDP (1) RSAT (1) Rundtomrundt (1) SDelete (1) SP1 (1) SP3 (1) Sipreroute (1) Switchboard (1) Sysadminday (1) Sysinternals (1) System administrator (1) TeamViewer (1) Topology Builder (1) Translation-rule (1) TrueCrypt (1) Twitter (1) UC520 (1) UM (1) Ubuntu (1) Ubuntu 9 (1) Unassigned (1) Windows Firewall (1) Windows Vista (1) Windows XP (1) aboutme (1) csps (1) cspshell (1) csv (1) get-aduser (1) get-csaduser (1) grant-csdialplan (1) grant-voicepolicy (1) new-csserverapplication (1) notepad (1) passwords (1) set-aduser (1)