forked from plessisa/RibbonEdgePsRest
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Posh-Ribbon.psm1
3124 lines (2386 loc) · 123 KB
/
Posh-Ribbon.psm1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<#
.SYNOPSIS
Posh-Ribbon Powershell module allows access to Ribbon SBC Edge via PowerShell using REST API's.
.DESCRIPTION
For the module to run correctly following pre-requisites should be met:
1) Powershell 7 OR latest version PowerShell v5.1 (5.1 will be phased out at a future date)
2) Ribbon SBC Edge on R3.0 or higher ( Tested on SBC R8.0 )
3) Create REST logon credentials (https://support.sonus.net/display/UXDOC50/Managing+Local+Users)
Once you have created the account use help Connect-UxGateway to get started.
.NOTES
Name: RibbonEdge
V3 Author: Chris Burns (PoshDev)
V2 Author: Chris Burns (GCIcom)
V1 Author: Vikas Jaswal (Modality Systems Ltd)
Additional cmdlets added by: Kjetil Lindløkken
Additional cmdlets added by: Adrien Plessis
Version History:
Version 3.0 - 29/Apr/21 - Updated to allow use with Powershell 7 and Powershell 5 ( Fixes include XML parser and Certificate policy)
Version 2.1 - 25/04/19 - Updated with some more Get and New Commands especially Call Routing Table - Chris Burns
Version 2.0 - 15/04/19 - *NEW Version* - Rewrite for modern module design, better use of [XML] accelerator and details switch,
a new custom uxSession Object to allow for access to multiple SBC's at once and a Custom XML -> PSObject Parser - Chris Burns
Version 1.7 - 20/12/18 - Match Ribbon rebranding, Update link to Ribbon Docs - Adrien Plessis
Version 1.6 - 04/10/18 - Added new-uxsipprofile cmdlet - Kjetil Lindløkken
Version 1.5 - 03/10/18 - Added optional parameter to the get-uxsipprofile cmdlet to add id directly - Kjetil Lindløkken
Version 1.4 - 03/10/18 - Added new-uxsipserverentry cmdlet - Kjetil Lindløkken
Version 1.3 - 02/10/18 - Added get-uxsipprofile, Get-uxsipprofileid, get-uxsipservertableentry cmdlets - Kjetil Lindløkken
Version 1.2 - 02/10/16 - Added get-uxsipservertable, new-uxsippservertable cmdlets - Kjetil Lindløkken
Version 1.1 - 03/12/13 - Added new-ux*, restart-ux*, and get-uxresource cmdlets - Vikas Jaswal
Version 1.0 - 30/11/13 - Module Created - Vikas Jaswal
Please use the script at your own risk!
.LINK
http://www.posh.dev
#>
Function Connect-UxGateway {
<#
.SYNOPSIS
This cmdlet connects to the Ribbon SBC and extracts the session token and places it into a custom PS Object called uxSession
.DESCRIPTION
This cmdlet connects to the Ribbon SBC and extracts the session token required for subsequent cmdlets.
All other cmdlets will fail if this command is not successfully executed.
.PARAMETER uxhostname
Enter here the hostname or IP address of the Ribbon SBC
.PARAMETER credentials
Pass a secure credential to the cmdlet, this should be your REST API credentials.
.PARAMETER SkipCertCheck
Use this switch to tell the cmdlet that you will be connecting to an SBC without a valid certificate
.EXAMPLE
$Creds = Get-credential
connect-uxgateway -uxhostname 1.1.1.1 -Credentials $Creds -SkipCertCheck
.EXAMPLE
$Creds = Get-credential
connect-uxgateway -uxhostname lyncsbc01.COMPANY.co.uk -Credentials $Creds
.EXAMPLE
$Creds = Get-credential
$Session1 = connect-uxgateway -uxhostname lyncsbc01.COMPANY.co.uk -Credentials $Creds -SkipCertCheck
$Session2 = connect-uxgateway -uxhostname lyncsbc02.COMPANY.co.uk -Credentials $Creds -SkipCertCheck
#>
[cmdletbinding()]
Param(
[Parameter(Mandatory = $true, Position = 0)]
[string]$uxhostname,
# The Rest API Credentials to get into the SBC
[Parameter(Mandatory = $true, Position = 1)]
[pscredential]$Credentials,
[Parameter(Mandatory = $false, Position = 1)]
[switch]$SkipCertCheck
)
# We need a check here to determine the host version
# we do this as ignoring certificate issues is handeled differently in version 7 and version 5
if($PSVersionTable.psversion.Major -gt 5) {$PSCore = $true} else {$PSCore = $false}
#[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy
if($SkipCertCheck){
if (!($pscore)) {
#Ignore SSL, without this GET commands dont work with SBC Edge
add-type @"
using System.Net;
using System.Security.Cryptography.X509Certificates;
public class TrustAllCertsPolicy : ICertificatePolicy {
public bool CheckValidationResult(
ServicePoint srvPoint, X509Certificate certificate,
WebRequest request, int certificateProblem) {
return true;
}
}
"@
#Force TLS1.2
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
}
}
$null = $Session
#Login to SBC Edge
$AuthenticationString = "Username={0}&Password={1}" -f $Credentials.GetNetworkCredential().username, $Credentials.GetNetworkCredential().password
$url = "https://$uxhostname/rest/login"
Try {
if($pscore -and $SkipCertCheck){
$uxcommand1output = Invoke-RestMethod -Uri $url -Method Post -Body $AuthenticationString -SessionVariable Session -ErrorAction Stop -SkipCertificateCheck
}else{
$uxcommand1output = Invoke-RestMethod -Uri $url -Method Post -Body $AuthenticationString -SessionVariable Session -ErrorAction Stop
}
}
Catch {
throw "$uxhostname - Unable to connect. Verify host is accessible on the network and check if you have ignored selfsigned certificates if needed. The error message returned is $_"
}
#$Result = ([xml]$uxcommand1output.trim()).root
$Result = ([xml]$($uxcommand1output.trim())).root
$Success = $Result.status.http_code
Write-verbose "Response Code = $Success"
#Check if the Login was successfull.HTTP code 200 is returned if login is successful
If ( $Success -ne "200") {
#Unable to Login
Write-verbose $uxcommand1output.trim()
throw "$uxhostname - Login unsuccessful, logon credentials are incorrect OR you may not be using REST Credentials."
}
Write-Information "Successfully connected to $uxhostname"
Write-verbose $uxcommand1output.trim()
$script:DefaultSession = [PSCustomObject]@{
host = $uxhostname
session = $Session
credentials = $Credentials
powershellVer = $PSVersionTable.psversion.Major
pscore = $pscore
ignoreCert = $SkipCertCheck
DefaultSessionType = $true
}
$DefaultSession.PSObject.TypeNames.Insert(0, "UX.SBCSessionObject")
$ReturnObject = [PSCustomObject]@{
host = $uxhostname
session = $Session
credentials = $Credentials
powershellVer = $PSVersionTable.psversion.Major
ignoreCert = $SkipCertCheck
pscore = $pscore
DefaultSessionType = $false # Setting this will tell future scripts if the session has been passed to them OR if it is the default session
}
$ReturnObject.PSObject.TypeNames.Insert(0, "UX.SBCSessionObject")
Return $ReturnObject
}
#Function to grab SBC Edge system information
Function Get-UxSystemInfo {
<#
.SYNOPSIS
This cmdlet collects System information from Ribbon SBC.
.EXAMPLE
get-uxSystemInfo
Gets System information from the last connected SBC.
.EXAMPLE
$Creds = Get-credential
PS:>$Obj = connect-uxgateway -uxhostname lyncsbc01.COMPANY.co.uk -Credentials $Creds
PS:>get-uxSystemInfo -uxSession $obj
This example stores the credential in a credential object and uses that credential to store a uxSession Object.
With this object we can now call the get-uxSystemInfo for any session object. Therby allowing us to get information from
any amount of SBC's.
#>
[cmdletbinding()]
Param(
#If using multiple servers you will need to pass the uxSession Object created by connect-uxGateway
#Else it will look for the last created session using the command above
[Parameter(Mandatory = $false, Position = 0)]
[PSCustomObject]$uxSession
)
Write-verbose "Called $($MyInvocation.MyCommand)"
#$resource = Get-UxResourceName -functionname $MyInvocation.MyCommand
$ResourceSplat = @{
resource = "system"
ReturnElement = "system"
}
if ($uxSession) { $ResourceSplat.uxSession = $uxSession }
get-uxresource @ResourceSplat
}
#Function to grab UX Global Call counters
Function Get-UxSystemCallStats {
<#
.SYNOPSIS
This cmdlet reports Call statistics from Ribbon SBC.
.DESCRIPTION
This cmdlet report Call statistics (global level only) from Ribbon SBC eg: Calls failed, Calls Succeeded, Call Currently Up, etc.
.EXAMPLE
get-uxsystemcallstats
.EXAMPLE
$Creds = Get-credential
PS:>$Obj = connect-uxgateway -uxhostname lyncsbc01.COMPANY.co.uk -Credentials $Creds
PS:>get-UxSystemCallStats -uxSession $obj
This example stores the credential in a credential object and uses that credential to store a uxSession Object.
With this object we can now call the get-UxSystemCallStats for any session object. Therby allowing us to get call stats from
any amount of SBC's.
#>
[cmdletbinding()]
Param(
#If using multiple servers you will need to pass the uxSession Object created by connect-uxGateway
#Else it will look for the last created session using the command above
[Parameter(Mandatory = $false, Position = 0)]
[PSCustomObject]$uxSession
)
Write-verbose "Called $($MyInvocation.MyCommand)"
#$resource = Get-UxResourceName -functionname $MyInvocation.MyCommand
$ResourceSplat = @{
resource = "systemcallstats"
ReturnElement = "systemcallstats"
}
if ($uxSession) { $ResourceSplat.uxSession = $uxSession }
get-uxresource @ResourceSplat
}
Function Get-UxSystemLog {
<#
.SYNOPSIS
This cmdlet reports the call logging level for a specified SBC.
.DESCRIPTION
This cmdlet report Call statistics (global level only) from Ribbon SBC eg: Calls failed, Calls Succeeded, Call Currently Up, etc.
.EXAMPLE
get-UxSystemLog
.EXAMPLE
$Creds = Get-credential
PS:> $Obj = connect-uxgateway -uxhostname lyncsbc01.COMPANY.co.uk -Credentials $Creds
PS:> get-UxSystemLog -uxSession $Obj
#>
[cmdletbinding()]
Param(
#If using multiple servers you will need to pass the uxSession Object created by connect-uxGateway
#Else it will look for the last created session using the command above
[Parameter(Mandatory = $false, Position = 0)]
[PSCustomObject]$uxSession
)
Write-verbose "Called $($MyInvocation.MyCommand)"
#$resource = Get-UxResourceName -functionname $MyInvocation.MyCommand
$ResourceSplat = @{
resource = "systemlog"
ReturnElement = "systemlog"
detail = $true
}
if ($uxSession) { $ResourceSplat.uxSession = $uxSession }
get-uxresource @ResourceSplat
}
#Function to backup UX. When the backup succeeds there is no acknowledgement from UX.Best way to verify backup was successful is to check the backup file size
Function Invoke-UxBackup {
<#
.SYNOPSIS
This cmdlet performs backup of Ribbon SBC
.DESCRIPTION
This cmdlet performs backup of Ribbon SBC.
Ensure to check the size of the backup file to verify the backup was successful as Ribbon does not acknowledge this.If a backup file is 1KB it means the backup was unsuccessful.
.PARAMETER backupdestination
Enter here the backup folder where the backup file will be copied. Ensure you have got write permissions on this folder.
.PARAMETER backupfilename
Enter here the Backup file name. The backup file will automatically be appended with .tar.gz extension.
.EXAMPLE
invoke-uxbackup -backupfilename c:\backup\lyncgw01backup01.tar.gz
#>
[cmdletbinding()]
Param(
[Parameter(Mandatory = $true, Position = 0)]
[PSCustomObject]$uxSession,
[Parameter(Mandatory = $true, Position = 1)]
[ValidateScript( { $Path = Split-path $_; if (!($Path | Test-path)) { Throw "Folder Must Exist" } return $true })]
[string]$backupfilename
)
if ($uxSession) {
$uxSessionObj = $uxSession
$uxHost = $uxSession.host
$SessionVar = $uxSession.Session
}
else {
$uxSessionObj = $DefaultSession
$uxHost = $DefaultSession.host
$SessionVar = $DefaultSession.session
}
# This script can be updated to use the latest Send-Command cmdlet. TODO.
#Refeshing the token, if needed
$ResponseCode = $((get-uxsysteminfo -uxSession $uxSessionObj).status.http_code)
Write-verbose "Response code from Gateway $ResponseCode"
if ($ResponseCode -ne "200") {
Throw "Session Expired or problem connecting to Box - Rerun Connect-uxGateway"
}
$args1 = ""
$url = "https://$uxHost/rest/system?action=backup"
if ($backupfilename -notmatch "(\.tar.gz)") {
$backupfilename = $backupfilename -replace "\..+"
Write-warning "The output file must be of a type tar.gz - replacing filename to $backupfilename.tar.gz"
$FileLocation = "{0}.tar.gz" -f $backupfilename
}
else {
$FileLocation = $backupfilename
}
# Lets Get the backup File and output it.
Try {
Invoke-RestMethod -Uri $url -Method POST -Body $args1 -WebSession $sessionvar -OutFile $FileLocation -ErrorAction Stop
}
Catch {
throw "Unable to process this command.Ensure you have connected to the gateway using `"connect-uxgateway`" cmdlet or if you were already connected your session may have timed out (10 minutes of no activity).The error message is $_"
}
}
#Function to return any resource (using GET)
Function Get-UxResource {
<#
.SYNOPSIS
This cmdlet makes a GET request to any valid UX resource. For full list of valid resources refer to https://support.sonus.net/display/UXAPIDOC
.DESCRIPTION
This cmdlet makes a GET request to any valid UX resource. For full list of valid resources refer to https://support.sonus.net/display/UXAPIDOC.
The cmdlet is one of the most powerful as you can query pretty much any UX resource which supports GET requests!
.PARAMETER resource
Enter a valid resource name here. For valid resource names refer to https://support.sonus.net/display/UXAPIDOC
.EXAMPLE
This example queries a "timing" resource
get-uxresource -resource timing
.EXAMPLE
This example queries a "certificate" resource
get-uxresource -resource certificate
After you know the certificate id URL using the above cmdlet, you can perform second query to find more details:
get-uxresource -resource certificate/1
.LINK
To find all the resources which can be queried, please refer to https://support.sonus.net/display/UXAPIDOC
#>
[cmdletbinding()]
Param(
[Parameter(Mandatory = $false, Position = 0)]
[PSCustomObject]$uxSession = $DefaultSession,
[Parameter(Mandatory = $true, Position = 1)]
[string]$resource,
[Parameter(Mandatory = $false, Position = 2)]
[string]$ReturnElement,
[Parameter(Mandatory = $false, Position = 3)]
[string]$Arguments,
[Parameter(Mandatory = $false, Position = 4)]
[switch]$Details,
[Parameter(Mandatory = $false, Position = 5)]
[pscredential]$Credentials
)
<#
#Region Getting Session
if ($uxSession) {
$uxSessionObj = $uxSession
$uxHost = $uxSession.host
$SessionVar = $uxSession.Session
}
else {
if ($DefaultSession) {
$uxSessionObj = $DefaultSession
$uxHost = $DefaultSession.host
$SessionVar = $DefaultSession.session
}
Else {
Throw "Unable to process this command.Ensure you have connected to the gateway using `"connect-uxgateway`" cmdlet or if you were already connected your session may have timed out (10 minutes of no activity)."
}
}
#endregion
#Region Refeshing the token, if needed
#$ResponseCode = $((get-uxsysteminfo -uxSession $uxSessionObj).status.http_code)
#Write-verbose "Response code from Gateway $ResponseCode"
#
#if ($ResponseCode -ne "200") {
# Throw "Session Expired or problem connecting to Box - Rerun Connect-uxGateway"
#}
#endregion
#>
$url = "https://$($uxSession.host)/rest/$resource"
if ($Details) {
$url += "?details=true"
}
Write-verbose "Connecting to $url"
Try {
if($($uxSession.ignoreCert) -and $($uxSession.pscore)){
$uxrawdata = Invoke-RestMethod -Uri $url -Method GET -WebSession $($uxSession.Session) -SkipCertificateCheck
}else{
$uxrawdata = Invoke-RestMethod -Uri $url -Method GET -WebSession $($uxSession.Session)
}
}
Catch {
Try {
if ($uxSession.DefaultSessionType) {
Write-Warning "Session Expired - Trying to renew session to $($uxSession.host)"
Connect-UxGateway -uxhostname $DefaultSession.host -Credentials $DefaultSession.Credentials
if($($uxSession.ignoreCert) -and $($uxSession.pscore)){
$uxrawdata = Invoke-RestMethod -Uri $url -Method GET -WebSession $($uxSession.Session) -ErrorAction Stop -SkipCertificateCheck
}else{
$uxrawdata = Invoke-RestMethod -Uri $url -Method GET -WebSession $($uxSession.Session) -ErrorAction Stop
}
}
}
catch {
#Write-Verbose $uxrawdata
if ($_.Exception -like "*(404) Not Found*") {
Throw "404 Returned - Unable to find Resource Are you requesting a valid resource?"
}
else {
throw "$_"
}
}
}
$Result = ([xml]$($uxrawdata.trim())).root
#$Result = ([xml]$uxrawdata).root
$Success = $Result.status.http_code
#Check if connection was successful.HTTP code 401 is returned which means the session has expired
If ( $Success -eq "401") {
# Lets Try again if it is the default session
Try {
if ($uxSession.DefaultSessionType) {
Write-Warning "Session Expired - Trying to renew session to $($uxSession.host)"
Connect-UxGateway -uxhostname $DefaultSession.host -Credentials $DefaultSession.Credentials
if($($uxSession.ignoreCert) -and $($uxSession.pscore)){
$uxrawdata = Invoke-RestMethod -Uri $url -Method GET -WebSession $($uxSession.Session) -ErrorAction Stop -SkipCertificateCheck
}else{
$uxrawdata = Invoke-RestMethod -Uri $url -Method GET -WebSession $($uxSession.Session) -ErrorAction Stop
}
}
}
catch {
#Unable to Login again
throw "We tried to reauthenticate and run your command again but failed, Try to rerun your command, OR use Connect-UxGateWay cmdlet again"
}
$Result = ([xml]$($uxrawdata.trim())).root
#$Result = ([xml]$uxrawdata).root
$Success = $Result.status.http_code
}
#Check if connection was successful.HTTP code 200 is returned
If ( $Success -ne "200") {
#Unable to Login
throw "Error Code $Success : Unable to process this command.Ensure you have connected to the gateway using `"connect-uxgateway`" cmdlet or if you were already connected your session may have timed out (10 minutes of no activity).The error message is $_"
}
# Return data and raw data in the verbose stream if needed.
Write-Verbose $uxrawdata
if ($ReturnElement) {
Return $Result.$ReturnElement
}
Return $Result
}
#Function to create a new resource on UX
Function New-UxResource {
<#
.SYNOPSIS
This cmdlet initiates a PUT request to create a new UX resource. For full list of valid resources refer to https://support.sonus.net/display/UXAPIDOC
.DESCRIPTION
This cmdlet initiates a a PUT request to create a new UX resource. For full list of valid resources refer to https://support.sonus.net/display/UXAPIDOC.
Using this cmdlet you can create any resource on UX which supports PUT request!
.PARAMETER resource
Enter a valid resource name here. For valid resource names refer to https://support.sonus.net/display/UXAPIDOC
.EXAMPLE
This example creates a new "sipservertable" resource
Grab the SIP Server table resource and next free available id
Get-UxResource -resource sipservertable | Select -ExpandProperty sipservertable_list | Select -ExpandProperty sipservertable_pk
Create new SIP server table and specify a free resource ID (15 here)
New-UxResource -Arguments "Description=SkypeMedServers" -resource sipservertable -index 15
OR
New-UxResource -Arguments "Description=SkypeMedServers" -resource sipservertable/15
.LINK
To find all the resources which can be queried, please refer to https://support.sonus.net/display/UXAPIDOC
#>
[cmdletbinding(SupportsShouldProcess = $True, ConfirmImpact = "High")]
Param(
# The Session Object used if wanting to connect to multiple servers
[Parameter(Mandatory = $false, Position = 0)]
[PSCustomObject]$uxSession = $DefaultSession,
# The Resource you wish to hit, such as sipservertable
[Parameter(Mandatory = $true, Position = 1)]
[string]$resource,
# Used with other cmdlets to help tidy up the XML return so the tree is not too deep.
[Parameter(Mandatory = $false, Position = 2)]
[string]$ReturnElement,
# Pass any argument that you wish to be built, such as Description=Skype
[Alias("Args", "Options", "Settings")]
[Parameter(Mandatory = $false, Position = 3)]
[string]$Arguments,
# If using a tidier method or planning on looping, you could use the Index Tag which will add to the end of the resource name /1
[Parameter(Mandatory = $true, Position = 4)]
[Int]$Index,
# Currently not used, Will be used infuture for automatic refesh tokens.
[Parameter(Mandatory = $false, Position = 5)]
[pscredential]$Credentials
)
#Region Refeshing the token, if needed
#$ResponseCode = $((get-uxsysteminfo -uxSession $uxSessionObj).status.http_code)
#Write-verbose "Response code from Gateway $ResponseCode"
#
#if ($ResponseCode -ne "200") {
# Throw "Session Expired or problem connecting to Box - Rerun Connect-uxGateway"
#}
#endregion
$url = "https://$($uxSession.host)/rest/$resource/$Index"
Write-verbose "Connecting to $url"
Write-verbose "Adding: $Arguments "
# Lets check the User Actually wants to make this change
$msg = "Adding A New Entry to $resource on the $($uxSession.host) Gateway with ID $Index"
if ($PSCmdlet.ShouldProcess($($msg))) {
Try {
if($($uxSession.ignoreCert) -and $($uxSession.pscore)){
$uxrawdata = Invoke-RestMethod -Uri $url -Method PUT -Body $Arguments -WebSession $($uxSession.Session) -ErrorAction Stop -SkipCertificateCheck
}else{
$uxrawdata = Invoke-RestMethod -Uri $url -Method PUT -Body $Arguments -WebSession $($uxSession.Session) -ErrorAction Stop
}
}
Catch {
throw "Unable to process this command.Ensure you have connected to the gateway using `"connect-uxgateway`" cmdlet or if you were already connected your session may have timed out (10 minutes of no activity).The error message is $_"
}
$Result = ([xml]$($uxrawdata.trim())).root
#$Result = ([xml]$uxrawdata).root
$Success = $Result.status.http_code
switch ( $Success) {
"200" { Write-Verbose "Happy with the response" }
"401" { throw "Error creating the new entry, is there an existing record at $url? .The error message is $_" }
"500" { Write-Verbose -Message $uxrawdata; throw "Unable to create a new resource. Ensure you have entered a unique resource id.Verify this using `"get-uxresource`" cmdlet" }
default { throw "Unable to process this command.Ensure you have connected to the gateway using `"connect-uxgateway`" cmdlet or if you were already connected your session may have timed out (10 minutes of no activity).The error message is $_" }
}
# Return data and raw data in the verbose stream if needed.
Write-Verbose $uxrawdata
if ($ReturnElement) {
Return $Result.$ReturnElement
}
Return $Result
}
}
Function Send-UxCommand {
<#
.SYNOPSIS
This cmdlet initates a POST request to send commands to the UX resource. For full list of valid resources refer to https://support.sonus.net/display/UXAPIDOC/Resource+-+system
.DESCRIPTION
This cmdlet initates a POST request to modify existing UX resource. For full list of valid resources refer to https://support.sonus.net/display/UXAPIDOC/Resource+-+system
.PARAMETER resource
Enter a valid resource name here. For valid resource names refer to https://support.sonus.net/display/UXAPIDOC
.EXAMPLE
Send-UxCommand -command reboot
.EXAMPLE
Send-UxCommand -command reboot -uxSession $1stGateway
.LINK
To find all the resources which can be queried, please refer to https://support.sonus.net/display/UXAPIDOC
#>
[cmdletbinding(SupportsShouldProcess = $True, ConfirmImpact = "High")]
Param(
[Parameter(Mandatory = $false, Position = 1)]
[PSCustomObject]$uxSession = $DefaultSession,
[Parameter(Mandatory = $true, Position = 0)]
[string]$Command,
[Parameter(Mandatory = $false, Position = 2)]
[string]$Arguments,
[Parameter(Mandatory = $false, Position = 3)]
[ValidateScript( { $Path = Split-path $_; if (!($Path | Test-path)) { Throw "Folder Must Exist" } return $true })]
[string]$OutPutFilename,
[Parameter(Mandatory = $false, Position = 4)]
[string]$ReturnElement,
[Parameter(Mandatory = $false, Position = 5)]
[pscredential]$Credentials
)
#Region Refeshing the token, if needed
#$ResponseCode = $((get-uxsysteminfo -uxSession $uxSessionObj).status.http_code)
#Write-verbose "Response code from Gateway $ResponseCode"
#
#if ($ResponseCode -ne "200") {
# Throw "Session Expired or problem connecting to Box - Rerun Connect-uxGateway"
#}
#endregion
if ($Command -eq "refreshadcache") {
$url = "https://$($uxSession.host)/rest/adconfig/?action=$Command"
}
else {
# The Command MUST be in lowercase so converting
$url = "https://$($uxSession.host)/rest/system?action=$($command.ToLower())"
}
Write-verbose "Connecting to $url"
Write-verbose "Adding: $Arguments"
# Lets check the User Actually wants to make this change
$msg = "Running $Command on the $($uxSession.host) Gateway"
if ($PSCmdlet.ShouldProcess($($msg))) {
Try {
$options = @{
uri = $url
Method = "POST"
Body = $Arguments
WebSession = $uxSession.Session
ErrorAction = "Stop"
}
if ($OutPutFilename) { $options.OutFile = $OutPutFilename }
if($($uxSession.ignoreCert) -and $($uxSession.pscore)){
$uxrawdata = Invoke-RestMethod @options -SkipCertificateCheck
}else{
$uxrawdata = Invoke-RestMethod @options
}
}
Catch {
throw "Unable to process this command.Ensure you have connected to the gateway using `"connect-uxgateway`" cmdlet or if you were already connected your session may have timed out (10 minutes of no activity).The error message is $_"
}
$Result = ([xml]$($uxrawdata.trim())).root
#$Result = ([xml]$uxrawdata).root
$Success = $Result.status.http_code
switch ( $Success) {
"200" { Write-Verbose "Happy with the response" }
"401" { throw "Error creating the new entry, is there an existing record at $url? .The error message is $_" }
"500" { Write-Verbose -Message $uxrawdata; throw "Unable to create a new resource. Ensure you have entered a unique resource id.Verify this using `"get-uxresource`" cmdlet" }
default { throw "Unable to process this command.Ensure you have connected to the gateway using `"connect-uxgateway`" cmdlet or if you were already connected your session may have timed out (10 minutes of no activity).The error message is $_" }
}
# Return data and raw data in the verbose stream if needed.
Write-Verbose $uxrawdata
if ($ReturnElement) {
Return $Result.$ReturnElement
}
Return $Result
}
}
#Function to delete a resource on UX. 200OK is returned when a resource is deleted successfully. 500 if resource did not exist or couldn't delete it
Function Remove-UxResource {
<#
.SYNOPSIS
This cmdlet initates a DELETE request to remove a UX resource. For full list of valid resources refer to https://support.sonus.net/display/UXAPIDOC
.DESCRIPTION
Whilst primarily used by the internal functions, you can use this function with your own scripts.
As this is likely to overwrite some of your SBC settings the ConfirmPreferences have been set to HIGH!
If you would like to prevent the confirm prompt use -confirm:$false when calling this function.
This can be dangerous if you are looping consider yourself WARNED. :-)
You can delete any resource which supports DELETE request.
.PARAMETER resource
Enter a valid resource name here. For valid resource names refer to https://support.sonus.net/display/UXAPIDOC
.EXAMPLE
Extract the transformation table id of the table you want to delete
get-uxtransformationtable
Now execute remove-uxresource cmdlet to delete the transformation table
remove-uxresource -resource transformationtable/13
.EXAMPLE
Same as Above but if you are scripting it use -confirm:$false
get-uxtransformationtable
Now execute remove-uxresource cmdlet to delete the transformation table
remove-uxresource -resource transformationtable/13 -confirm:$false
.EXAMPLE
Extract the SIP Server table resource and find the id of the table you want to delete
((get-uxresource -resource sipservertable).sipservertable_list).sipservertable_pk
Now execute remove-uxresource cmdlet
remove-uxresource -resource sipservertable/10
.LINK
To find all the resources which can be queried, please refer to https://support.sonus.net/display/UXAPIDOC
#>
[cmdletbinding(SupportsShouldProcess = $True, ConfirmImpact = "High")]
Param(
[Parameter(Mandatory = $false, Position = 0)]
[PSCustomObject]$uxSession = $DefaultSession,
[Parameter(Mandatory = $true, Position = 1)]
[string]$resource,
[Parameter(Mandatory = $false, Position = 2)]
[string]$ReturnElement,
[Parameter(Mandatory = $false, Position = 3)]
[string]$Arguments,
[Parameter(Mandatory = $false, Position = 4)]
[Int]$Index,
[Parameter(Mandatory = $false, Position = 5)]
[pscredential]$Credentials
)
if ($resource -contains "http://") {
Throw "Resource is not properly formatted. Please only pass the resource you wish to remove not the whole address such as transformationtable then index of the entry"
}
#The URL which will be passed to the UX
$url = "https://$($uxSession.host)/rest/$resource"
if ($index) { $url += "/$index" }
Write-verbose "Removing $url"
Write-verbose "With: $Arguments "
$msg = "Deleting A New Entry to $resource on the $($uxSession.host) Gateway"
if ($index) { $msg += "with ID $Index" }
if ($PSCmdlet.ShouldProcess($($msg))) {
Try {
if($($uxSession.ignoreCert) -and $($uxSession.pscore)){
$uxrawdata = Invoke-RestMethod -Uri $url -Method DELETE -Body $Arguments -WebSession $uxSession.Session -ErrorAction Stop -SkipCertificateCheck
}else{
$uxrawdata = Invoke-RestMethod -Uri $url -Method DELETE -Body $Arguments -WebSession $uxSession.Session -ErrorAction Stop
}
}
Catch {
throw "Unable to process this command.Ensure you have connected to the gateway using `"connect-uxgateway`" cmdlet or if you were already connected your session may have timed out (10 minutes of no activity).The error message is $_"
}
$Result = ([xml]$($uxrawdata.trim())).root
#$Result = ([xml]$uxrawdata).root
$Success = $Result.status.http_code
switch ( $Success) {
"200" { Write-Verbose "Happy with the response" }
"401" { throw "Error creating the new entry, is there an existing record at $url? .The error message is $_" }
"500" { Write-Verbose -Message $uxrawdata; throw "Unable to create a new resource. Ensure you have entered a unique resource id.Verify this using `"get-uxresource`" cmdlet" }
default { throw "Unable to process this command.Ensure you have connected to the gateway using `"connect-uxgateway`" cmdlet or if you were already connected your session may have timed out (10 minutes of no activity).The error message is $_" }
}
# Return data and raw data in the verbose stream if needed.
Write-Verbose $uxrawdata
if ($ReturnElement) {
Return $Result.$ReturnElement
}
Return $Result
}
}
#Function to create a modify and existing resource on the UX
Function Set-UxResource {
<#
.SYNOPSIS
This cmdlet initates a POST request to modify existing UX resource. For full list of valid resources refer to https://support.sonus.net/display/UXAPIDOC
.DESCRIPTION
Whilst primarily used by the internal functions, you can use this function with your own scripts.
As this is likely to overwrite some of your SBC settings the ConfirmPreferences have been set to HIGH!
If you would like to prevent the confirm prompt use -confirm:$false when calling this function.
This can be dangerous if you are looping consider yourself WARNED. :-)
.PARAMETER resource
Enter a valid resource name here. For valid resource names refer to https://support.sonus.net/display/UXAPIDOC
.EXAMPLE
Assume you want to change the description of one of the SIPServer table.
Using Get find the ID of the sip server table
((get-uxresource -resource sipservertable).sipservertable_list).sipservertable_pk
Once you have found the ID, issue the cmdlet below to modify the description
set-uxresource -args Description=SBA2 -resource sipservertable/20
.EXAMPLE
Assume you want to change Description of the transformation table.
Extract the transformation table id of the table you want to modify
get-uxtransformationtable
Once you have found the ID, issue the cmdlet below to modify the description
set-uxresource -args "Description=Test5" -resource "transformationtable/12"
.LINK
To find all the resources which can be queried, please refer to https://support.sonus.net/display/UXAPIDOC
#>
[cmdletbinding(SupportsShouldProcess = $True, ConfirmImpact = "High")]
Param(
[Parameter(Mandatory = $false, Position = 5)]
[PSCustomObject]$uxSession = $DefaultSession,
[Parameter(Mandatory = $true, Position = 0)]
[string]$resource,
[Parameter(Mandatory = $false, Position = 3)]
[string]$ReturnElement,
[Parameter(Mandatory = $false, Position = 2)]
[string]$Arguments,
[Parameter(Mandatory = $true, Position = 1)]
[Int]$Index,
[Parameter(Mandatory = $false, Position = 6)]
[pscredential]$Credentials
)
#The URL which will be passed to the UX
$url = "https://$($uxSession.host)/rest/$resource/$index"
Write-verbose "Editing $url"
Write-verbose "With: $Arguments "
$msg = "Deleting A New Entry to $resource on the $($uxSession.host) Gateway with ID $Index"
if ($PSCmdlet.ShouldProcess($($msg))) {
Try {
if($($uxSession.ignoreCert) -and $($uxSession.pscore)){
$uxrawdata = Invoke-RestMethod -Uri $url -Method POST -Body $Arguments -WebSession $uxSession.Session -ErrorAction Stop -SkipCertificateCheck
}else{
$uxrawdata = Invoke-RestMethod -Uri $url -Method POST -Body $Arguments -WebSession $uxSession.Session -ErrorAction Stop
}
}
Catch {
throw "Unable to process this command.Ensure you have connected to the gateway using `"connect-uxgateway`" cmdlet or if you were already connected your session may have timed out (10 minutes of no activity).The error message is $_"
}
$Result = ([xml]$($uxrawdata.trim())).root
#$Result = ([xml]$uxrawdata).root
$Success = $Result.status.http_code
switch ( $Success) {
"200" { Write-Verbose "Happy with the response" }
"401" { throw "Error creating the new entry, is there an existing record at $url? .The error message is $_" }
"500" { Write-Verbose -Message $uxrawdata; throw "Unable to create a new resource. Ensure you have entered a unique resource id.Verify this using `"get-uxresource`" cmdlet" }
default { throw "Unable to process this command.Ensure you have connected to the gateway using `"connect-uxgateway`" cmdlet or if you were already connected your session may have timed out (10 minutes of no activity).The error message is $_" }
}
# Return data and raw data in the verbose stream if needed.
Write-Verbose $uxrawdata
if ($ReturnElement) {
Return $Result.$ReturnElement
}
Return $Result
}
}
Function Get-UxTransformationTable {