Updated: Get IP Office extension list

Hey all together.

Some times ago I published a small script that pulls all the users and groups from IP Office and presents them as a sorted HTML file. I had issues to correctly display German umlauts (ä, ö, ü) in the HTML document and thought it was an issue that the script didn’t correctly convert those characters in HTML code (ä for example).

I found out that the real issue was that the provided data from IP Office came as UTF8 but PowerShell tries to treat that as local format. We can tell PowerShell to treat the data as UTF8 while reading.

We just have to add the parameter ‘Encoding UTF8’ to the ‘Get-Content’ commandlet:

# Extract users from XML file
[xml]$xmlfile = Get-Content $output -Encoding UTF8
$xmlfile.GetType().FullName
$a = $xmlfile.user_list.list.user

# Extract groups from XML file
[xml]$xmlfile = Get-Content $output -Encoding UTF8
$xmlfile.GetType().FullName
$b = $xmlfile.huntgroup_list.list.group

So here is the updated full script:

# A few variables
# $ipoaddress will be used as suggested default IP address
$ipoaddress = "10.10.10.10"
$htmlpath = "C:\temp"
$htmlfile = "HtmlReport.html"

# Ensure to run loop at least once
$reach = $false

while ($reach -eq $false)
{
    Write-Output "IP address of IP Office is needed"
    # Ask to change IPO IP address
    $prompt = "Enter IP address of primary server or hit Enter to use the default [" + $ipoaddress + "]"
    #Clear-Variable -Name ipoip
    $ipoip = Read-Host -Prompt $prompt
    
    # Use value of $ipoaddress if nothing is entered or use the value that has been entered
    # Check if the used IP address is reachable by ping
    if ($ipoip -eq "")
    {
        # Test connection to IPO
        if (Test-Connection $ipoaddress -Count 1 -Quiet)
        {
            $reach = $true
        }       
    }
    else
    {
        $ipoaddress = $ipoip
        # Test connection to IPO
        if (Test-Connection $ipoaddress -Count 1 -Quiet)
        {
            $reach = $true
        }
        
    }
    Clear-Host
    if ($reach -ne $true)
    {
    Write-Output "IP Office is not reachable"
    Write-Output ""
    }
}

# Create directory if it doesn´t exist
If ($(Test-Path  $htmlpath) -eq $false){
	New-Item -Path $htmlpath -ItemType Directory
}

# Implement web client
$wc = New-Object System.Net.WebClient

# Get user list from IPO
$url = "http://" + $ipoaddress + "/system/user/scn_user_list"
$output = $htmlpath + "\scn_user_list.xml"
$wc.DownloadFile($url, $output)

# Extract users from XML file
[xml]$xmlfile = Get-Content $output -Encoding UTF8
$xmlfile.GetType().FullName
$a = $xmlfile.user_list.list.user

# Get group list from IPO
$url = "http://" + $ipoaddress + "/system/huntgroup/scn_huntgroup_list"
$output = $htmlpath + "\scn_group_list.xml"
$wc.DownloadFile($url, $output)

# Extract groups from XML file
[xml]$xmlfile = Get-Content $output -Encoding UTF8
$xmlfile.GetType().FullName
$b = $xmlfile.huntgroup_list.list.group

$htmlfile = $htmlpath + "\" + $htmlfile

# Merge users and groups
$c = $a + $b

# Write users and groups into HTML file
$c | Sort-Object -Property extn | select @{Expression={$_.extn};Label="Nebenstelle"},@{Expression={$_.name};Label="Name"},@{Expression={$_.fname};Label="Vollständiger Name"} | ConvertTo-Html | Set-Content $htmlfile
$c.Count

# Open HTML file
Invoke-Item $htmlfile

 

If you need further help with IP Office you can contact me through my main website: https://www.fwilke.com/home

Do you want to get information about new posts? Subscribe to my Newsletter

Leave a Reply

Your email address will not be published. Required fields are marked *