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 "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) if($FileContent.SelectNodes("//associatedblfsdFeatures")) { $Feature = "Pickup" #Create new associatedblfsdFeaturesElement, add to the busyLampField Elemnt $BLFAssociatedFeature = $FileContent.CreateElement("associatedBlfSdFeatures") [void]$NewBLFNode.AppendChild($BLFAssociatedFeature) #Create the feature element, add corresponding text, and append to the associatedfeature element. $BLFFeature = $FileContent.CreateElement("feature") $FeatureText =$FileContent.CreateTextNode($Feature) [void]$BLFFeature.AppendChild($FeatureText) [void]$BLFAssociatedFeature.AppendChild($BLFFeature) } #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 $FileName $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 $CUCMServer }#PROCESS END{} } |