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, ConvertTo-SortedSidecar 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' #Displaying directories on sidecar to the user: Write-Output "These are the current directories listed on the sidecar: " $CurrentDirsListed = $FileContent.SelectNodes("//busyLampFields/busyLampField") $SortedDirs = $CurrentDirsListed | Sort-Object -Property label foreach($dir in $SortedDirs) { $dir.index + ":`t" + $dir.label } 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 "Label to be shown on the sidecar (i.e. John-1234)" #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) [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 $SortedPath = "C:\users\$env:USERNAME\Desktop\Sorted.xml" $SortedXML = [xml](Get-Content $SortedPath) Write-Verbose "Sending SOAP request to add user to the sidecar" -verbose Update-Sidecar $SortedXML $DeviceName }#PROCESS END{} } |