none
SfB Conference Line Automation Powershell Script; Trouble with finding existing LineURIs RRS feed

  • Question

  • Hi all. I am not sure if this is the right subforum, I could not find anything that more closely matched what I am doing.

    I am working on a script to automate provisioning conference policies. I have run into a bit of trouble when I am trying to check to see if the phone number provided is used by another. I have the code to find it, and it works if you pass it a string. However if you pass it the variable that contains the same thing as the string it starts returning what seems like every user in the company. If I try to run it with the variable while logged into the server it works, which really has me scratching my head.

    I sanitized the information, but the rest of the script is working except for the "Get-CsUser -filter { LineURI -like $fNumber}" line.

    Problem function:

    function validateNumber($number){
    	if($number -match "^\d+$"){
    		if ([convert]::ToString($number).length -eq 10)
    		{
    			$fNumber = "tel:+" + $number + ";ext=" + $number.Substring(5)
    			write-host $fNumber
    			write-host "tel:+number;ext=extension"
    			Get-CsUser -filter { LineURI -like "tel:+number;ext=extension"} #works returning only the user with this number
    			Get-CsUser -filter { LineURI -like $fNumber} #returns tons of users that don't match this string
    			
    		}
    		else{
    		write-host "Number is not valid, try again"
    	        }
    	}
    	else{
    		write-host "Number is not valid, try again"
    	}
    }

    The entire script

    ##Script to automate SFB conference line set ups.
    
    ##Function declarations
    function testUser($name){
    	[hashtable]$Return = @{}
    	$error = ""
    	$valid = $TRUE
    	
    	$exists = [bool](Get-ADUser -Filter {SamAccountName -eq $name})
    	if (!$exists){
    		$error = "User does not exist, please check the name and try again"
    		$valid = $FALSE
    		}
    	else{
    		[string]$sip = Get-CsAdUser -identity "Domain\$user" | select SipAddress	
    		if ($sip -like '*domain.com*'){
    			##Validate there is no assigned conference policy already. 
    			[string]$confPolicy = Get-CsUser domain\$user | select -ExpandProperty conferencing* | select FriendlyName
    			if(![string]::IsNullOrEmpty($confPolicy)){
    				$error = "Client already has a conferencing policy applied. Contact client for specifics of the issue."
    				$valid = $FALSE}
    			}
    		else{
    			$error = "Client has the old SIP address. Pass ticket to Wintel to update SIP and set up conferencing."
    			$valid = $FALSE}
    		}
    	
    	$Return.valid = $valid
    	$Return.error = $error
    	
    	Return $Return
    }
    
    function connect(){
    	##create session to SfB server
    	$cred = Get-Credential "domain\adminaccount"
    	$session = New-PSSession -ConnectionURI "serverURL" -Credential $cred
    	Import-PSSession $session
    	Import-Module ActiveDirectory 
    }
    
    function validateNumber($number){
    	if($number -match "^\d+$"){
    		if ([convert]::ToString($number).length -eq 10)
    		{
    			$fNumber = "tel:+" + $number + ";ext=" + $number.Substring(5)
    			write-host $fNumber
    			write-host "tel:+number;ext=extension"
    			Get-CsUser -filter { LineURI -like "tel:+number;ext=extension"} #works returning only the user with this number
    			Get-CsUser -filter { LineURI -like $fNumber} #returns tons of users that don't match this string
    			
    		}
    		else{
    		write-host "Number is not valid, try again"
    	}
    	}
    	else{
    		write-host "Number is not valid, try again"
    	}
    }
    
    #Main
    	connect
    	
    	$user = read-host -prompt 'Enter the username to be set up'
    	$data = testUser($user)
    	
    	if ($data.valid){
    		
    	}
    	else{
    		write-host $data.error
    	}
    
    	$phoneNumber = read-host -prompt 'Enter the phone number to tie to the account. (XXXXXXXXXX)'
    	#Grant-CsConferencingPolicy -identity domain\$user -PolicyName "Dialin Test Policy"	
    	validateNumber($phoneNumber)
    	
    	<#
    	Set-CsUser -Identity domain\$user -LineUri $formattedNumber
    
    	[string]$confPolicy = Get-CsUser domain\$user | select -ExpandProperty conferencing* | select FriendlyName
    		if(![string]::IsNullOrEmpty($confPolicy)){
    		write-host "Conferencing policy for $user has been updated"
    		}
    		#>
    		
    	Get-PSSession | Remove-PSSession
    
    

    Wednesday, May 22, 2019 3:47 PM