Friday, August 28, 2015

Setting up IP Phones in AD

You can mass update the IP Phone fields your Active Directory in a couple of easy steps.

Generically, here is what you will need to do.  There are several tools on the internet to assist.  We will attach a couple scripts as well.  Proceed carefully as all the normal AD warning apply.
  1. Export your AD account names to a CSV file with Powershell.
  2. Open in Excel and add a column for the ipPhone field it its missing.
  3. Remove any row entries that do not apply. aka Service accounts etc.
  4. Enter the appropriate DN for each name
  5. Delete any unnecessary columns such as the DisplayName Column.
  6. Delete the header line with column names in it.
  7. Save as a CSV.  example: c:\temp\ADUsersImport.csv
  8. Import the CSV to AD with Powershell.

SAMPLE Export Script (zero risk to anything.)
Change the highlighted text to your choice of export file name.

Get-ADUser -Filter {(Name -notlike "*(Administrator)")}  -Properties SamAccountName,DisplayName,ipPhone| Select-Object SamAccountName,DisplayName,ipPhone | export-csv -path c:\temp\ADUsersExported.csv -NoTypeInformation -Encoding "UTF8"

The exported file will look like this....

SAMPLE Excel Spreadsheet

SAMPLE CSV for Import

SAMPLE Import Script (Medium risk, make certain your data is clean)

Create a file with the following script named c:\temp\ipphoner.ps1

Import-Module ActiveDirectory 
$CSVPath = "c:\temp\ADUsersImport.csv"
$csvData = Import-CSV $CSVPath -delimiter "," -Header ("sAMAccountName","IPPhone")
foreach ($line in $csvData ) 
$accountTable = @{ 
'sAMAccountName'= $line.sAMAccountName 
'IPPhone'= $line.ipPhone 
ForEach($line in $csvData) 
$sAMAccountName = $line.sAMAccountName 
$ipphone = $line.ipPhone 
$Blank = ""
{ "modifying $($sAMAccountName) and adding $ipphone number " 
$SETIPPHONE.ipphone = $ipphone
Set-ADUser $sAMAccountName -Replace @{ipPhone=$ipphone} }

From the Windows Powershell prompt in a C:\Temp run the script.
This should update the iphhone field of all of the users in the CSV.

No comments:

Post a Comment