CUCMSidecarWorkflow/Private/Add-UserToSidecar.ps1
|
function Add-UserToSidecar { <# .SYNOPSIS Adds a directory to the specified device given in Get-DeviceInfo. .DESCRIPTION Add-UserToSideCar prompts the user to enter the directory number and label of the person being added to the sidecar. It then adds the information to the XML document produced from the Get-DeviceInfo function. Once added, Sort-BusyLampFields is called. Follwing that, Update-SideCar is called, completeing the addition to the sidecar. .PARAMETER FileName The same XML document from Get-DeviceInfo. #> [CmdletBinding()] Param( [Parameter(Mandatory = $true)] [string]$FileName ) BEGIN{} PROCESS { #The XML to be read and a standard element needed for the API call. $FileContent = [xml](Get-Content $FileName) $DefaultRoutePartition = 'Internal_DN-PT' Write-Output "Please enter the folowing information: " $DirToAdd = Read-Host "Extension (e.g Directory Number) of the person to be added (i.e. 1234)" $LabelToAdd = Read-Host "Person's name to be shown on sidecar" #creating new Busy Lamp Field Element $NewBLFNode = $FileContent.CreateElement("busyLampField") #Creating new blfdirn in newBLFNode $BLFDirn = $FileContent.CreateElement("blfDirn") $BLFDirnText = $FileContent.CreateTextNode($DirToAdd) [void]$BLFDirn.AppendChild($BLFDirnText) [void]$NewBLFNode.AppendChild($BLFDirn) #Creating route partition for new BLFNode $BLFPartition = $FileContent.CreateElement("routePartition") $PartitionText = $FileContent.CreateTextNode($DefaultRoutePartition) [void]$BLFPartition.AppendChild($PartitionText) [void]$NewBLFNode.AppendChild($BLFPartition) #Creating label for the new BLFNode $BLFLabel = $FileContent.CreateElement("label") $LabelText = $FileContent.CreateTextNode($LabelToAdd + "-" + $DirToAdd) [void]$BLFLabel.AppendChild($LabelText) [void]$NewBLFNode.AppendChild($BLFLabel) #add whole node to xml doc $ParentNode = $FileContent.SelectSingleNode("//busyLampFields") [void]$ParentNode.AppendChild($NewBLFNode) [void]$FileContent.Save($FileName) #Remove indicies of BLFs in order to sort, and insert alphabetically for SOAP request $BLFIndecies = $FileContent.SelectNodes("//busyLampFields/busyLampField/index") foreach($BLFIindex in $BLFIndecies) { $RemoveIndex = $FileContent.SelectSingleNode("//busyLampField/index") [void]$RemoveIndex.ParentNode.RemoveChild($RemoveIndex) } [void]$FileContent.Save($FileName) ConvertTo-SortedSidecar $FileContent $SortedFile = "C:\users\$env:USERNAME\Desktop\Sorted.xml" $SortedDoc = [xml](Get-Content $SortedFile) Write-Verbose "Sending SOAP request to add user to the sidecar" -verbose Update-Sidecar $SortedDoc $DeviceName Show-SortedSidecar $SortedFile }#PROCESS END{} } |