-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2PintFunctions.psm1
2729 lines (2292 loc) · 121 KB
/
2PintFunctions.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
#Requires -Version 5.1
New-Variable -Name Namespace -Value 'root\StifleR' -Option AllScope
New-Variable -Name API -Value "api" -Option AllScope
New-Variable -Name WebService -Value $false -Option AllScope
function Add-Subnet {
<#
.SYNOPSIS
Use this to add a subnet to StifleR
.DESCRIPTION
Just another way of adding a new subnet to StifleR
Details:
- If you don't automatically add your subnets when clients connect, this could be an alternative...
.PARAMETER SubnetID
Specify which subnetID that need to be created
.PARAMETER GatewayMAC
Specify the MAC address of the GatewayMAC, default is '00-00-00-00-00-00'
.PARAMETER TargetBandwidth
Specify the max bandwidth allowed for the Red leader on this subnet
.PARAMETER Description
Specify a description that should be added to this subnet
.PARAMETER ParentLocationID
Make this subnet a child of another subnet by using the Id of the parent
.PARAMETER LEDBATTargetBandwidth
Specify the max LEDBAT bandwidth allowed for the Red leader on this subnet
.PARAMETER VPN
Specify if this is a VPN subnet or not, default is false
.PARAMETER WellConnected
Specify if this is a WellConnected subnet or not
.PARAMETER DOType
Specify the Delivery Optimization type for this subnet, default is Group (2)
.PARAMETER SetDOGroupID
This parameter sets the Id of this new subnet as the Delivery Optimization Group ID
.PARAMETER Server (ComputerName, Computer)
This will be the server hosting the StifleR Server-service.
.EXAMPLE
Add-StiflerSubnet -Server server01 -SubnetID 172.10.10.0 -VPN $true
Creates a new subnet with the SubnetID of 172.10.10.0 and classes it as a VPN subnet
.FUNCTIONALITY
StifleR
#>
[CmdletBinding()]
param (
[Parameter(HelpMessage = "Specify StifleR server")][ValidateNotNullOrEmpty()][Alias('ComputerName','Computer','__SERVER')]
[string]$Server = $env:COMPUTERNAME,
[Parameter(Position=0,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,ValueFromRemainingArguments=$false,Mandatory=$true)]
[String]$SubnetID,
[string]$GatewayMAC='00-00-00-00-00-00',
[String]$LocationName=$SubnetID,
[uint32]$TargetBandwidth=0,
[string]$Description,
[string]$ParentLocationID,
[int]$LEDBATTargetBandwidth=0,
[bool]$VPN=$false,
[bool]$WellConnected=$false,
[ValidateSet('Not set','HTTP Only','LAN','Group','Internet','Simple','Bypass')]
[string]$DOType='Not set',
[switch]$SetDOGroupID
)
begin {
Write-Verbose "Check server availability with Test-Connection"
Write-Verbose "Check if server has the StifleR WMI-Namespace"
Test-ServerConnection $Server
$SubnetQuery = "SELECT * FROM Subnets WHERE SubnetID = '$SubnetID'"
Write-Verbose "Variable - SubnetQuery : $SubnetQuery"
Write-Verbose "Verify if subnet exist: Get-CIMInstance -ComputerName $Server -Namespace $Namespace -Class Subnets -Filter ""SubnetID = '$SubnetID'"""
if ( $(Get-CIMInstance -ComputerName $Server -Namespace $Namespace -Class Subnets -Filter "SubnetID = '$SubnetID'") ) {
Write-Warning "SubnetID $SubnetID already exist, aborting!"
break
}
}
process {
Write-Debug "Next step - Adding subnet"
try {
Write-Verbose "Adding subnet: Invoke-CimMethod -Namespace $Namespace -ClassName Subnets -MethodName AddSubnet -ComputerName $Server -Arguments @{ subnet=$SubnetID ; TargetBandwidth=$TargetBandwidth ; locationName=$LocationName ; description=$Description ; GatewayMAC=$GatewayMAC ; ParentLocationId=$ParentLocationID } | out-null"
Invoke-CimMethod -Namespace $Namespace -ClassName Subnets -MethodName AddSubnet -ComputerName $Server -Arguments @{ subnet=$SubnetID ; TargetBandwidth=$TargetBandwidth ; locationName=$LocationName ; description=$Description ; GatewayMAC=$GatewayMAC ; ParentLocationId=$ParentLocationID } | out-null
$NewSubnetSuccess = $true
Write-Verbose 'Variable - NewSubnetSuccess : $true'
Write-Output "Successfully added the subnet $SubnetID with the following parameters: TargetBanwidth: $TargetBandwidth locationName=$LocationName description=$Description GatewayMAC=$GatewayMAC ParentLocationId=$ParentLocationID"
Write-EventLog -ComputerName $Server -LogName StifleR -Source "StifleR" -EventID 9202 -Message "Successfully added the subnet $SubnetID with the following parameters: TargetBanwidth: $TargetBandwidth locationName=$LocationName description=$Description GatewayMAC=$GatewayMAC ParentLocationId=$ParentLocationID" -EntryType Information
}
catch {
Write-Warning "Failed to add the subnet $SubnetID with the following parameters: TargetBanwidth: $TargetBandwidth locationName=$LocationName description=$Description GatewayMAC=$GatewayMAC ParentLocationId=$ParentLocationID"
Write-EventLog -ComputerName $Server -LogName StifleR -Source "StifleR" -EventID 9203 -Message "Failed to add the subnet $SubnetID with the following parameters: TargetBanwidth: $TargetBandwidth locationName=$LocationName description=$Description GatewayMAC=$GatewayMAC ParentLocationId=$ParentLocationID" -EntryType Error
}
if ( $NewSubnetSuccess -eq $true ) {
Write-Debug "Next step - Modify properties"
if ( $LEDBATTargetBandwidth -ne 0 ) {
Write-Debug "Next step - Modify property LEDBATTargetBandwidth"
try {
Write-Verbose "Modifying subnet: Set-CimInstance -Namespace $Namespace -Query $SubnetQuery -Property @{LEDBATTargetBandwidth = $LEDBATTargetBandwidth} -ComputerName $Server"
Set-CimInstance -Namespace $Namespace -Query $SubnetQuery -Property @{LEDBATTargetBandwidth = $LEDBATTargetBandwidth} -ComputerName $Server
Write-Output "Successfully changed the property LEDBATTargetBandwidth on subnet $SubnetID to $LEDBATTargetBandwidth"
Write-EventLog -ComputerName $Server -LogName StifleR -Source "StifleR" -EventID 9204 -Message "Successfully changed the property LEDBATTargetBandwidth on subnet $SubnetID to $LEDBATTargetBandwidth" -EntryType Information
}
catch {
Write-Warning "Failed to change the property LEDBATTargetBandwidth on subnet $SubnetID to $LEDBATTargetBandwidth"
Write-EventLog -ComputerName $Server -LogName StifleR -Source "StifleR" -EventID 9205 -Message "Failed to change the property LEDBATTargetBandwidth on subnet $SubnetID to $LEDBATTargetBandwidth" -EntryType Error
}
}
if ( $VPN -eq $True ) {
Write-Debug "Next step - Modify property VPN"
try {
$Arguments = @{ value = $VPN }
Invoke-CimMethod -Namespace $Namespace -Query "SELECT * FROM Subnets Where SubnetID = '$SubnetID'" -MethodName SetAsVPN -ComputerName $Server -Arguments $Arguments -ErrorAction Stop | out-null
Write-Output "Successfully changed the property VPN on subnet $SubnetID to $VPN"
Write-EventLog -ComputerName $Server -LogName StifleR -Source "StifleR" -EventID 9226 -Message "Successfully changed the property VPN on subnet $SubnetID to $VPN" -EntryType Information
}
catch {
Write-Warning "Failed to change the property VPN on subnet $SubnetID to $VPN"
Write-EventLog -ComputerName $Server -LogName StifleR -Source "StifleR" -EventID 9227 -Message "Failed to change the property VPN on subnet $SubnetID to $VPN" -EntryType Error
}
}
if ( $WellConnected -eq $True ) {
Write-Debug "Next step - Modify property WellConnected"
try {
Write-Verbose "Modifying subnet: Set-CimInstance -Namespace $Namespace -Query $SubnetQuery -Property @{WellConnected = $WellConnected } -ComputerName $Server"
$Arguments = @{ value = $WellConnected }
Invoke-CimMethod -Namespace $Namespace -Query "SELECT * FROM Subnets Where SubnetID = '$SubnetID'" -MethodName SetAsWellConnected -ComputerName $Server -Arguments $Arguments -ErrorAction Stop | out-null
Write-Output "Successfully changed the property WellConnected on subnet $SubnetID to $WellConnected"
Write-EventLog -ComputerName $Server -LogName StifleR -Source "StifleR" -EventID 9224 -Message "Successfully changed the property WellConnected on subnet $SubnetID to $WellConnected" -EntryType Information
}
catch {
Write-Warning "Failed to change the property WellConnected on subnet $SubnetID to $WellConnected"
Write-EventLog -ComputerName $Server -LogName StifleR -Source "StifleR" -EventID 9225 -Message "Failed to change the property WellConnected on subnet $SubnetID to $WellConnected" -EntryType Error
}
}
if ( $DOType -ne 'Not set' ) {
Write-Debug "Next step - Modify property DOType"
if ( $DOType -eq 'HTTP Only' ) { [int]$DOType = 0 }
if ( $DOType -eq 'LAN' ) { [int]$DOType = 1 }
if ( $DOType -eq 'Group' ) { [int]$DOType = 2 }
if ( $DOType -eq 'Internet' ) { [int]$DOType = 3 }
if ( $DOType -eq 'Simple' ) { [int]$DOType = 99 }
if ( $DOType -eq 'Bypass' ) { [int]$DOType = 100 }
Write-Verbose "Modified variable: DOType has now the value of $DOType"
try {
Write-Verbose "Set-CimInstance -Namespace $Namespace -Query $SubnetQuery -Property @{DODownloadMode = $DOType } -ComputerName $Server"
Set-CimInstance -Namespace $Namespace -Query $SubnetQuery -Property @{DODownloadMode = $DOType } -ComputerName $Server
Write-Output "Successfully changed the property DODownloadMode on subnet $SubnetID to $DOType"
Write-EventLog -ComputerName $Server -LogName StifleR -Source "StifleR" -EventID 9204 -Message "Successfully changed the property DODownloadMode on subnet $SubnetID to $DOType" -EntryType Information
}
catch {
Write-Warning "Failed to change the property DODownloadMode on subnet $SubnetID to $DOType"
Write-EventLog -ComputerName $Server -LogName StifleR -Source "StifleR" -EventID 9205 -Message "Failed to change the property DODownloadMode on subnet $SubnetID to $DOType" -EntryType Error
}
}
if ( $SetDOGroupID ) {
Write-Debug "Next step - Modify property DOGroupID"
Write-Verbose "Get Subnets ID (not SubnetID): Get-CIMInstance -Namespace $Namespace -Class Subnets -Filter ""SubnetID LIKE '%$SubnetID%'"" -ComputerName $Server"
$id = $(Get-CIMInstance -Namespace $Namespace -Class Subnets -Filter "SubnetID LIKE '%$SubnetID%'" -ComputerName $Server).id
Write-Verbose "Subnets ID is = $id"
try {
Write-Verbose "Set-CimInstance -Namespace $Namespace -Query $SubnetQuery -Property @{DOGroupID = $id } -ComputerName $Server"
Set-CimInstance -Namespace $Namespace -Query $SubnetQuery -Property @{DOGroupID = $id } -ComputerName $Server
Write-Output "Successfully changed the property DOGroupID on subnet $SubnetID to $id"
Write-EventLog -ComputerName $Server -LogName StifleR -Source "StifleR" -EventID 9204 -Message "Successfully changed the property DOGroupID on subnet $SubnetID to $id" -EntryType Information
}
catch {
Write-Warning "Failed to change the property DOGroupID on subnet $SubnetID to $id"
Write-EventLog -ComputerName $Server -LogName StifleR -Source "StifleR" -EventID 9205 -Message "Failed to change the property DOGroupID on subnet $SubnetID to $id" -EntryType Error
}
}
}
}
}
function Get-Client {
<#
.SYNOPSIS
Get information about the clients available in StifleR.
.DESCRIPTION
Pull client details from the server hosting the StifleR Server service.
Details:
- This skips the necessity of using WBEMTest or similiar tools to WMIExplorer to get the same information...
.PARAMETER Client
Specify the full name (or partial for multiple results) of the client you want to display information about
.PARAMETER Property
Use specific properties contained in the WMI class Clients in the StifleR namespace.
.PARAMETER Server (ComputerName, Computer)
This will be the server hosting the StifleR Server-service.
.PARAMETER ExactMatch
Use this switch if you want to look for the exact match of the specified value of the Client parameter
.PARAMETER Roaming
Use this switch if you want to look for roaming clients instead
.PARAMETER SubnetID
Use this parameter if you want to display all clients on a specific subnet
.PARAMETER IsConnected
Use this parameter if you want to display all clients with a current connection
.PARAMETER Method
Use this parameter if you want to get specified WMI information from the client,
available options are 'GetBranchCacheFlags' and 'GetConnectionFlags'
Can only return values from a single client per run
.EXAMPLE
Get-StiflerClient -Client Client01 -Server 'server01'
Pull information about the client Client01 from server01
.EXAMPLE
Get-StifleRClient -Server server01 -SubnetID 192. -IsConnected
Get all clients from subnet 192.* that have an active connection at the moment
.EXAMPLE
Get-StifleRClient -Server server01 -Client client01 -Method GetConnectionFlags
Get current connections flags from client01
.FUNCTIONALITY
StifleR
#>
[cmdletbinding(DefaultParameterSetName='Client')]
param (
[Parameter(Mandatory,HelpMessage = "Specify the client you want to retrieve information about",ValueFromPipeline, ValueFromPipelineByPropertyName,ParameterSetName = "Client")]
[Parameter(Mandatory,ParameterSetName = "Methods")]
[string[]]$Client,
[Parameter(HelpMessage = "Specify StifleR server")][ValidateNotNullOrEmpty()][Alias('ComputerName','Computer','__SERVER')]
[string]$Server = $env:COMPUTERNAME,
[Parameter(HelpMessage = "Specify specific properties",ParameterSetName = "Subnet")]
[string]$SubnetID,
[Parameter(ParameterSetName = "Client")]
[Parameter(ParameterSetName = "Roaming")]
[Parameter(ParameterSetName = "Subnet")]
[array]$Property,
[Parameter(ParameterSetName = "Client")]
[switch]$ExactMatch,
[Parameter(ParameterSetName = "Roaming")]
[Parameter(ParameterSetName = "Methods")]
[switch]$Roaming,
[Parameter(ParameterSetName = "Subnet")]
[Parameter(ParameterSetName = "Client")]
[switch]$IsConnected,
[Parameter(ParameterSetName = "Methods")]
[ValidateSet('GetBranchCacheFlags','GetConnectionFlags')]
[string]$Method
)
begin {
[array]$MissingProps = @()
[array]$ClassProperties = @()
if ( $Server -match 'http[s]?://' ) {
try {
Invoke-RestMethod -Uri "$Server/$API" -UseDefaultCredentials -TimeoutSec 2
}
catch {
if ( $_.Exception.Message -match 'The remote name could not be resolved' ) {
Write-Warning "The server could not be contacted (could not be resolved), aborting!"
break
}
if ( $_.Exception.Message -match 'The operation has timed out' ) {
Write-Warning "The server could not be contacted (timed out), verify if 'HTTP' or 'HTTPS' should be used and that the correct port is used, aborting!"
break
}
}
$WebService = $true
}
else {
Write-Verbose "Check server availability with Test-Connection"
Write-Verbose "Check if server has the StifleR WMI-Namespace"
Test-ServerConnection $Server
$WebService = $false
}
if ( !$WebService ) {
if ( $Roaming ) {
$Class = 'ClientsRoaming'
}
else {
$Class = 'Clients'
}
if ( $IsConnected ) {
$Class = 'Connections'
}
if ( $Property -ne '*' ) {
$ClassProperties = (Get-CimClass -ComputerName $Server -ClassName $Class -Namespace $Namespace ).CimClassProperties.Name
foreach ( $Prop in $($Property) ) {
if ( $ClassProperties -notcontains $Prop ) { $MissingProps += "$Prop" }
}
if ( $MissingProps.Count -gt 0 ) {
$MissingProps = $MissingProps -join ', '
Write-Error -Message "One or more of the following properties couldn't be found in the class $Class`: $MissingProps"
break
}
}
}
if ( $IsConnected ) {
$defaultProperties = @(‘ComputerName’,'Version','LastCheckInTime','NetworkId')
}
elseif ( $Roaming ) {
$defaultProperties = @(‘ComputerName’,'Version')
}
elseif ( $WebService ) {
$defaultProperties = @(‘ComputerName’,'StifleRAgentId','Online')
}
else {
$defaultProperties = @(‘ComputerName’,'Version','Online')
}
$defaultDisplayPropertySet = New-Object System.Management.Automation.PSPropertySet(‘DefaultDisplayPropertySet’,[string[]]$defaultProperties)
$PSStandardMembers = [System.Management.Automation.PSMemberInfo[]]@($defaultDisplayPropertySet)
if ( $Property -eq '*' ) { $defaultProperties = '*' }
if ( $Property -ne $Null -and $Property -notcontains '*' ) { $defaultProperties = $Property }
if ( $SubnetID ) {
[bool]$SubnetIDExist = $false
if ( !$WebService ) {
[array]$SubnetExist = Get-Subnet -Server $Server -SubnetID $SubnetID
if ( $SubnetExist.Count -gt 0 ) {
$SubnetIDExist = $True
}
else {
Write-Warning "The provided SubnetID $SubnetID does not exist, aborting!"
break
}
}
else {
[array]$SubnetExist = Invoke-RestMethod -Uri "$Server/$API/location/$SubnetID" -UseDefaultCredentials #| out-null
if ( $SubnetExist -ne 'null' ) {
$SubnetIDExist = $True
}
else {
Write-Warning "The provided SubnetID $SubnetID does not exist, aborting!"
break
}
}
}
}
process {
if ( $PSCmdlet.ParameterSetName -eq 'Methods' ) {
if ( $WebService ) {
Write-Warning "Those methods are not currently supported through the web service API, aborting!"
}
else {
if ( $Roaming ) {
$Class = 'ClientsRoaming'
}
else {
$Class = 'Connections'
}
$MethodObj = New-Object PSObject
$MethodResult = @()
$MethodResult = $(Invoke-CimMethod -Namespace $Namespace -Query "SELECT * FROM $Class Where ComputerName = '$Client'" -MethodName $Method -ComputerName $Server).ReturnValue -Split "`r`n"
if ( $MethodResult ) {
foreach ( $line in $MethodResult ) {
if ( $line -ne '' ) {
$Temp = $($line.Split(';'))[0]
$Name = $Temp.Substring($temp.IndexOf(']')+1,$temp.Length - $temp.IndexOf(']')-1)
$MethodObj | Add-member -MemberType NoteProperty -Name $Name -Value $line.split(';')[1] -Force
}
}
}
if ( !$MethodResult ) {
Write-Warning "The provided Client is missing an active connection in StifleR, aborting!"
}
else {
return $MethodObj
}
}
}
else {
$ClientInformation = @()
if ( $ExactMatch -or $WebService ) {
if ( $WebService ) {
$ClientInformation = Invoke-RestMethod -Uri "$Server/$API/search/client/$Client" -UseDefaultCredentials | ConvertFrom-Json | Select-Object -ExpandProperty *
}
else {
$ClientInformation = Get-CIMInstance -Namespace $Namespace -Class $Class -Filter "ComputerName = '$Client'" -ComputerName $Server
}
}
else {
if ( $SubnetIDExist ) {
$ids = $(Get-CIMInstance -Namespace $Namespace -Class Subnets -Filter "SubnetID LIKE '%$SubnetID%'" -ComputerName $Server).id
foreach ( $id in $ids ) {
if ( $IsConnected ) {
$ClientInformation += Get-CIMInstance -Namespace $Namespace -Class $Class -Filter "NetworkGuid = '$id'" -ComputerName $Server
}
else {
$ClientInformation += Get-CIMInstance -Namespace $Namespace -Class $Class -Filter "LastOnNetwork = '$id'" -ComputerName $Server
}
}
}
else {
if ( $Client -eq '*' ) { $Client = '' }
$ClientInformation = Get-CIMInstance -Namespace $Namespace -Class $Class -Filter "ComputerName LIKE '%$Client%'" -ComputerName $Server
}
}
$ClientInformation | Add-Member MemberSet PSStandardMembers $PSStandardMembers
if ( $ClientInformation.Count -eq 0 ) {
Write-Warning "No events found with the matching criterias, aborting!"
}
else {
if ( !$WebService ) {
$ClientInformation | Select-Object $defaultProperties -ExcludeProperty PSComputerName,Cim*
}
else {
$ClientInformation | Select-Object $defaultProperties #| Select-Object -ExpandProperty *
}
}
}
}
}
function Get-ClientVersion {
<#
.SYNOPSIS
Gets all settings from the Servers configuration file
.DESCRIPTION
Get a summary of StifleR Agent versions
Details:
- Get a summary of StifleR Agent versions on clients you have in your environment
and the number of clients with each version
.PARAMETER Server (ComputerName, Computer)
This will be the server hosting the StifleR Server-service.
.EXAMPLE
get-StifleRClientVersion -Server server01
Get the versions for clients from server01
.FUNCTIONALITY
StifleR
#>
[CmdletBinding()]
param (
[Parameter(HelpMessage = "Specify StifleR server")][ValidateNotNullOrEmpty()][Alias('ComputerName','Computer','__SERVER')]
[string]$Server = $env:COMPUTERNAME
)
begin {
Write-Verbose "Check server availability with Test-Connection"
Write-Verbose "Check if server has the StifleR WMI-Namespace"
Test-ServerConnection $Server
}
process {
$VersionInfo = @()
$Versions = $(Get-CimInstance -Namespace $Namespace -Query "Select * from Clients" -ComputerName $Server | Select-Object -Unique version ).version
foreach ( $Version in $Versions ) {
$VersionCount = $(Get-CimInstance -Namespace $Namespace -Query "Select * from Clients Where Version = '$Version'" -ComputerName $Server ).Count
$VersionInfo += New-Object -TypeName psobject -Property @{Version=$Version; Clients=$VersionCount}
}
$VersionInfo | Sort-Object Version -Descending
}
}
function Get-Download {
<#
.SYNOPSIS
Use this get information about the downloads in StifleR
.DESCRIPTION
Get information about downloads
Details:
- Get information about downloads
.PARAMETER Client
Specify this parameter if you need to instantly terminate the process
.PARAMETER Property
Specify which properties to return from the function
.PARAMETER State
Specify what state (of the download) to look, available options if used are
'Caching','Canceled','Connecting','Error','Suspended','Transferring','TransientError' and 'Queued'
.PARAMETER Server (ComputerName, Computer)
This will be the server hosting the StifleR Server-service.
.EXAMPLE
Get-StifleRDownload -Server server01
Get all downloads for all clients from 'server01'
.EXAMPLE
Get-StifleRDownload -Server server01 -Client client01
Get all downloads for 'client01'
.EXAMPLE
Get-StifleRDownload -Server server01 -State Error -Property ComputerName, State, ID
Get all downloads for all clients that matches the state 'Error' and only returns the properties
ComputerName, State and ID
.FUNCTIONALITY
StifleR
#>
[cmdletbinding()]
param (
[Parameter(HelpMessage = "Specify StifleR server")][ValidateNotNullOrEmpty()][Alias('ComputerName','Computer','__SERVER')]
[string]$Server = $env:COMPUTERNAME,
[string]$Client,
[array]$Property,
[ValidateSet('Caching','Canceled','Connecting','Error','Suspended','Transferring','TransientError','Queued')]
[string]$State
)
begin {
$MissingProps = @()
$ClassProperties = @()
Write-Verbose "Check server availability with Test-Connection"
Write-Verbose "Check if server has the StifleR WMI-Namespace"
Test-ServerConnection $Server
$defaultProperties = @(‘ComputerName’,'Created','ID','State','StifleRID')
$defaultDisplayPropertySet = New-Object System.Management.Automation.PSPropertySet(‘DefaultDisplayPropertySet’,[string[]]$defaultProperties)
$PSStandardMembers = [System.Management.Automation.PSMemberInfo[]]@($defaultDisplayPropertySet)
if ( $Property -ne '*' ) {
$ClassProperties = (Get-CimClass -ComputerName $Server -ClassName Downloads -Namespace $Namespace ).CimClassProperties.Name
foreach ( $Prop in $($Property) ) {
if ( $ClassProperties -notcontains $Prop ) { $MissingProps += "$Prop" }
}
if ( $MissingProps.Count -gt 0 ) {
$MissingProps = $MissingProps -join ', '
Write-Error -Message "One or more of the following properties couldn't be found in the Class Downloads: $MissingProps"
break
}
}
if ( $Property -eq '*' ) { $defaultProperties = '*' }
if ( $Property -ne $Null -and $Property -notcontains '*' ) { $defaultProperties = $Property }
}
process {
$Downloads = @()
$Downloads = Get-CimInstance -Namespace $Namespace -Query "Select * from Downloads Where ComputerName Like '%$Client%' And State Like '$State%'" -ComputerName $Server | Sort-Object Created
$Downloads | Add-Member MemberSet PSStandardMembers $PSStandardMembers
}
end {
$Downloads | Select-Object $defaultProperties -ExcludeProperty PSComputerName,Cim*
}
}
function Get-EventLog {
<#
.SYNOPSIS
Get event logs from StifleR
.DESCRIPTION
Get event logs from StifleR
Details:
- Get event logs from StifleR
.PARAMETER MaxEvents
Specify how many items that this function will try to get, it is not
the maximum returned results from it!
Default is 1000
.PARAMETER EventID
Specify one or multiple Event IDs to look for
.PARAMETER Message
Specify a string to search for in the Data field (a.k.a. Message)
.PARAMETER LevelDisplayName
Specify the type of events you want, default is 'All'
Available options are 'Trace','Debug','Information','Warning','Error','Critical'
.PARAMETER ProviderName
Specify the Provider you want to look into for events, default is 'StifleRServer'
Available options are 'All','StifleR','StifleRBeacon','StifleRClient' and 'StifleRServer'
.PARAMETER StartDate
Specify a datetime from when you want to search for events
.PARAMETER EndDate
Specify a datetime until you want to search for events
.PARAMETER ListLog
Specify this parameter if you want information about the event log
for StifleR (FileSize, RecordCount etc.).
When using this parameter all other input will be ignored!
.PARAMETER Server (ComputerName, Computer)
This will be the server hosting the StifleR Server-service.
.EXAMPLE
Get-StiflerEventLog -Server 'server01' -MaxEvents 10 | sort-object Id
Get the 10 latest events from server01 and sort them by Id, default is
by ascending TimeCreated
.EXAMPLE
Get-StiflerEventLog -Server 'server01' -LevelDisplayName Information -EventID 4821,1506
-Message Saving -StartDate (Get-Date).AddMinutes(-60)
Get all events tagged as Information, EventIDs 4821 or 1506, Message contains 'Saving'
created within the last 60 minutes
.EXAMPLE
Get-StiflerEventLog -Server 'server01' -StartDate (Get-Date).AddMinutes(-120) -EndDate (Get-Date).AddMinutes(-60)
Get all events that happened from 60 to 120 minutes ago
.FUNCTIONALITY
StifleR
#>
[cmdletbinding(DefaultParameterSetName='GetLog')]
param (
[Parameter(HelpMessage = "Specify StifleR server")][ValidateNotNullOrEmpty()][Alias('ComputerName','Computer','__SERVER')]
[string]$Server = $env:COMPUTERNAME,
[Parameter(ParameterSetName = "GetLog")]
[int]$MaxEvents = 1000,
[Parameter(ParameterSetName = "GetLog")]
[array]$EventID,
[Parameter(ParameterSetName = "GetLog")]
[string]$Message,
[Parameter(ParameterSetName = "GetLog")]
[ValidateSet('Trace','Debug','Information','Warning','Error','Critical')]
[string]$LevelDisplayName,
[ValidateSet('All','StifleR','StifleRBeacon','StifleRClient','StifleRServer')]
[Parameter(ParameterSetName = "GetLog")]
[string]$ProviderName='StifleRServer',
[Parameter(ParameterSetName = "GetLog")]
[datetime]$StartDate,
[Parameter(ParameterSetName = "GetLog")]
[datetime]$EndDate,
[Parameter(ParameterSetName = "ListLog")]
[switch]$ListLog
)
begin {
Write-Verbose "Check server availability with Test-Connection"
Write-Verbose "Check if server has the StifleR WMI-Namespace"
Test-ServerConnection $Server
}
process {
if ( $ListLog ) {
Write-Verbose "When you used the parameter -ListLog all other inputs will be ignored!"
Get-WinEvent -ComputerName $Server -ListLog StifleR | Select-Object *
}
else {
if ( $LevelDisplayName -eq 'Trace' ) { $Level = 0 }
if ( $LevelDisplayName -eq 'Debug' ) { $Level = 1 }
if ( $LevelDisplayName -eq 'Error' ) { $Level = 2 }
if ( $LevelDisplayName -eq 'Warning' ) { $Level = 3 }
if ( $LevelDisplayName -eq 'Information' ) { $Level = 4 }
if ( $LevelDisplayName -eq 'Critical' ) { $Level = 5 }
if ( $ProviderName -eq 'All' ) {
$FilterXML = "<QueryList><Query><Select Path='StifleR'>*[System[Provider]["
}
else {
$FilterXML = "<QueryList><Query><Select Path='StifleR'>*[System[Provider[@Name='$ProviderName']]["
}
If ( $LevelDisplayName ) {
$FilterXML = "$FilterXML(Level=$Level)"
$And = $true
}
else {
$FilterXML = "$FilterXML(Level=0 or Level=1 or Level=2 or Level=3 or Level=4 or Level=5)"
$And = $true
}
if ( $EventID.Count -ge 1 ) {
[int]$Counter = 0
foreach ( $Id in $EventID ) {
if ( $Counter -eq 0 ) {
if ( $And -eq $true ) {
$FilterXML = "$FilterXML and (EventID=$Id"
}
else {
$FilterXML = "$FilterXML(EventID=$Id"
$And -eq $true
}
}
else {
$FilterXML = "$FilterXML or EventID=$Id"
}
$Counter++
}
$FilterXML = "$FilterXML)"
$And = $true
}
$FilterXML = "$FilterXML]]</Select></Query></QueryList>"
Write-Verbose "FilterXML string : $FilterXML"
try {
[array]$Events = Get-WinEvent -ComputerName $Server -MaxEvents $MaxEvents -FilterXML $FilterXML -ErrorAction Stop #| out-null
if ( $StartDate -or $EndDate ) {
if ( $StartDate -and !$EndDate) {
$Events = $Events | Where-Object TimeCreated -ge $StartDate
}
if ( !$StartDate -and $EndDate) {
$Events = $Events | Where-Object TimeCreated -le $EndDate
}
if ( $StartDate -and $EndDate ) {
$Events = $Events | Where-Object { $_.TimeCreated -le $EndDate -and $_.TimeCreated -ge $StartDate }
}
}
if ( $Message ) {
$Events = $Events | Where-Object Message -like "*$Message*" | Sort-Object TimeCreated
}
if ( $Events.Count -eq 0 ) {
Write-Warning "No events found with the matching criterias, aborting!"
}
else {
$Events | Sort-Object TimeCreated
}
}
catch {
if ( $Events.Count -eq 0 ) {
Write-Warning "No events found with the matching criterias, aborting!"
}
}
}
}
}
function Get-ErrorDescription {
<#
.SYNOPSIS
Get information about error codes
.DESCRIPTION
Get information about error codes
.PARAMETER Server (ComputerName, Computer)
This will be the server hosting the StifleR Server-service.
.PARAMETER ErrorCode
Put the error code here to get its matching string description
.EXAMPLE
Get-StifleRErrorDescription -server 'server01' -ErrorCode 4062
Get information about what 4062 means
.FUNCTIONALITY
StifleR
#>
[CmdletBinding()]
param (
[Parameter(HelpMessage = "Specify StifleR server")][ValidateNotNullOrEmpty()][Alias('ComputerName','Computer','__SERVER')]
[string]$Server = $env:COMPUTERNAME,
[Parameter(Mandatory)]
[uint32]$ErrorCode
)
begin {
Write-Verbose "Check server availability with Test-Connection"
Write-Verbose "Check if server has the StifleR WMI-Namespace"
Test-ServerConnection $Server
}
process {
$Arguments = @{ errorcode = $ErrorCode }
(Invoke-CimMethod -Namespace $Namespace -ClassName StifleREngine -MethodName GetErrorDescription -ComputerName $Server -Arguments $Arguments).ReturnValue
}
}
function Get-Leader {
<#
.SYNOPSIS
Use this to get a list of leaders (Red\Blue)
.DESCRIPTION
Use this to get a list of leaders (Red\Blue)
Details:
- Use this to get a list of leaders (Red\Blue)
.PARAMETER SubnetID (Alias NetworkID)
Specify this parameter if you need to instantly terminate the process
.PARAMETER Server (ComputerName, Computer)
This will be the server hosting the StifleR Server-service.
.EXAMPLE
Get-StifleRLeader -Server 'sserver01'
Stops the StifleRServer service on server01
.FUNCTIONALITY
StifleR
#>
[cmdletbinding()]
param (
[Parameter(HelpMessage = "Specify StifleR server")][ValidateNotNullOrEmpty()][Alias('ComputerName','Computer','__SERVER')]
[string]$Server = $env:COMPUTERNAME,
[Alias('NetworkID')]
[string]$SubnetID
)
begin {
Write-Verbose "Check server availability with Test-Connection"
Write-Verbose "Check if server has the StifleR WMI-Namespace"
Test-ServerConnection $Server
}
process {
if ( $SubnetID ) {
$QueryAddition = "WHERE NetworkID Like '%$SubnetID%'"
}
$Leaders = @()
[array]$RedLeaders = Get-CimInstance -Namespace $Namespace -Query "Select * from RedLeaders $QueryAddition" -ComputerName $Server | Select-Object * -ExcludeProperty PSComputerName,PSShowComputerName,CimClass,CimInstanceProperties,CimSystemProperties
if ( $RedLeaders.Count -gt 0 ) {
$RedLeaders | Add-Member -Name 'LeaderType' -Value 'Red' -MemberType NoteProperty | out-null
$Leaders += $RedLeaders
}
[array]$BlueLeaders = Get-CimInstance -Namespace $Namespace -Query "Select * from BlueLeaders $QueryAddition" -ComputerName $Server | Select-Object * -ExcludeProperty PSComputerName,PSShowComputerName,CimClass,CimInstanceProperties,CimSystemProperties
if ( $BlueLeaders.Count -gt 0 ) {
$BlueLeaders | Add-Member -Name 'LeaderType' -Value 'Blue' -MemberType NoteProperty | out-null
$Leaders += $BlueLeaders
}
$Leaders | Sort-Object NetworkID
}
}
function Get-LicenseInformation {
<#
.SYNOPSIS
Use this to get information about your StifleR license
.DESCRIPTION
Information about your StifleR License
Details:
- Information about your StifleR License
.PARAMETER InstallDir
Specify the Installation directory for StifleR Server,
default is 'C$\Program Files\2Pint Software\StifleR'
.PARAMETER Server (ComputerName, Computer)
This will be the server hosting the StifleR Server-service.
.EXAMPLE
Get-StiflerLicenseInformation -Server server01
Get information from License.nfo file on server01
.FUNCTIONALITY
StifleR
#>
[cmdletbinding()]
param (
[Parameter(HelpMessage = "Specify StifleR server")][ValidateNotNullOrEmpty()][Alias('ComputerName','Computer','__SERVER')]
[string]$Server = $env:COMPUTERNAME,
[string]$InstallDir='C$\Program Files\2Pint Software\StifleR'
)
begin {
Write-Verbose "Check server availability with Test-Connection"
Write-Verbose "Check if server has the StifleR WMI-Namespace"
Test-ServerConnection $Server
}
process {
try {
Write-Verbose "Get content from license file : (Get-Content ""\\$Server\$InstallDir\License.nfo"").Where({ $_ -eq '[Licensing]'},'SkipUntil')"
$Content = (Get-Content "\\$Server\$InstallDir\License.nfo").Where({ $_ -eq '[Licensing]'},'SkipUntil')
$LicenseProperties = [PSCustomObject]@{}
foreach ( $LicProp in $Content ) {
if ( $LicProp -ne '[Licensing]' ) {
$Attrib = $LicProp.Split('=')
$LicenseProperties | Add-Member -Name $Attrib[0] -Value $Attrib[1] -MemberType NoteProperty
}
}
$LicenseProperties | Add-Member -Name 'DaysLeft' -Value $(New-TimeSpan -Start (get-date) -End $LicenseProperties.ExpiryDate).Days -MemberType NoteProperty
$LicenseProperties
}
catch {
Write-Warning "Failed to get information from the license file on server $Server"
}
}
}
function Get-ServerSettings {
<#
.SYNOPSIS
Gets all settings from the Servers configuration file
.DESCRIPTION
Gets all values from servers configuration file
Details:
- GGets all values from servers configuration file
.PARAMETER InstallDir
Specify the Installation directory for StifleR Server,
default is 'C$\Program Files\2Pint Software\StifleR'
.PARAMETER Server (ComputerName, Computer)
This will be the server hosting the StifleR Server-service.
.EXAMPLE
get-StifleRServerSettings -Server server01
Get the settings from server01
.EXAMPLE
Get-StifleRServerSettings -Server server01 -InstallDir
'D$\Program Files\2Pint Software\StifleR'
Get the settings from server01 where the installations directory for StifleR Server is
'D$\Program Files\2Pint Software\StifleR' instead of the default directory
.FUNCTIONALITY
StifleR
#>
[CmdletBinding()]
param (
[Parameter(HelpMessage = "Specify StifleR server")][ValidateNotNullOrEmpty()][Alias('ComputerName','Computer','__SERVER')]
[string]$Server = $env:COMPUTERNAME,
[string]$InstallDir='C$\Program Files\2Pint Software\StifleR',
[switch]$SortByKeyName
)
begin {
Write-Verbose "Check server availability with Test-Connection"
Write-Verbose "Check if server has the StifleR WMI-Namespace"
Test-ServerConnection $Server
}
process {
try {
[xml]$Content = Get-Content "\\$Server\$InstallDir\StifleR.Service.exe.config" -ErrorAction 1
$Properties = @()
$Properties += $Content.configuration.appSettings.add
$obj = New-Object PSObject
foreach ( $Prop in $Properties | Sort-Object Key ) {
$obj | Add-Member -MemberType NoteProperty -Name $Prop.key -Value $Prop.value
}
return $obj
}
catch {
Write-Error "Failed to obtain properties from $Server, check InstallDir and access permissions."
}
}
}