Param ( [Parameter (Mandatory= $true)] [String] $upn, [Parameter (Mandatory= $true)] [String] $Location ) #replace with your automation credential $cred = Get-AutomationPSCredential -Name "Cred" $Session = New-CsOnlineSession -Credential $cred Import-PsSession $Session -AllowClobber -DisableNameChecking | Out-Null #Number Allocation By Site add ones that relate to your form so that the system knows which area number to assign to the user if($Location -ieq "UKREM"){ $StartNumber = "441270" } if($Location -ieq "UKHO"){ $StartNumber = "440208" } if($Location -ieq "UKPME"){ $StartNumber = "44121" } #Get Location ID $LocationID = Get-CsOnlineLisLocation | Where {$_.Description -ieq $Location} | Select $LocationID #Get Free Number $MyNumber = Get-CsOnlineTelephoneNumber -InventoryType Subscriber -IsNotAssigned -TelephoneNumberStartsWith $StartNumber | Select -First 1 #Assign to User $SetUser = Set-CsOnlineVoiceUser -Identity $upn -TelephoneNumber $MyNumber.Id -LocationID $LocationID.LocationID.GUID #Assign some more policies here #Output Get-PSSession | ? ComputerName -like "*lync*" | Remove-PsSession $output = @() $output += New-Object -TypeName psobject -Property @{upn = $upn; phone= "+$($MyNumber.Id)"} Write-Output $output | ConvertTo-Json