Most Valued User Kaleidoscope Posted November 20, 2017 Most Valued User #1 Share Posted November 20, 2017 Hey everyone, we were looking for a way to give users to possibility to configure call forwards for a group. We quickly realized that we needed to write something quick and dirty in powershell. If there are other ways to set call forwards for a group please let me know! This is by no means complete and this is far from elegant code! There are no error checks, configuration is completely done in the code (see the button sections) and I ABSOLUTELY DON'T GIVE ANY GUARANTEES that your server doesn't catch fire when running it! So please use that at your own risk! It does the trick for me, so maybe someone finds this useful and uses it as a starting point for greater things! Cheers! ################################################################################# Import-Module ippbx Connect-IpPbx -ServerName "your_swyx_server_here.local" Add-Type -AssemblyName System.Windows.Forms ################################################################################# # get the ID of the user/group you want to control by # Get-IpPbxUser -UserName "Username" ################################################################################# $pbxuserid = 999 # CHANGEME $pbxuser = Get-IpPbxUser -UserId $pbxuserid $pbxusername = $pbxuser.Name $pbxinternal = Get-IpPbxInternalNumber -UserName $pbxusername $pbxusernumber = $pbxinternal.Number ################################################################################# function CreateLabel2Text { $tmppbxuser= Get-IpPbxUser -UserId $pbxuserid $fwdno = $tmppbxuser.DefaultFwdNum $forwardowner = Get-IpPbxNumberOwner -Number "${fwdno}" $forwardname = $forwardowner.Name if ($forwardname) { $label2.Text = "==> $forwardname - ${fwdno}" } else { $label2.Text = "==> ${fwdno}" } } ################################################################################# function ChangeCallForward($fwdno) { Get-IpPbxUser -UserId $pbxuserid | ForEach-Object { $_.DefaultFwd = 1; $_.DefaultFwdNum = $fwdno; $_ } | Update-IpPbxUser CreateLabel2Text $Form.Refresh() } ################################################################################# $Form = New-Object system.Windows.Forms.Form $Form.Text = "SWYX Call Forward" $Form.TopMost = $true $Form.Width = 480 $Form.Height = 400 ################################################################################# $buttonA1 = New-Object system.windows.Forms.Button $buttonA1.Text = "Label A1" $buttonA1.Width = 200 $buttonA1.Height = 30 $buttonA1.location = new-object system.drawing.point(20,100) $buttonA1.Font = "Microsoft Sans Serif,10" $buttonA1.Add_Click({ChangeCallForward(1234)}) $Form.controls.Add($buttonA1) $buttonA2 = New-Object system.windows.Forms.Button $buttonA2.Text = "Label A2" $buttonA2.Width = 200 $buttonA2.Height = 30 $buttonA2.location = new-object system.drawing.point(20,140) $buttonA2.Font = "Microsoft Sans Serif,10" $buttonA2.Add_Click({ChangeCallForward("5678")}) $Form.controls.Add($buttonA2) $buttonA3 = New-Object system.windows.Forms.Button $buttonA3.Text = "Label A3" $buttonA3.Width = 200 $buttonA3.Height = 30 $buttonA3.location = new-object system.drawing.point(20,180) $buttonA3.Font = "Microsoft Sans Serif,10" $buttonA3.Add_Click({ChangeCallForward('+49-123-456')}) $Form.controls.Add($buttonA3) $buttonA4 = New-Object system.windows.Forms.Button $buttonA4.Text = "Label A4" $buttonA4.Width = 200 $buttonA4.Height = 30 $buttonA4.location = new-object system.drawing.point(20,220) $buttonA4.Font = "Microsoft Sans Serif,10" $buttonA4.Add_Click({ChangeCallForward('')}) $Form.controls.Add($buttonA4) $buttonA5 = New-Object system.windows.Forms.Button $buttonA5.Text = "Label A5" $buttonA5.Width = 200 $buttonA5.Height = 30 $buttonA5.location = new-object system.drawing.point(20,260) $buttonA5.Font = "Microsoft Sans Serif,10" $buttonA5.Add_Click({ChangeCallForward('')}) $Form.controls.Add($buttonA5) ################################################################################# $buttonB1 = New-Object system.windows.Forms.Button $buttonB1.Text = "Label B1" $buttonB1.Width = 200 $buttonB1.Height = 30 $buttonB1.location = new-object system.drawing.point(240,100) $buttonB1.Font = "Microsoft Sans Serif,10" $buttonB1.Add_Click({ChangeCallForward('')}) $buttonB1.enabled = $false $Form.controls.Add($buttonB1) $buttonB2 = New-Object system.windows.Forms.Button $buttonB2.Text = "Label B2" $buttonB2.Width = 200 $buttonB2.Height = 30 $buttonB2.location = new-object system.drawing.point(240,140) $buttonB2.Font = "Microsoft Sans Serif,10" $buttonB2.Add_Click({ChangeCallForward('')}) $buttonB2.enabled = $false $Form.controls.Add($buttonB2) $buttonB3 = New-Object system.windows.Forms.Button $buttonB3.Text = "Label B3" $buttonB3.Width = 200 $buttonB3.Height = 30 $buttonB3.location = new-object system.drawing.point(240,180) $buttonB3.Font = "Microsoft Sans Serif,10" $buttonB3.Add_Click({ChangeCallForward('')}) $buttonB3.enabled = $false $Form.controls.Add($buttonB3) $buttonB4 = New-Object system.windows.Forms.Button $buttonB4.Text = "Label B4" $buttonB4.Width = 200 $buttonB4.Height = 30 $buttonB4.location = new-object system.drawing.point(240,220) $buttonB4.Font = "Microsoft Sans Serif,10" $buttonB4.Add_Click({ChangeCallForward('')}) $buttonB4.enabled = $false $Form.controls.Add($buttonB4) $buttonB5 = New-Object system.windows.Forms.Button $buttonB5.Text = "Label B5" $buttonB5.Width = 200 $buttonB5.Height = 30 $buttonB5.location = new-object system.drawing.point(240,260) $buttonB5.Font = "Microsoft Sans Serif,10" $buttonB5.Add_Click({ChangeCallForward('')}) $buttonB5.enabled = $false $Form.controls.Add($buttonB5) ################################################################################# $label1 = New-Object system.windows.Forms.Label $label1.Text = "$pbxusername $pbxusernumber" $label1.AutoSize = $true $label1.Width = 25 $label1.Height = 10 $label1.location = new-object system.drawing.point(20,20) $label1.Font = "Microsoft Sans Serif,10,style=Bold" $Form.controls.Add($label1) $label2 = New-Object system.windows.Forms.Label $label2.Text = "Rufnummer 6143" $label2.ForeColor = "#0c8000" $label2.AutoSize = $true $label2.Width = 25 $label2.Height = 10 $label2.location = new-object system.drawing.point(20,40) $label2.Font = "Microsoft Sans Serif,10,style=Bold" $Form.controls.Add($label2) ################################################################################# CreateLabel2Text [void]$Form.ShowDialog() $Form.Dispose() Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.