-
Notifications
You must be signed in to change notification settings - Fork 0
/
PoSh-PRTG.psm1
934 lines (771 loc) · 43.9 KB
/
PoSh-PRTG.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
### New-PRTGSession -Url $Url -Username prtgadmin -PassHash 1234567890 -Persistent
### $Session = New-PRTGSession -Url $Url -Username prtgadmin -PassHash 1234567890 -Persistent
### Invoke-PRTGAPI -Url $Url -Endpoint "table.xml" -Username prtgadmin -PassHash 1234567890 -Parameters @{content="devices"; id = 1337}
### Get-PRTGSensorDetails -SensorID 1337
# This Function has no Parameter Sets and no Mandatory parameters so that we can just "splat" calls to the other functions straight into it, without it complaining.
# Url, Endpoint and at least 1 auth Method (Credentials or UserName/PassHash) are required (but can't be marked Mandatory without breaking everything).
Function Invoke-PRTGAPI
{
<#
.SYNOPSIS
Makes a call to the PRTG API and returns the result as XML.
.DESCRIPTION
Makes a call to the PRTG API and returns the result as XML.
.EXAMPLE
Invoke-PRTGAPI -Url "https://prtg.contoss.com/api/" -Credential $Credential
.EXAMPLE
Invoke-PRTGAPI -Url "https://prtg.contoss.com/api/" -Username prgadmin -PassHash 43298432
.PARAMETER Credentials
The PSCredentials object used to connect to PRTG. Can be a local PRTG user or an AD synchronised PRTG user.
.PARAMETER Username
The Username used to connect to PRTG. Note: Must be a local PRTG user, as AD synchronised users do not have a passhash.
.PARAMETER PassHash
The PassHash used to connect to PRTG. Can be found in the User Profile page of a local PRTG user. Note: Must be a local PRTG user, as AD synchronised users do not have a passhash.
.PARAMETER Url
The base path to PRTG, e.g prtg.contosso.com or https://prtg.contosso.com:8443"
.PARAMETER Endpoint
The name of the 'endpoint' you are using, e.g. 'table.xml' or 'getsensordetails.xml'
.PARAMETER Parameters
A HashTable containing keyvalue pairs which are passed in the body of the API request. Usually used to sort or limit results returned.
#>
[CmdletBinding()]
param
(
[Parameter(Mandatory=$False, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True, HelpMessage='The URL of the PRTG instance.')]
[String]$Url,
[Parameter(Mandatory=$False, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True, HelpMessage='The endpoint you want to hit.')]
[String]$Endpoint,
[Parameter(Mandatory=$False, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True, HelpMessage='A HashTable of API parameter keyvalue pairs.')]
[HashTable]$Parameters = @{},
[Parameter(Mandatory=$False, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True, HelpMessage='A PSObject created with New-PRTGSession')]
[PSObject]$Session,
[Parameter(Mandatory=$False, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True, HelpMessage='A PSCredentials object. containing the username and password of a PRTG user.')]
[PSCredential]$Credentials,
[Parameter(Mandatory=$False, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True, HelpMessage='A PSCredentials object. containing the username and password of a PRTG user.')]
[String]$Username,
[Parameter(Mandatory=$False, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True, HelpMessage='A PSCredentials object. containing the username and password of a PRTG user.')]
[String]$PassHash
)
# Unwrap the Session Parameter (if supplied)
If ($Session) {
$Url = $Session.Url
$Credentials = $Session.Credentials
$Username = $Session.Username
$PassHash = $Session.PassHash
}
# Use the Persistent session (if it exists) and explicit values aren't defined
If ($Global:PRTGSession) {
If (!$Url) { $Url = $Global:PRTGSession.Url }
If (!$Credentials) { $Credentials = $Global:PRTGSession.Credentials }
If (!$Username) { $Username = $Global:PRTGSession.Username }
If (!$PassHash) { $PassHash = $Global:PRTGSession.PassHash }
}
#Add the credentials to a variable to be used as the "body" of the HTTP Request (will become GET params)
$Body = @{ }
If ($Credentials) {
$Body.username = $Credentials.UserName
$Body.password = $Credentials.GetNetworkCredential().Password
}
ElseIf ($Username -And $PassHash) {
$Body.username = $Username
$Body.passhash = $PassHash
}
Else {
Throw "You must supply either Credentials or a Username and PassHash."
}
#Verify that the URL and Endpoint have been supplied.
If (!$Url) {
Throw "You must specify the base Url of the PRTG instance by providing the -Url parameter."
}
ElseIf (!$Endpoint) {
Throw "You must specify the Endpoint."
}
Try {
$Url = $Url + "/api/" + $Endpoint
If ($Verbose) { $Result = Invoke-WebRequest -Method Get -Uri $Url -Body ($Body + $Parameters) -UseBasicParsing -ErrorAction Stop -Verbose}
Else { $Result = Invoke-WebRequest -Method Get -Uri $Url -Body ($Body + $Parameters) -UseBasicParsing -ErrorAction Stop}
If ($Result.StatusCode -Eq 200) {
If ($Verbose) { Write-Verbose $Result.Content }
If ($Verbose) { Write-Verbose $Result.Headers.'Content-Disposition' }
If ($Result.Headers.'Content-Disposition' -Like '*.xml*')
{
If ($Verbose) { "Detected XML. Returning parsed XML."}
[xml]$XML = $Result.Content
Return $XML
}
else
{
If ($Verbose) { Write-Warning "Detected non-XML. Returning raw Content." }
Return $Result.Content
}
}
}
Catch {
Throw $_
}
}
Function New-PRTGSession
{
<#
.SYNOPSIS
Creates a PRTG Session object, which is a PSObject containing a URL and credentials that can be passed to PRTG cmdlets.
.DESCRIPTION
If you set the Persistent switch, it stores the URL and credentials as a global variable which the other PRTG cmdlets try to use if they are not supplied with explicit Url and credentials parameters.
.EXAMPLE
Connect-PRTG
.EXAMPLE
Connect-PRTG -Url "https://prtg.contoss.com/api/" -Credential $Credential
.EXAMPLE
Connect-PRTG -Url "https://prtg.contoss.com/api/" -Username prgadmin -PassHash 43298432
.PARAMETER Credentials
The PSCredentials object used to connect to PRTG. Can be a local PRTG user or an AD synchronised PRTG user.
.PARAMETER Username
The Username used to connect to PRTG. Note: Must be a local PRTG user, as AD synchronised users do not have a passhash.
.PARAMETER PassHash
The PassHash used to connect to PRTG. Can be found in the User Profile page of a local PRTG user. Note: Must be a local PRTG user, as AD synchronised users do not have a passhash.
.PARAMETER Url
The base path to PRTG, e.g prtg.contosso.com or https://prtg.contosso.com:8443"
.PARAMETER Persistent
If present, will store the "Session" as a global variable which the other PRTG Cmdlets will use if they are not supplied with explicit Url and credentials parameters.
#>
[CmdletBinding(DefaultParameterSetName="Credentials")]
param
(
[Parameter(Mandatory=$True, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True, HelpMessage='The URL of the PRTG API (including a trailing slash).')]
[String]$Url,
[Parameter(ParameterSetName="Credentials", Mandatory=$True, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True, HelpMessage='A PSCredentials object. containing the username and password of a PRTG user.')]
[PSCredential]$Credentials,
[Parameter(ParameterSetName="PassHash", Mandatory=$True, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True, HelpMessage='A PSCredentials object. containing the username and password of a PRTG user.')]
[String]$Username,
[Parameter(ParameterSetName="PassHash", Mandatory=$True, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True, HelpMessage='A PSCredentials object. containing the username and password of a PRTG user.')]
[String]$PassHash,
[Parameter(Mandatory=$False, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True, HelpMessage="Mark the session as 'persistent' which stores the details in a global variable so that you don't have to supply them with every subsequent cmdlet call.")]
[Switch]$Persistent
)
#Test the URL and Credentials with a call to table.xml with id=-1 (won't exist)
Try {
If (!$Session) { $Session = @{Url = $Url; Credentials = $Credentials; Username = $Username; PassHash = $PassHash} }
Invoke-PRTGAPI -Endpoint "table.xml" -Parameters @{content="test"; filter_objid = "-1"} -Session $Session | Out-Null
If ($Persistent) {
$Global:PRTGSession = $Session
}
Return $Session
}
Catch
{
Throw $_
}
}
Function Remove-PRTGSession
{
<#
.SYNOPSIS
Disconnects (destroys) a PRTG instance.
.DESCRIPTION
Although this cmdlet is called Remove-PRTGSession, it's not actually really necessary and simply just flushes a variable (or the global variable). It is provided for the sake of completion.
.EXAMPLE
Disconnect-PRTG
#>
[CmdletBinding()]
param
(
[Parameter(ParameterSetName="Session", Mandatory=$False, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True, HelpMessage='A PSObject created with New-PRTGSession that you want to flush.')]
[PSObject]$Session,
[Parameter(ParameterSetName="Persistent", Mandatory=$False, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True, HelpMessage="Flush the Persistent session.")]
[Switch]$Persistent
)
If ($PSCmdlet.ParameterSetName -Eq "Session") { $Session = $Null }
If ($PSCmdlet.ParameterSetName -Eq "Persistent") { $Global:PRTGSession = $Null }
}
Function Get-PRTGSession
{
<#
.SYNOPSIS
Returns a persistent PRTG Session, if it exists.
.DESCRIPTION
Returns a persistent PRTG Session PSOBject, if it exists (or $null if it does not).
.EXAMPLE
Get-PRTGSession
#>
Return $Global:PRTGSession
}
Function Get-PRTGSensorDetails
{
<#
.SYNOPSIS
Gets the details of an existing PRTG Sensor.
.DESCRIPTION
Uses the PRTG API to get the details of an existing PRTG Sensor as a PSOBject.
.EXAMPLE
Get-PRTGSensorDetails -SensorID 1235
.PARAMETER SensorID
The ID of an existing PRTG Sensor that you want to retrieve the details for.
.PARAMETER Credentials
The Credentials used to connect to PRTG.
.PARAMETER Url
The base path to the PRTG API, including a trailing slash. e.g https://prtg.contosso.com/api/"
#>
[CmdletBinding(DefaultParameterSetName="Session")]
param
(
[Parameter(Mandatory=$True, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True, HelpMessage='The ID of the PRTG Sensor that you want to edit.')]
[long]$SensorID,
[Parameter(ParameterSetName="Session", Mandatory=$False, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True, HelpMessage='A PSObject created with New-PRTGSession')]
[PSObject]$Session,
[Parameter(ParameterSetName="Credentials", Mandatory=$True, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True, HelpMessage='A PSCredentials object. containing the username and password of a PRTG user.')]
[PSCredential]$Credentials,
[Parameter(ParameterSetName="PassHash", Mandatory=$True, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True, HelpMessage='The username of a PRTG user.')]
[String]$Username,
[Parameter(ParameterSetName="PassHash", Mandatory=$True, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True, HelpMessage='The passhash of a PRTG user.')]
[String]$PassHash,
[Parameter(Mandatory=$False, ValueFromPipeline=$False, ValueFromPipelineByPropertyName=$True, HelpMessage='The URL of the PRTG API.')]
[String]$Url
)
If (!$Session) { If (!$Session) { $Session = @{Url = $Url; Credentials = $Credentials; Username = $Username; PassHash = $PassHash} } }
$Result = Invoke-PRTGAPI -Endpoint "getsensordetails.xml" -Parameters @{id = $SensorID} -Session $Session
#This is HORRIBLE and causes me much shame, but converting an XML object to a PSObject isnt a oneliner in PowerShell...
#Also, because of the CDATA the following won't work (easily): http://stackoverflow.com/questions/3242995/convert-xml-to-psobject
#Doing it manually also allows us to rename/recase the Properties, so there's that...
$SensorDetails = @{
Name = $Result.sensordata.name."#cdata-section"
ID = $SensorID
SensorType = $Result.sensordata.sensortype."#cdata-section"
Interval = $Result.sensordata.interval."#cdata-section"
ProbeName = $Result.sensordata.probename."#cdata-section"
ParentGroupName = $Result.sensordata.parentgroupname."#cdata-section"
ParentDeviceID = $Result.sensordata.parentdeviceid."#cdata-section"
LastValue = $Result.sensordata.lastvalue."#cdata-section"
LastMessage = $Result.sensordata.lastmessage."#cdata-section"
Favorite = $Result.sensordata.favorite."#cdata-section"
StatusText = $Result.sensordata.statustext."#cdata-section"
StatusID = $Result.sensordata.statusid."#cdata-section"
LastUp = $Result.sensordata.lastup."#cdata-section" #TODO: This returns a horrible format, ideally we should parse this and Return something nicer...
LastDown = $Result.sensordata.lastdown."#cdata-section" #TODO: This returns a horrible format, ideally we should parse this and Return something nicer...
LastCheck = $Result.sensordata.lastcheck."#cdata-section" #TODO: This returns a horrible format, ideally we should parse this and Return something nicer...
Uptime = $Result.sensordata.uptime."#cdata-section" #TODO: This returns a horrible format, ideally we should parse this and Return something nicer...
UptimeTime = $Result.sensordata.uptimetime."#cdata-section" #TODO: This returns a horrible format, ideally we should parse this and Return something nicer...
Downtime = $Result.sensordata.downtime."#cdata-section" #TODO: This returns a horrible format, ideally we should parse this and Return something nicer...
DowntimeTime = $Result.sensordata.downtimetime."#cdata-section" #TODO: This returns a horrible format, ideally we should parse this and Return something nicer...
UpDownTotal = $Result.sensordata.updowntotal."#cdata-section" #TODO: This returns a horrible format, ideally we should parse this and Return something nicer...
UpDownSince = $Result.sensordata.updownsince."#cdata-section" #TODO: This returns a horrible format, ideally we should parse this and Return something nicer...
}
Return New-Object PSObject -Property $SensorDetails
}
Function Copy-PRTGSensor
{
<#
.SYNOPSIS
Clones an existing PRTG Sensor and returns the ID of the newly created sensor.
.DESCRIPTION
Uses the PRTG API to create a new sensor, however the PRTG API only allows you to create a new sensor by cloning an existing sensor.
.EXAMPLE
Clone-PRTGSensor -SensorID 1234 -TargetID 5678 -Name "My Sensor" -Unpause
.EXAMPLE
Get-Content C:\Temp\Input.txt | Foreach-Object {Clone-PRTGSensor -SensorID 5382 -TargetID 2347 -Name (("Queues: " + $_ + " - ActiveMessageCount") -replace "development", "production")}
.PARAMETER SensorID
The ID of an existing PRTG Sensor that you want to clone.
.PARAMETER TargetID
The ID of the Group/Device that the new sensor will be childed to.
.PARAMETER Name
The name of the new PRTG Sensor.
.PARAMETER Credentials
The Credentials used to connect to PRTG.
.PARAMETER Url
The base path to the PRTG API, including a trailing slash. e.g https://prtg.contosso.com/api/"
#>
[CmdletBinding()]
param
(
[Parameter(Mandatory=$True, ValueFromPipeline=$False, ValueFromPipelineByPropertyName=$True, HelpMessage='The ID of an existing PRTG Sensor that you want to clone.')]
[long]$SensorID,
[Parameter(Mandatory=$True, ValueFromPipeline=$False, ValueFromPipelineByPropertyName=$True, HelpMessage='The ID of the Device that the new PRTG Sensor will be childed to.')]
[long]$TargetID,
[Parameter(Mandatory=$False, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True, HelpMessage='The new name of the cloned PRTG Sensor.')]
[String]$Name,
[Parameter(Mandatory=$False, ValueFromPipeline=$False, ValueFromPipelineByPropertyName=$True, HelpMessage='If preset, the newly created Sensor will be Unpaused/Resumed immediatly after it is created. (Deafult is for newly created sensors to be paused)')]
[Switch]$Unpause,
[Parameter(ParameterSetName="Session", Mandatory=$False, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True, HelpMessage='A PSObject created with New-PRTGSession')]
[PSObject]$Session,
[Parameter(ParameterSetName="Credentials", Mandatory=$True, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True, HelpMessage='A PSCredentials object. containing the username and password of a PRTG user.')]
[PSCredential]$Credentials,
[Parameter(ParameterSetName="PassHash", Mandatory=$True, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True, HelpMessage='The username of a PRTG user.')]
[String]$Username,
[Parameter(ParameterSetName="PassHash", Mandatory=$True, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True, HelpMessage='The passhash of a PRTG user.')]
[String]$PassHash,
[Parameter(Mandatory=$False, ValueFromPipeline=$False, ValueFromPipelineByPropertyName=$True, HelpMessage='The URL of the PRTG API.')]
[String]$Url
)
If (!$Session) { $Session = @{Url = $Url; Credentials = $Credentials; Username = $Username; PassHash = $PassHash} }
$Parameters =@{id = $SensorID; targetid = $TargetID}
If ($Name) {$Parameters.name = $Name }
$Result = Invoke-PRTGAPI -Endpoint "duplicateobject.htm" -Parameters $Parameters -Session $Session
If ($Result -Match 'id=(?<ID>\d+)') #TODO: make this more robust
{
$NewSensorID = $matches.ID
If ($Unpause) {
Resume-PRTGSensor -SensorID $NewSensorID | Out-Null
}
Return New-Object PSObject -Property @{SensorID = $NewSensorID}
}
Else
{
Throw "The PRTG API did not appear to Return the ID of the new sensor. The sensor was probably not successfully created."
}
}
New-Alias -Name Clone-PRTGSensor -Value Copy-PRTGSensor
Function Get-PRTGSensorProperty
{
<#
.SYNOPSIS
Gets the property of an existing PRTG Sensor.
.DESCRIPTION
Uses the PRTG API to get the property on an existing PRTG Sensor. The Property parameter can be discerned by opening the Settings page of a Sensor and looking at the HTML source of the INPUT fields (and removing the trailing underscore).
.EXAMPLE
Get-PRTGSensorProperty -SensorID 1235 -Property "xmlurl"
.EXAMPLE
Get-Content C:\input.txt | Foreach-Object {Get-PRTGSensorProperty -SensorID $_ -Property "xmlurl"}
.PARAMETER SensorID
The ID of an existing PRTG Sensor that you want to retrieve a proeprty for.
.PARAMETER Credentials
The Credentials used to connect to PRTG.
.PARAMETER Url
The base path to the PRTG API, including a trailing slash. e.g https://prtg.contosso.com/api/"
#>
[CmdletBinding()]
param
(
[Parameter(Mandatory=$True, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True, HelpMessage='The ID of the PRTG Sensor that you want to edit.')]
[long]$SensorID,
[Parameter(Mandatory=$True, ValueFromPipeline=$False, ValueFromPipelineByPropertyName=$True, HelpMessage='The name of the property that you want to edit.')]
[String]$Property,
[Parameter(ParameterSetName="Session", Mandatory=$False, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True, HelpMessage='A PSObject created with New-PRTGSession')]
[PSObject]$Session,
[Parameter(ParameterSetName="Credentials", Mandatory=$True, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True, HelpMessage='A PSCredentials object. containing the username and password of a PRTG user.')]
[PSCredential]$Credentials,
[Parameter(ParameterSetName="PassHash", Mandatory=$True, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True, HelpMessage='The username of a PRTG user.')]
[String]$Username,
[Parameter(ParameterSetName="PassHash", Mandatory=$True, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True, HelpMessage='The passhash of a PRTG user.')]
[String]$PassHash,
[Parameter(Mandatory=$False, ValueFromPipeline=$False, ValueFromPipelineByPropertyName=$True, HelpMessage='The URL of the PRTG API.')]
[String]$Url
)
If (!$Session) { $Session = @{Url = $Url; Credentials = $Credentials; Username = $Username; PassHash = $PassHash} }
$Result = Invoke-PRTGAPI -Endpoint "getobjectproperty.htm" -Parameters @{id = $SensorID; name = $Property} -Session $Session
#TODO: ideally need to Return success or failure but blindly assuming it worked will have to do for now...
#(Returns it's own SensorID so that cmdlet pipelining works)
$SensorProperty = @{SensorID = $SensorID; Value = $Result.prtg.result}
Return New-Object PSObject -Property $SensorProperty
}
Function Set-PRTGSensorProperty
{
<#
.SYNOPSIS
Sets (edits) the property on an existing PRTG Sensor.
.DESCRIPTION
Uses the PRTG API to set the property on an existing PRTG Sensor. The Property parameter can be discerned by opening the Settings page of a Sensor and looking at the HTML source of the INPUT fields (and removing the trailing underscore).
.EXAMPLE
Set-PRTGSensorProperty -SensorID 1235 -Property "xmlurl" -Value "http://www.google.com"
.EXAMPLE
Get-Content C:\input.txt | Foreach-Object {Set-PRTGSensorProperty -SensorID $_ -Property "xmlurl" -Value "MyValue1"}
.PARAMETER SensorID
The ID of an existing PRTG Sensor that you want to edit the property of.
.PARAMETER Credentials
The Credentials used to connect to PRTG.
.PARAMETER Url
The base path to the PRTG API, including a trailing slash. e.g https://prtg.contosso.com/api/"
#>
[CmdletBinding()]
param
(
[Parameter(Mandatory=$True, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True, HelpMessage='The ID of the PRTG Sensor that you want to edit.')]
[long]$SensorID,
[Parameter(Mandatory=$True, ValueFromPipeline=$False, ValueFromPipelineByPropertyName=$True, HelpMessage='The name of the property that you want to edit.')]
[String]$Property,
[Parameter(Mandatory=$True, ValueFromPipeline=$False, ValueFromPipelineByPropertyName=$True, HelpMessage='The new value of the property.')]
[String]$Value,
[Parameter(ParameterSetName="Session", Mandatory=$False, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True, HelpMessage='A PSObject created with New-PRTGSession')]
[PSObject]$Session,
[Parameter(ParameterSetName="Credentials", Mandatory=$True, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True, HelpMessage='A PSCredentials object. containing the username and password of a PRTG user.')]
[PSCredential]$Credentials,
[Parameter(ParameterSetName="PassHash", Mandatory=$True, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True, HelpMessage='The username of a PRTG user.')]
[String]$Username,
[Parameter(ParameterSetName="PassHash", Mandatory=$True, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True, HelpMessage='The passhash of a PRTG user.')]
[String]$PassHash,
[Parameter(Mandatory=$False, ValueFromPipeline=$False, ValueFromPipelineByPropertyName=$True, HelpMessage='The URL of the PRTG API.')]
[String]$Url
)
If (!$Session) { $Session = @{Url = $Url; Credentials = $Credentials; Username = $Username; PassHash = $PassHash} }
$Result = Invoke-PRTGAPI -Endpoint "setobjectproperty.htm" -Parameters @{id = $SensorID; name = $Property; value = $Value} -Session $Session
#TODO: ideally need to Return success or failure but blindly assuming it worked will have to do for now...
#(Returns it's own SensorID so that cmdlet pipelining works)
Return New-Object PSObject -Property @{SensorID = $SensorID}
}
Function Resume-PRTGSensor
{
<#
.SYNOPSIS
Resumes a paused PRTG Sensor.
.DESCRIPTION
Uses the PRTG API to resume a paused PRTG Sensor.
.EXAMPLE
Resume-PRTGSensor -SensorID 1234
.PARAMETER SensorID
The ID of an existing PRTG Sensor that you want to resume.
.PARAMETER Credentials
The Credentials used to connect to PRTG.
.PARAMETER Url
The base path to the PRTG API, including a trailing slash. e.g https://prtg.contosso.com/api/"
#>
[CmdletBinding()]
param
(
[Parameter(Mandatory=$True, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True, HelpMessage='The ID of the PRTG Sensor that you want to edit.')]
[long]$SensorID,
[Parameter(ParameterSetName="Session", Mandatory=$False, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True, HelpMessage='A PSObject created with New-PRTGSession')]
[PSObject]$Session,
[Parameter(ParameterSetName="Credentials", Mandatory=$True, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True, HelpMessage='A PSCredentials object. containing the username and password of a PRTG user.')]
[PSCredential]$Credentials,
[Parameter(ParameterSetName="PassHash", Mandatory=$True, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True, HelpMessage='The username of a PRTG user.')]
[String]$Username,
[Parameter(ParameterSetName="PassHash", Mandatory=$True, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True, HelpMessage='The passhash of a PRTG user.')]
[String]$PassHash,
[Parameter(Mandatory=$False, ValueFromPipeline=$False, ValueFromPipelineByPropertyName=$True, HelpMessage='The URL of the PRTG API.')]
[String]$Url
)
If (!$Session) { $Session = @{Url = $Url; Credentials = $Credentials; Username = $Username; PassHash = $PassHash} }
$Result = Invoke-PRTGAPI -Endpoint "pause.htm" -Parameters @{id = $SensorID; action = 1} -Session $Session
#TODO: ideally need to Return success or failure but blindly assuming it worked will have to do for now...
#(Returns it's own SensorID so that cmdlet pipelining works)
Return New-Object PSObject -Property @{SensorID = $SensorID}
}
Function Pause-PRTGSensor
{
<#
.SYNOPSIS
Pauses a PRTG Sensor.
.DESCRIPTION
Uses the PRTG API to pause PRTG Sensor. If you do not specify a length, the sensor will be paused indefinitely.
.EXAMPLE
Pause-PRTGSensor -SensorID 1234
.EXAMPLE
Pause-PRTGSensor -SensorID 1234 -Duration 60 -Message "Pausing, server powered off for 1 week."
.PARAMETER SensorID
The ID of an existing PRTG Sensor that you want to pause.
.PARAMETER Credentials
The Credentials used to connect to PRTG.
.PARAMETER Url
The base path to the PRTG API, including a trailing slash. e.g https://prtg.contosso.com/api/"
#>
[CmdletBinding()]
param
(
[Parameter(Mandatory=$True, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True, HelpMessage='The ID of the PRTG Sensor that you want to edit.')]
[long]$SensorID,
[Parameter(Mandatory=$False, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True, HelpMessage='The Duration (in minutes) to pause the sensor for.')]
[int]$Duration,
[Parameter(Mandatory=$False, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True, HelpMessage='The Pause message.')]
[int]$Message,
[Parameter(ParameterSetName="Session", Mandatory=$False, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True, HelpMessage='A PSObject created with New-PRTGSession')]
[PSObject]$Session,
[Parameter(ParameterSetName="Credentials", Mandatory=$True, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True, HelpMessage='A PSCredentials object. containing the username and password of a PRTG user.')]
[PSCredential]$Credentials,
[Parameter(ParameterSetName="PassHash", Mandatory=$True, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True, HelpMessage='The username of a PRTG user.')]
[String]$Username,
[Parameter(ParameterSetName="PassHash", Mandatory=$True, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True, HelpMessage='The passhash of a PRTG user.')]
[Parameter(Mandatory=$False, ValueFromPipeline=$False, ValueFromPipelineByPropertyName=$True, HelpMessage='The URL of the PRTG API.')]
[String]$Url
)
If (!$Session) { $Session = @{Url = $Url; Credentials = $Credentials; Username = $Username; PassHash = $PassHash} }
$Parameters = @{}
$Endpoint = ""
if ($Length)
{
$Endpoint = "pauseobjectfor.htm"
$Parameters = @{
id=$SensorID
action=0
duration=$Duration
pausemsg=$Message
}
}
else
{
$Endpoint = "pause.htm"
$Parameters = @{
id=$SensorID
action=0
}
}
$Result = Invoke-PRTGAPI -Endpoint $Endpoint -Parameters $Parameters -Session $Session
#TODO: ideally need to Return success or failure but blindly assuming it worked will have to do for now...
#(Returns it's own SensorID so that cmdlet pipelining works)
Return New-Object PSObject -Property @{SensorID = $SensorID}
}
Function Get-PRTGObject
{
<#
.SYNOPSIS
Gets objects (Devices, Sensors, Groups, etc) from PRTG.
.DESCRIPTION
Uses the PRTG API to get a list of PRTG Objects as an array.
.EXAMPLE
Get-PRTGObject -Type Sensors
.PARAMETER Name
The Name of the object you want.
.PARAMETER ID
The ID of the object you want.
.PARAMETER Type
The Type of objects you want. Valid options are devices, groups or sensors.
.PARAMETER Columns
The Columns you want retrieved for each item. A ful list of columns is availible in the PRTG API documentation.
.PARAMETER Filter
A HashTable of Keyvalue pairs to filter the data, based on columns. As required by the PRTG API, the word "filter_" is automatically prepended to each key (if not already there). For parameters you don't want prepended with "filter_" (e.g maxresults), use the Parameters parameter.
.PARAMETER Parameters
A HashTable of Keyvalue pairs to pass as additional parameters. For filtering, you should use the Filter parameter.
.PARAMETER Credentials
The Credentials used to connect to PRTG.
.PARAMETER Url
The base path to the PRTG API, including a trailing slash. e.g https://prtg.contosso.com/api/"
#>
[OutputType([array])]
[CmdletBinding(DefaultParameterSetName='Session')]
param
(
[Parameter(Mandatory=$False, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True, HelpMessage='The name of the Group you want to retrieve.')]
[String]$Name,
[Parameter(Mandatory=$False, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True, HelpMessage='The ID of the Group you want to retrieve.')]
[int]$ID,
[Parameter(Mandatory=$False, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True, HelpMessage='A comma separated string of types you are searching for: ["devices", "sensors", "groups"]')]
[String]$Type = "devices",
[Parameter(Mandatory=$False, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True, HelpMessage='A comma separated list of fields/columns to return')]
[String]$Columns = "objid,type,name",
[Parameter(Mandatory=$False, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True, HelpMessage='A HashTable of filter keyvalue pairs.')]
[HashTable]$Filters = @{},
[Parameter(Mandatory=$False, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True, HelpMessage='A HashTable of API parameter keyvalue pairs.')]
[HashTable]$Parameters = @{},
[Parameter(ParameterSetName="Session", Mandatory=$False, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True, HelpMessage='A PSObject created with New-PRTGSession')]
[PSObject]$Session,
[Parameter(ParameterSetName="Credentials", Mandatory=$True, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True, HelpMessage='A PSCredentials object. containing the username and password of a PRTG user.')]
[PSCredential]$Credentials,
[Parameter(ParameterSetName="PassHash", Mandatory=$True, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True, HelpMessage='The username of a PRTG user.')]
[String]$Username,
[Parameter(ParameterSetName="PassHash", Mandatory=$True, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True, HelpMessage='The passhash of a PRTG user.')]
[String]$PassHash,
[Parameter(Mandatory=$False, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True, HelpMessage='The URL of the PRTG API.')]
[String]$Url
)
If ($Name -And $ID) {
Write-Warning "Supplying values for both the Name and ID parameters results in a Boolean AND search. Results must match BOTH fields."
}
If ($Name) {
$Parameters.Add("filter_name", $Name)
}
If ($ID) {
$Parameters.Add("filter_objid", $ID)
}
# Add any Filters to the Parameters object, prepending any with "filter_" as required.
$Filters.GetEnumerator() | ForEach-Object {
If (!$_.Name.StartsWith("filter_")) { $_.Name = ("filter_" + $_.Name) }
$Parameters.Add($_.Name, $_.Value)
}
If (!$Session) { $Session = @{Url = $Url; Credentials = $Credentials; Username = $Username; PassHash = $PassHash} }
$Result = Invoke-PRTGAPI -Endpoint "table.xml" -Parameters ($Parameters + @{columns = $Columns; content = $Type.ToLower()}) -Session $Session
#$Items += Select-Xml -XML $Result -XPath "//item" | Select-Object -ExpandProperty Node
[Array]$Items = @($Result.SelectNodes("//item"))
Return [Array]$Items
}
Function Get-PRTGGroup
{
<#
.SYNOPSIS
Gets a list of Groups from PRTG.
.DESCRIPTION
Uses the PRTG API to get a list of PRTG Groups as an array.
.EXAMPLE
Get-PRTGGroup
.PARAMETER Name
The Name of the object you want.
.PARAMETER ID
The ID of the object you want.
.PARAMETER Columns
The Columns you want retrieved for each item. A ful list of columns is availible in the PRTG API documentation.
.PARAMETER Filter
A HashTable of Keyvalue pairs to filter the data, based on columns.
.PARAMETER Credentials
The Credentials used to connect to PRTG.
.PARAMETER Url
The base path to the PRTG API, including a trailing slash. e.g https://prtg.contosso.com/api/"
#>
[OutputType([array])]
[CmdletBinding(DefaultParameterSetName='Session')]
param
(
[Parameter(Mandatory=$False, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True, HelpMessage='The name of the Group you want to retrieve.')]
[String]$Name,
[Parameter(Mandatory=$False, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True, HelpMessage='The ID of the Group you want to retrieve.')]
[int]$ID,
[Parameter(Mandatory=$False, ValueFromPipeline=$False, ValueFromPipelineByPropertyName=$True, HelpMessage='A comma separated list of fields/columns to return')]
[String]$Columns = "objid,name,host,group,parentid,probe,tags,active,comments",
[Parameter(Mandatory=$False, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True, HelpMessage='A HashTable of filter keyvalue pairs.')]
[HashTable]$Filters = @{},
[Parameter(Mandatory=$False, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True, HelpMessage='A HashTable of API parameter keyvalue pairs.')]
[HashTable]$Parameters = @{},
[Parameter(ParameterSetName="Session", Mandatory=$False, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True, HelpMessage='A PSObject created with New-PRTGSession')]
[PSObject]$Session,
[Parameter(ParameterSetName="Credentials", Mandatory=$True, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True, HelpMessage='A PSCredentials object. containing the username and password of a PRTG user.')]
[PSCredential]$Credentials,
[Parameter(ParameterSetName="PassHash", Mandatory=$True, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True, HelpMessage='The username of a PRTG user.')]
[String]$Username,
[Parameter(ParameterSetName="PassHash", Mandatory=$True, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True, HelpMessage='The passhash of a PRTG user.')]
[String]$PassHash,
[Parameter(Mandatory=$False, ValueFromPipeline=$False, ValueFromPipelineByPropertyName=$True, HelpMessage='The URL of the PRTG API.')]
[String]$Url
)
Return @(Get-PRTGObject -Type "groups" @PSBoundParameters)
}
Function Get-PRTGDevice
{
<#
.SYNOPSIS
Gets a list of Devices from PRTG.
.DESCRIPTION
Uses the PRTG API to get a list of PRTG Devices as an array.
.EXAMPLE
Get-PRTGDevice
.PARAMETER Name
The Name of the object you want.
.PARAMETER ID
The ID of the object you want.
.PARAMETER Columns
The Columns you want retrieved for each item. A ful list of columns is availible in the PRTG API documentation.
.PARAMETER Filter
A HashTable of Keyvalue pairs to filter the data, based on columns.
.PARAMETER Credentials
The Credentials used to connect to PRTG.
.PARAMETER Url
The base path to the PRTG API, including a trailing slash. e.g https://prtg.contosso.com/api/"
#>
[OutputType([array])]
[CmdletBinding(DefaultParameterSetName='Session')]
param
(
[Parameter(Mandatory=$False, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True, HelpMessage='The name of the Device you want to retrieve.')]
[String]$Name,
[Parameter(Mandatory=$False, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True, HelpMessage='The ID of the Device you want to retrieve.')]
[int]$ID,
[Parameter(Mandatory=$False, ValueFromPipeline=$False, ValueFromPipelineByPropertyName=$True, HelpMessage='A comma separated list of fields/columns to return')]
[String]$Columns = "objid,name,host,group,parentid,probe,tags,active,comments",
[Parameter(Mandatory=$False, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True, HelpMessage='A HashTable of filter keyvalue pairs.')]
[HashTable]$Filters = @{},
[Parameter(Mandatory=$False, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True, HelpMessage='A HashTable of API parameter keyvalue pairs.')]
[HashTable]$Parameters = @{},
[Parameter(Mandatory=$False, ValueFromPipeline=$False, ValueFromPipelineByPropertyName=$True, HelpMessage='The URL of the PRTG API.')]
[String]$Url,
[Parameter(ParameterSetName="Session", Mandatory=$False, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True, HelpMessage='A PSObject created with New-PRTGSession')]
[PSObject]$Session,
[Parameter(ParameterSetName="Credentials", Mandatory=$True, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True, HelpMessage='A PSCredentials object. containing the username and password of a PRTG user.')]
[PSCredential]$Credentials,
[Parameter(ParameterSetName="PassHash", Mandatory=$True, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True, HelpMessage='The username of a PRTG user.')]
[String]$Username,
[Parameter(ParameterSetName="PassHash", Mandatory=$True, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True, HelpMessage='The passhash of a PRTG user.')]
[String]$PassHash
)
Return @(Get-PRTGObject -Type "devices" @PSBoundParameters)
}
Function Get-PRTGSensor
{
<#
.SYNOPSIS
Gets a list of Sensors from PRTG.
.DESCRIPTION
Uses the PRTG API to get a list of PRTG Sensors as an array.
.EXAMPLE
Get-PRTGSensor
.PARAMETER Name
The Name of the object you want.
.PARAMETER ID
The ID of the object you want.
.PARAMETER Columns
The Columns you want retrieved for each item. A ful list of columns is availible in the PRTG API documentation.
.PARAMETER Filter
A HashTable of Keyvalue pairs to filter the data, based on columns.
.PARAMETER Credentials
The Credentials used to connect to PRTG.
.PARAMETER Url
The base path to the PRTG API, including a trailing slash. e.g https://prtg.contosso.com/api/"
#>
[OutputType([array])]
[CmdletBinding(DefaultParameterSetName='Session')]
param
(
[Parameter(Mandatory=$False, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True, HelpMessage='The name of the Group you want to retrieve.')]
[String]$Name,
[Parameter(Mandatory=$False, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True, HelpMessage='The ID of the Group you want to retrieve.')]
[int]$ID,
[Parameter(Mandatory=$False, ValueFromPipeline=$False, ValueFromPipelineByPropertyName=$True, HelpMessage='A comma separated list of fields/columns to return')]
[String]$Columns = "objid,name,sensor,device,host,group,parentid,probe,tags,active,comments, value_, status, message,priority,",
[Parameter(Mandatory=$False, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True, HelpMessage='A HashTable of filter keyvalue pairs.')]
[HashTable]$Filters = @{},
[Parameter(Mandatory=$False, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True, HelpMessage='A HashTable of API parameter keyvalue pairs.')]
[HashTable]$Parameters = @{},
[Parameter(ParameterSetName="Session", Mandatory=$False, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True, HelpMessage='A PSObject created with New-PRTGSession')]
[PSObject]$Session,
[Parameter(ParameterSetName="Credentials", Mandatory=$True, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True, HelpMessage='A PSCredentials object. containing the username and password of a PRTG user.')]
[PSCredential]$Credentials,
[Parameter(ParameterSetName="PassHash", Mandatory=$True, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True, HelpMessage='The username of a PRTG user.')]
[String]$Username,
[Parameter(ParameterSetName="PassHash", Mandatory=$True, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True, HelpMessage='The passhash of a PRTG user.')]
[String]$PassHash,
[Parameter(Mandatory=$False, ValueFromPipeline=$False, ValueFromPipelineByPropertyName=$True, HelpMessage='The URL of the PRTG API.')]
[String]$Url
)
Return @(Get-PRTGObject -Type "sensors" @PSBoundParameters)
}
Function Rename-PRTGSensor
{
<#
.SYNOPSIS
Renames an existing PRTG Sensor.
.DESCRIPTION
Uses the PRTG API to rename a PRTG sensor.
.EXAMPLE
Rename-PRTGSensor -SensorID 1234 -Name "My Sensor"
.PARAMETER SensorID
The ID of an existing PRTG Sensor that you want to rename.
.PARAMETER Name
The new name of the new PRTG Sensor.
.PARAMETER Credentials
The Credentials used to connect to PRTG.
.PARAMETER Url
The base path to the PRTG API, including a trailing slash. e.g https://prtg.contosso.com/api/"
#>
[CmdletBinding()]
param
(
[Parameter(Mandatory=$True, ValueFromPipeline=$False, ValueFromPipelineByPropertyName=$True, HelpMessage='The ID of an existing PRTG Sensor that you want to rename.')]
[long]$SensorID,
[Parameter(Mandatory=$True, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True, HelpMessage='The new name of the new PRTG Sensor.')]
[String]$Name,
[Parameter(ParameterSetName="Session", Mandatory=$False, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True, HelpMessage='A PSObject created with New-PRTGSession')]
[PSObject]$Session,
[Parameter(ParameterSetName="Credentials", Mandatory=$True, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True, HelpMessage='A PSCredentials object. containing the username and password of a PRTG user.')]
[PSCredential]$Credentials,
[Parameter(ParameterSetName="PassHash", Mandatory=$True, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True, HelpMessage='The username of a PRTG user.')]
[String]$Username,
[Parameter(ParameterSetName="PassHash", Mandatory=$True, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True, HelpMessage='The passhash of a PRTG user.')]
[String]$PassHash,
[Parameter(Mandatory=$False, ValueFromPipeline=$False, ValueFromPipelineByPropertyName=$True, HelpMessage='The URL of the PRTG API.')]
[String]$Url
)
If (!$Session) { $Session = @{Url = $Url; Credentials = $Credentials; Username = $Username; PassHash = $PassHash} }
$Result = Invoke-PRTGAPI -Endpoint "rename.htm" -Parameters @{id = $SensorID; value=$Name} -Session $Session
$Result
#If ($Result -Match 'id=(?<ID>\d+)') #TODO: make this more robust
#{
# Return New-Object PSObject -Property @{SensorID = $matches.ID}
#}
#Else
#{
# Throw "The PRTG API did not appear to Return the ID of the new sensor. The sensor was probably not successfully created."
#}
}