In the beginning we had a PHP Website to make xml files for prefilling the PCA toolbar.
The site use LDAP connection. Due to security it is changed to LDAPS. So I needed to build something to to do the same but then with LDAPS connection.
I could change the PHP code, but the code was old, and I’m not used PHP code.
On the server that I use, Domain tools are installed.
On the Script location this is how my directory is build
In the script, it downloads the XML files from the PeterConnects server and place them in XMLIN
In the XMLOUT directory are the files that you manual need to put on the PeterConnects server.
BACKUP Directory. Here are all backups of the XMLOUT files. When running script, first it makes a backup of the XMLOUT files. Then the rest.
In the Config.txt file is how you would like the filling. This is per line same in the toolbar. Have the departments together
PHONE;NAME;DEPARTMENT
xxx;van der Meer, Daag;ICT
Now the script:
Row 15: Add/Change Servername
Row 20: Add/Change Domain Search location of the users.
Row 21: Add/Change Full Domain name.
I Always run this script manual, but it is possible to automate it. Also to upload it back to the PeterConnects server and Restart PeterConnects services to activate the XML’s.
#######################################
#### Created By Daag van der Meer
#### 16-10-2020 Finished
#####################################
# Determine script location for PowerShell
$ScriptDir = Split-Path $script:MyInvocation.MyCommand.Path
$ExportDir = "$ScriptDir\XMLOUT\"
$ImportDir = "$ScriptDir\XMLIN\"
$BackupDir = "$ScriptDir\BACKUPS\"
$date = (Get-Date).ToString('yyyyMMddHHmmss')
$PeterConnectsserver = "\\<SERVER>\c$\Program Files\PeterConnects\Data\Toolbar\*.*"
$ZIP = "Backup"+$date+".zip"
$BackupLoc = "$ScriptDir\BACKUPS\"+$ZIP
$Powershell = "$ScriptDir\Start.ps1"
$Config = "$ScriptDir\config.txt"
$DomainSearch = "OU=xxx,DC=xxx,DC=xxx,DC=xxx"
$UPNDC = "@xxx.xxx.xxx" # This is the domain DNS
##
## BACKUP Old XML files
Compress-Archive -Path $ImportDir,$Powershell, $Config -DestinationPath $BackupLoc
#######
### Delete Current XML
Get-ChildItem -Path $ImportDir -Include *.* -Recurse | foreach { $_.Delete()}
####
##Download latest XML's
Copy-Item $PeterConnectsserver -Destination $ImportDir
function get_uniqueID{
Param($unique_ID)
$IDcnt = $IDcnt+1;
$i+1
$ordercnt = $ordercnt+1;
}
########
## Clean Export folder
########
Get-ChildItem -Path $ExportDir -Include *.* -Recurse | foreach { $_.Delete()}
Get-ADUser -Filter * -properties displayName,sAMAccountName,ipphone,info,department -SearchBase $DomainSearch | Where-Object {$_.ipphone -ne $null} |
ForEach-Object {
$displayName = $_.displayName
$userPrincipalName2 = $_.sAMAccountName
$userPrincipalName = $userPrincipalName2+$UPNDC
$ipphone = $_.ipphone
$info = $_.info
$department = $_.department
$i = 0
$IDcnt = 0;
$ordercnt = 0;
$uniqueID_incr = 1
$uniqueID_base = 20000 * $ipphone
$uniqueID = $uniqueID_base
$NEW_XML = $ExportDir + "Config_" +$userPrincipalName+".xml"
$ORG_XML = $ImportDir + "Config_" +$userPrincipalName+".xml"
$aftersales = $uniqueID_base + $uniqueID_incr - 1
$dealerdevelopment = $uniqueID_base + $uniqueID_incr - 2
$directie = $uniqueID_base + $uniqueID_incr - 3
$finance = $uniqueID_base + $uniqueID_incr - 4
$groepen = $uniqueID_base + $uniqueID_incr - 5
$ICT = $uniqueID_base + $uniqueID_incr - 6
$marketing = $uniqueID_base + $uniqueID_incr - 7
$mijngroep = $uniqueID_base + $uniqueID_incr - 8
$overig = $uniqueID_base + $uniqueID_incr - 9
$sales = $uniqueID_base + $uniqueID_incr - 10
$self = $uniqueID_base + $uniqueID_incr - 11
$Gemistegesprekken = $uniqueID_base + $uniqueID_incr - 12
$XMLTESTPATH = Test-Path $ORG_XML
If ($XMLTESTPATH -eq $True) {
$SELECTSTRING = Select-String -Pattern '<ToolbarUserConfig ID="[0-9][0-9][0-9][0-9]*">' $ORG_XML | % { $_.Matches }
$toolbar_id = $SELECTSTRING -replace '<ToolbarUserConfig ID="','' -replace '">',''
#Write-Host $ReplSELECTSTRING
# Create the XML File Tags
$enc = New-Object System.Text.UTF8Encoding($True)
$XmlWriter = New-Object System.Xml.XmlTextWriter($NEW_XML,$enc)
$xmlWriter.Formatting = 'Indented'
$xmlWriter.WriteStartDocument()
$xmlWriter.WriteStartElement('ToolbarUserConfig')
$XmlWriter.WriteAttributeString('ID', $toolbar_id)
#$xmlWriter.WriteStartElement('WebApplication')
$xmlWriter.WriteStartElement('UserInfo')
$xmlWriter.WriteElementString('PcaUniqueId',$ipphone)
$xmlWriter.WriteElementString('UserDomain',$userPrincipalName)
$xmlWriter.WriteElementString('Label', $displayName)
$xmlWriter.WriteElementString('LineNr', $ipphone)
$xmlWriter.WriteElementString('ShowLineNr', $ipphone)
$xmlWriter.WriteStartElement('TenantPrefix')
$xmlWriter.WriteEndElement()
$xmlWriter.WriteElementString('ShowLineNumbers', 'true')
$xmlWriter.WriteStartElement('ColumnOffsets')
$xmlWriter.WriteEndElement()
$xmlWriter.WriteElementString('OnHotkey', 'DialDirect')
$xmlWriter.WriteElementString('Hotkey', 'CTRL-SHIFT B')
$xmlWriter.WriteElementString('EnableClipboardMonitor', 'true')
$xmlWriter.WriteElementString('OnInboundCall', 'NoNotify')
$xmlWriter.WriteElementString('ShowPopupInboundCall', 'WhileRinging')
$xmlWriter.WriteElementString('UrlSetName', 'TELEFOONLIJST')
$xmlWriter.WriteElementString('ShowMonitorsGrouped', 'true')
$xmlWriter.WriteElementString('FollowOwnMaGroup', 'false')
$xmlWriter.WriteElementString('MaDefaultGroup', $mijngroep)
$xmlWriter.WriteElementString('EnableMultipleColumns', 'false')
$xmlWriter.WriteElementString('ShowEmptyGroups', 'false')
$xmlWriter.WriteElementString('ContactClickAction', 'Dial')
$xmlWriter.WriteElementString('ContactSingleClick', 'false')
$xmlWriter.WriteElementString('ShowServiceDeskQueue', 'false')
$xmlWriter.WriteElementString('EnableAnswerHotkey', 'false')
$xmlWriter.WriteElementString('EnableAnswerHotkeyWhenFocussed', 'true')
$xmlWriter.WriteElementString('AnswerHotkey', 'NULL VK_0')
$xmlWriter.WriteElementString('AnswerHotkeyWhenFocussed', 'NULL m')
$xmlWriter.WriteElementString('PickupOnPhonePickup', 'false')
$xmlWriter.WriteElementString('LanguageCode', 'Dutch')
$xmlWriter.WriteElementString('TbQueueCallRing', 'OnPhone')
$xmlWriter.WriteElementString('OnTelURI', 'Disabled')
$xmlWriter.WriteEndElement()
##### Start of MonitoredUSers
$xmlWriter.WriteStartElement('MonitoredUsers')
Foreach ($line in get-Content $Config)
{
$Split = $line.split(";")
$ConfigPhone = $Split[0]
$ConfigName = $Split[1]
$ConfigDepartment = $Split[2]
#Write-host $ConfigPhone
If ($ConfigDepartment -like "Directie")
{$Department = $directie
}
If ($ConfigDepartment -like "Sales")
{$Department = $sales
}
If ($ConfigDepartment -like "After Sales")
{$Department = $aftersales
}
If ($ConfigDepartment -like "DealerDevelopment")
{$Department = $dealerdevelopment
}
If ($ConfigDepartment -like "Finance")
{$Department = $finance
}
If ($ConfigDepartment -like "Marketing")
{$Department = $marketing
}
If ($ConfigDepartment -like "ICT")
{$Department = $ICT
}
If ($ConfigDepartment -like "Overig")
{$Department = $overig
}
If ($ConfigDepartment -like "Groepen")
{$Department = $groepen
}
$xmlWriter.WriteStartElement('MonitoredUser')
$ordercnt = $ordercnt+1
$i++
$uniqueID = $uniqueID + $i
$XmlWriter.WriteAttributeString('ID', ($uniqueID))
$xmlWriter.WriteStartElement('UserId')
$XmlWriter.WriteAttributeString('IdType', 'PrimaryPhoneNumber')
$XmlWriter.WriteAttributeString('ID', $ConfigPhone)
$xmlWriter.WriteEndElement()
$xmlWriter.WriteStartElement('MonitorInfo')
$xmlWriter.WriteElementString('PcaUniqueId', $ConfigPhone)
$xmlWriter.WriteElementString('IdGroup', $Department)
$xmlWriter.WriteElementString('Label', $ConfigName)
$xmlWriter.WriteElementString('Order', $ordercnt)
$xmlWriter.WriteElementString('LastUsedMsgType', 'Unknown')
$xmlWriter.WriteElementString('Hidden', 'false')
$xmlWriter.WriteElementString('ShowLineNr', $ConfigPhone)
$xmlWriter.WriteEndElement()
$xmlWriter.WriteEndElement()
}
$xmlWriter.WriteEndElement() ##### End of MonitoredUsers
##### Start of MonitoredUsersGroups
$xmlWriter.WriteStartElement('MonitoredUsersGroups')
$xmlWriter.WriteStartElement('MonitoredUsersGroup')
$XmlWriter.WriteAttributeString('ID', $self)
$xmlWriter.WriteStartElement('GroupInfo')
$xmlWriter.WriteElementString('Label', 'Self')
$xmlWriter.WriteElementString('Order', '1')
$xmlWriter.WriteElementString('GroupType', 'Self')
$xmlWriter.WriteElementString('GroupBgColor', '65536')
$xmlWriter.WriteElementString('ButtonBgColor', '65536')
$xmlWriter.WriteElementString('ShowMembers', 'NotHidden')
$xmlWriter.WriteElementString('Public', 'false')
$xmlWriter.WriteEndElement()
$xmlWriter.WriteEndElement()
# $xmlWriter.WriteEndElement()
$xmlWriter.WriteStartElement('MonitoredUsersGroup')
$XmlWriter.WriteAttributeString('ID', $mijngroep)
$xmlWriter.WriteStartElement('GroupInfo')
$xmlWriter.WriteElementString('Label', 'Mijn Groep')
$xmlWriter.WriteElementString('Order', '2')
$xmlWriter.WriteElementString('GroupType', 'MaOwnGroup')
$xmlWriter.WriteElementString('GroupBgColor', '65536')
$xmlWriter.WriteElementString('ButtonBgColor', '65536')
$xmlWriter.WriteElementString('ShowMembers', 'All')
$xmlWriter.WriteElementString('Public', 'false')
$xmlWriter.WriteEndElement()
$xmlWriter.WriteEndElement()
$xmlWriter.WriteStartElement('MonitoredUsersGroup')
$XmlWriter.WriteAttributeString('ID', $directie)
$xmlWriter.WriteStartElement('GroupInfo')
$xmlWriter.WriteElementString('Label', 'Directie')
$xmlWriter.WriteElementString('Order', '3')
$xmlWriter.WriteElementString('GroupType', 'Other')
$xmlWriter.WriteElementString('GroupBgColor', '65536')
$xmlWriter.WriteElementString('ButtonBgColor', '65536')
$xmlWriter.WriteElementString('ShowMembers', 'None')
$xmlWriter.WriteElementString('Public', 'false')
$xmlWriter.WriteEndElement()
$xmlWriter.WriteEndElement()
$xmlWriter.WriteStartElement('MonitoredUsersGroup')
$XmlWriter.WriteAttributeString('ID', $sales)
$xmlWriter.WriteStartElement('GroupInfo')
$xmlWriter.WriteElementString('Label', 'Sales')
$xmlWriter.WriteElementString('Order', '4')
$xmlWriter.WriteElementString('GroupType', 'Other')
$xmlWriter.WriteElementString('GroupBgColor', '65536')
$xmlWriter.WriteElementString('ButtonBgColor', '65536')
$xmlWriter.WriteElementString('ShowMembers', 'None')
$xmlWriter.WriteElementString('Public', 'false')
$xmlWriter.WriteEndElement()
$xmlWriter.WriteEndElement()
$xmlWriter.WriteStartElement('MonitoredUsersGroup')
$XmlWriter.WriteAttributeString('ID', $aftersales)
$xmlWriter.WriteStartElement('GroupInfo')
$xmlWriter.WriteElementString('Label', 'Ownership Experience')
$xmlWriter.WriteElementString('Order', '5')
$xmlWriter.WriteElementString('GroupType', 'Other')
$xmlWriter.WriteElementString('GroupBgColor', '65536')
$xmlWriter.WriteElementString('ButtonBgColor', '65536')
$xmlWriter.WriteElementString('ShowMembers', 'None')
$xmlWriter.WriteElementString('Public', 'false')
$xmlWriter.WriteEndElement()
$xmlWriter.WriteEndElement()
$xmlWriter.WriteStartElement('MonitoredUsersGroup')
$XmlWriter.WriteAttributeString('ID', $dealerdevelopment)
$xmlWriter.WriteStartElement('GroupInfo')
$xmlWriter.WriteElementString('Label', 'Retail Management')
$xmlWriter.WriteElementString('Order', '6')
$xmlWriter.WriteElementString('GroupType', 'Other')
$xmlWriter.WriteElementString('GroupBgColor', '65536')
$xmlWriter.WriteElementString('ButtonBgColor', '65536')
$xmlWriter.WriteElementString('ShowMembers', 'None')
$xmlWriter.WriteElementString('Public', 'false')
$xmlWriter.WriteEndElement()
$xmlWriter.WriteEndElement()
$xmlWriter.WriteStartElement('MonitoredUsersGroup')
$XmlWriter.WriteAttributeString('ID', $finance)
$xmlWriter.WriteStartElement('GroupInfo')
$xmlWriter.WriteElementString('Label', 'Finance')
$xmlWriter.WriteElementString('Order', '7')
$xmlWriter.WriteElementString('GroupType', 'Other')
$xmlWriter.WriteElementString('GroupBgColor', '65536')
$xmlWriter.WriteElementString('ButtonBgColor', '65536')
$xmlWriter.WriteElementString('ShowMembers', 'None')
$xmlWriter.WriteElementString('Public', 'false')
$xmlWriter.WriteEndElement()
$xmlWriter.WriteEndElement()
$xmlWriter.WriteStartElement('MonitoredUsersGroup')
$XmlWriter.WriteAttributeString('ID', $marketing)
$xmlWriter.WriteStartElement('GroupInfo')
$xmlWriter.WriteElementString('Label', 'Marketing')
$xmlWriter.WriteElementString('Order', '8')
$xmlWriter.WriteElementString('GroupType', 'Other')
$xmlWriter.WriteElementString('GroupBgColor', '65536')
$xmlWriter.WriteElementString('ButtonBgColor', '65536')
$xmlWriter.WriteElementString('ShowMembers', 'None')
$xmlWriter.WriteElementString('Public', 'false')
$xmlWriter.WriteEndElement()
$xmlWriter.WriteEndElement()
$xmlWriter.WriteStartElement('MonitoredUsersGroup')
$XmlWriter.WriteAttributeString('ID', $ICT)
$xmlWriter.WriteStartElement('GroupInfo')
$xmlWriter.WriteElementString('Label', 'ICT')
$xmlWriter.WriteElementString('Order', '9')
$xmlWriter.WriteElementString('GroupType', 'Other')
$xmlWriter.WriteElementString('GroupBgColor', '65536')
$xmlWriter.WriteElementString('ButtonBgColor', '65536')
$xmlWriter.WriteElementString('ShowMembers', 'None')
$xmlWriter.WriteElementString('Public', 'false')
$xmlWriter.WriteEndElement()
$xmlWriter.WriteEndElement()
$xmlWriter.WriteStartElement('MonitoredUsersGroup')
$XmlWriter.WriteAttributeString('ID', $overig)
$xmlWriter.WriteStartElement('GroupInfo')
$xmlWriter.WriteElementString('Label', 'Overig')
$xmlWriter.WriteElementString('Order', '10')
$xmlWriter.WriteElementString('GroupType', 'Other')
$xmlWriter.WriteElementString('GroupBgColor', '65536')
$xmlWriter.WriteElementString('ButtonBgColor', '65536')
$xmlWriter.WriteElementString('ShowMembers', 'None')
$xmlWriter.WriteElementString('Public', 'false')
$xmlWriter.WriteEndElement()
$xmlWriter.WriteEndElement()
$xmlWriter.WriteStartElement('MonitoredUsersGroup')
$XmlWriter.WriteAttributeString('ID', $groepen)
$xmlWriter.WriteStartElement('GroupInfo')
$xmlWriter.WriteElementString('Label', 'Groepen')
$xmlWriter.WriteElementString('Order', '11')
$xmlWriter.WriteElementString('GroupType', 'Other')
$xmlWriter.WriteElementString('GroupBgColor', '65536')
$xmlWriter.WriteElementString('ButtonBgColor', '65536')
$xmlWriter.WriteElementString('ShowMembers', 'None')
$xmlWriter.WriteElementString('Public', 'false')
$xmlWriter.WriteEndElement()
$xmlWriter.WriteEndElement()
$xmlWriter.WriteStartElement('MonitoredUsersGroup')
$XmlWriter.WriteAttributeString('ID', $Gemistegesprekken)
$xmlWriter.WriteStartElement('GroupInfo')
$xmlWriter.WriteElementString('Label', 'Gemiste gesprekken')
$xmlWriter.WriteElementString('Order', '12')
$xmlWriter.WriteElementString('GroupType', 'MissedCalls')
$xmlWriter.WriteElementString('GroupBgColor', '65536')
$xmlWriter.WriteElementString('ButtonBgColor', '65536')
$xmlWriter.WriteElementString('ShowMembers', 'All')
$xmlWriter.WriteElementString('Public', 'false')
$xmlWriter.WriteEndElement()
$xmlWriter.WriteEndElement()
$xmlWriter.WriteEndElement()
$xmlWriter.WriteEndElement()
$xmlWriter.WriteEndDocument()
$xmlWriter.Flush()
$xmlWriter.Close()
$a = '<?xml version="1.0" encoding="utf-8"?>'
$b = '<?xml version="1.0" encoding="UTF-8" ?>'
((Get-Content $NEW_XML) -replace [regex]::Escape($a), $b ) | Set-Content $NEW_XML
}
$TestPath = Test-Path $ORG_XML
If ($TestPath -eq $False)
{
Write-host "No XML for $displayName and has PhoneNumber:$ipphone" -ForegroundColor red
}
}
Get-Content -Path $ExportDir\*.xml -OutBuffer 1000000000 | Select-String "<MonitoredUser ID=" -List |Out-File $ScriptDir\peter.txt
$Inhoud = Get-Content $ScriptDir\peter.txt | Group-Object | Where-Object { $_.Count -gt 1 } | Select -ExpandProperty Name
Write-Host $Inhoud
If ($Inhoud -ne ''){
Write-host "XML Is not working. Duplicate ID numbers" -ForegroundColor Yellow
$a = new-object -comobject wscript.shell
$b = $a.popup(“WARNING XML is not working in peter Connect. Duplicated ID“,0,”Warning”,1)
}
Remove-Item $ScriptDir\peter.txt
[void](Read-Host 'Press Enter to continue…')
[void]($Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown'))