-
Notifications
You must be signed in to change notification settings - Fork 4
/
PFERemediationScript.ps1
3425 lines (2860 loc) · 159 KB
/
PFERemediationScript.ps1
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
# ==================================================================
# This Sample Code is provided for the purpose of illustration only
# and is not intended to be used in a production environment.
# THIS SAMPLE CODE AND ANY RELATED INFORMATION ARE PROVIDED "AS IS" WITHOUT
# WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED
# TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
# PURPOSE. We grant You a nonexclusive, royalty-free right to use and modify
# the Sample Code and to reproduce and distribute the object code form of the
# Sample Code, provided that You agree: (i) to not use Our name, logo, or
# trademarks to market Your software product in which the Sample Code is
# embedded; (ii) to include a valid copyright notice on Your software product
# in which the Sample Code is embedded; and (iii) to indemnify, hold harmless,
# and defend Us and Our suppliers from and against any claims or lawsuits,
# including attorneys’ fees, that arise or result from the use or
# distribution of the Sample Code.
#
# ==================================================================
#Current Version information for script
[string]$strScriptBuild = "201708221005"
[string]$strScriptVersion = "16.03.5.4" + "." + $strScriptBuild
#region #################################### START FUNCTIONS ####################################>
#region Write-CHLog
Function Write-CHLog (){
<#
.SYNOPSIS
Log output and function called
.DESCRIPTION
Accepts string values for the function called and for the actual message to be logged and writes it to the main PFE Script logfile
.EXAMPLE
Write-CHLog -function "RegWrite" -message "Setting XXXX in the registry"
.EXAMPLE
Write-CHLog "RegWrite" "Setting XXXX in the registry"
.PARAMETER Function
The function that called for Write-CHLog
.PARAMETER Message
The content of the message to be logged
#>
param
(
[Parameter(Mandatory=$True,
ValueFromPipelineByPropertyName=$True)]
[string]$strFunction,
[Parameter(Mandatory=$True,
ValueFromPipelineByPropertyName=$True)]
[string]$strMessage
)
<#
$strFunction = "Main"
$strMessage = "Test Write-CHLog"
#>
#set log file location
[string]$strLogFile = "$global:strCurrentLocation\PS-PFERemediationScript.log"
#define output to log file
[string]$strOutput = (Get-Date -Format "yyyy-MM-dd HH:mm:ss:ff") + " - " + $strFunction + "(): " + $strMessage
#append the output to the file; this will create the file if necessary as well
Try{
$strOutput | Out-File -FilePath $strLogFile -Append
}
Catch{
"Cannot write to log file; exiting script"
Exit(1)
}
}#endregion Write-CHLog
#region Get-CHRegistryValue
Function Get-CHRegistryValue (){
<#
.SYNOPSIS
Read Registry Value
.DESCRIPTION
Accepts string values for registry key and registry value requested
.EXAMPLE
Get-CHRegistryValue -strRegKey $strPFEKeyPath -strRegValue "ScriptLog"
.EXAMPLE
Get-CHRegistryValue "HKLM:\SOFTWARE\Microsoft\CCM\Logging\@Global" "LogDirectory"
.PARAMETER strRegKey
The path to the registry key being requested
.PARAMETER strRegValue
The name of the registry value requested
#>
param
(
[Parameter(Mandatory=$True,
ValueFromPipelineByPropertyName=$True)]
[string]$strRegKey,
[Parameter(Mandatory=$True,
ValueFromPipelineByPropertyName=$True)]
[string]$strRegValue
)
if($global:blnDebug ){ Write-CHLog "Get-CHRegistryValue" "Getting registry value for $strRegKey\$strRegValue" }
Try{
$strRegRead = Get-Item $strRegKey -ErrorAction Stop | ForEach { $_.GetValue($strRegValue) }
if ($strRegRead -eq $null){
$strRegRead = ""
If($global:blnDebug ){ Write-CHLog "Get-CHRegistryValue" "Warning: The value for $strRegKey\$strRegValue is empty" }
}
}
Catch{
$strRegRead = "Error"
$strErrorMsg = ($Error[0].toString()).Split(".")[0]
Write-CHLog "Get-CHRegistryValue" "Failed to get $strRegValue as the path $strRegKey does not exist"
Write-CHLog "Get-CHRegistryValue" "Return error: $strErrorMsg"
}
#returning status
if($global:blnDebug ){Write-CHLog "Get-CHRegistryValue" "Return value is $strRegRead"}
return $strRegRead
}#endregion Get-CHRegistryValue
#region Set-CHRegistryValue
Function Set-CHRegistryValue (){
<#
.SYNOPSIS
Write Registry Value
.DESCRIPTION
Accepts string values for registry key and registry value to include data and data type to write
.EXAMPLE
Set-CHRegistryValue -strRegKey "HKLM:\SOFTWARE\Microsoft\Microsoft PFE Remediation for Configuration Manager" -strRegValue "Test Set Reg Value" -strData "Worked again"
.EXAMPLE
Set-CHRegistryValue "HKLM:\SOFTWARE\Microsoft\Microsoft PFE Remediation for Configuration Manage" -strRegValue "Test New Reg Value" -strData "Worked" -strDataType "string"
.PARAMETER strRegKey
The path to the registry key being requested
.PARAMETER strRegValue
The name of the registry value requested
.PARAMETER strData
The path to the registry key being requested
.PARAMETER strDataType
The data type for a new registry entry; this is only required if blnNew is True; setting to not mandatory since creating new registry entries is rare
.PARAMETER blnNew
To force the type of a new registry entry, the type is required; if blnNew is True, strDataType will be used to force this type
#>
param
(
[Parameter(Mandatory=$True,
ValueFromPipelineByPropertyName=$True)]
[string]$strRegKey,
[Parameter(Mandatory=$True,
ValueFromPipelineByPropertyName=$True)]
[string]$strRegValue,
[Parameter(Mandatory=$True,
ValueFromPipelineByPropertyName=$True)]
[string]$strData,
[Parameter(Mandatory=$False,
ValueFromPipelineByPropertyName=$True)]
[ValidateSet('dword','string','qword','expandstring','binary','multistring')]
[string]$strDataType
)
if($strDataType -ne "multistring"){
[string]$strRegKeyExists = Get-CHRegistryValue -strRegKey $strRegKey -strRegValue $strRegValue
#for cases where new registry values are written, new-itemproperty will set the type
if ($strRegKeyExists -eq "Error"){
#logging
if($global:blnDebug ){ Write-CHLog "Set-CHRegistryValue" "Setting new registry value for $strRegKey\$strRegValue to $strData" }
Try{
New-ItemProperty $strRegKey -Name $strRegValue -Value $strData -PropertyType $strDataType -ErrorAction Stop | Out-Null
if($global:blnDebug ){ Write-CHLog "Set-CHRegistryValue" "New registry value $strRegKey\$strRegValue was created; the value was set to $strData" }
}
Catch{
$strErrorMsg = ($Error[0].toString()).Split(".")[0]
Write-CHLog "Set-CHRegistryValue" "New registry value $strRegKey\$strRegValue was not created; the error is $strErrorMsg"
}
}
else{
#logging
if($global:blnDebug ){ Write-CHLog "Set-CHRegistryValue" "Setting registry value for $strRegKey\$strRegValue to $strData" }
#most cases are updating existing registry entries
Try{
Set-ItemProperty $strRegKey -Name $strRegValue -Value $strData -ErrorAction Stop
if($global:blnDebug ){ Write-CHLog "Set-CHRegistryValue" "Registry value $strRegKey\$strRegValue was set to $strData" }
}
Catch{
$strErrorMsg = ($Error[0].toString()).Split(".")[0]
Write-CHLog "Set-CHRegistryValue" "New registry value $strRegKey\$strRegValue was not created; the error is $strErrorMsg"
}
}
}
else{
[array]$arrRegKeyExists = Get-CHRegistryValue -strRegKey $strRegKey -strRegValue $strRegValue
if($global:blnDebug ){ Write-CHLog "Set-CHRegistryValue" "Registry data type is multistring" }
#for cases where new registry values are written, new-itemproperty will set the type
if ($arrRegKeyExists[0] -eq "Error"){
#logging
if($global:blnDebug ){ Write-CHLog "Set-CHRegistryValue" "Setting new registry value for $strRegKey\$strRegValue to $strData" }
#convert strData to array
[array]$arrData = $strData.Split(",")
Try{
New-ItemProperty $strRegKey -Name $strRegValue -Value $arrData -PropertyType $strDataType -ErrorAction Stop | Out-Null
if($global:blnDebug ){ Write-CHLog "Set-CHRegistryValue" "New registry value $strRegKey\$strRegValue was created; the value was set to $strData" }
}
Catch{
$strErrorMsg = ($Error[0].toString()).Split(".")[0]
Write-CHLog "Set-CHRegistryValue" "New registry value $strRegKey\$strRegValue was not created; the error is $strErrorMsg"
}
}
else{
#logging
if($global:blnDebug ){ Write-CHLog "Set-CHRegistryValue" "Setting registry value for $strRegKey\$strRegValue to $strData" }
#convert strData to array
[array]$arrData = $strData.Split(",")
#most cases are updating existing registry entries
Try{
Set-ItemProperty $strRegKey -Name $strRegValue -Value $arrData -ErrorAction Stop
if($global:blnDebug ){ Write-CHLog "Set-CHRegistryValue" "Registry value $strRegKey\$strRegValue was set to $strData" }
}
Catch{
$strErrorMsg = ($Error[0].toString()).Split(".")[0]
Write-CHLog "Set-CHRegistryValue" "New registry value $strRegKey\$strRegValue was not created; the error is $strErrorMsg"
}
}
}
}#endregion Set-CHRegistryValue
#region Test-CHWriteWMI
Function Test-CHWriteWMI (){
<#
.SYNOPSIS
Checks the ability to write to WMI
.DESCRIPTION
Attempts to write test objects to WMI namespace and returns boolean value
.EXAMPLE
Test-CHWriteWMI -strNamespace "root"
.EXAMPLE
Test-CHWriteWMI "root\ccm"
.PARAMETER strNamespace
String value for the namespace requested for reading
#>
param
(
[Parameter(Mandatory=$True,
ValueFromPipelineByPropertyName=$True)]
[string]$strNamespace
)
<#Test settings to run without function call
$strNamespace = "root\ccm"
#>
If($global:blnDebug ){ Write-CHLog "Test-CHWriteWMI" "Attempting to write to $strNamespace" }
#check for prior existence of PFE class in $strNamespace
if ((Get-WmiObject -namespace $strNamespace -Class "PFE" -ErrorAction SilentlyContinue) -ne $null){
If($global:blnDebug ){ Write-CHLog "Test-CHWriteWMI" "The test class PFE already existed in Namespace $strNamespace; cleaning up created class" }
Try{
#Delete test class from namespace prior to testing
If($global:blnDebug ){ Write-CHLog "Test-CHWriteWMI" "Namespace $strNamespace can be written to; cleaning up created class" }
[wmiclass]$objOldClass = Get-WmiObject -namespace $strNamespace -Class "PFE"
$objOldClass.Delete()
}
Catch{
Write-CHLog "Test-CHWriteWMI" "Failed to delete test class PFE from $strNamespace"
return $False
}
}
Try{
#attempt creation of new class object in namespace
[wmiclass]$objWMIClass = New-Object System.Management.ManagementClass($strNamespace,$null,$null)
$objWMIClass.Name = "PFE"
$objWMIClass.Put() | Out-Null
Try{
#add a property to the class called TestProperty and give it a value of TestValue
$objWMIClass.Properties.Add("TestProperty","")
$objWMIClass.SetPropertyValue("TestProperty","TestValue")
$objWMIClass.Put() | Out-Null
Try{
#create a new instance of the PFE class and changing the value of the TestProperty in this instance
$objNewWMIInstance = $objWMIClass.CreateInstance()
$objNewWMIInstance.TestProperty = "New Instance"
Try{
#Cleanup test class in the namespace and returning True for success
If($global:blnDebug ){ Write-CHLog "Test-CHWriteWMI" "Namespace $strNamespace can be written to; cleaning up created class" }
$objWMIClass.Delete()
return $True
}
Catch{
Write-CHLog "Test-CHWriteWMI" "Failed to delete test class PFE from $strNamespace"
return false
}
}
Catch{
Write-CHLog "Test-CHWriteWMI" "Failed to create instance of class PFE to $strNamespace"
return $false
}
}
Catch{
Write-CHLog "Test-CHWriteWMI" "Failed to write property TestProperty to PFE class of namespace $strNamespace"
return $false
}
}
Catch{
Write-CHLog "Test-CHWriteWMI" "Failed to write class PFE to $strNamespace"
return $false
}
}#endregion Test-CHWriteWMI
#region Test-CHWMIHealth
Function Test-CHWMIHealth (){
<#
.SYNOPSIS
Verifies health of WMI
.DESCRIPTION
Attempts to read WMI and write to namespaces recursively along with basic WMI health checks and returns boolean value
.EXAMPLE
Test-CHWMIHealth
.PARAMETER strNamespace
String value for the namespace requested for reading
#>
Write-CHLog "Test-CHWMIHealth" "Running winmgmt /verifyrepository"
#attempt to verify WMI repository
$null = winmgmt /verifyrepository
if($lastexitcode -ne 0){
Write-CHLog "Test-CHWMIHealth" "Result of WMI repository check is not consistent"
return $False
}
else{
#get value of WMI repository corruption status
[int]$intRepositoryCorrupt = Get-CHRegistryValue -strRegKey "HKLM:\SOFTWARE\Microsoft\Wbem\CIMOM" -strRegValue "RepositoryCorruptionReported"
if($intRepositoryCorrupt -eq 0){
Write-CHLog "Test-CHWMIHealth" "Result of WMI repository check is $intRepositoryCorrupt"
Try{
#attempt to read a core class from root\cimv2 namespace
Get-WmiObject win32_operatingsystem -ErrorAction Stop | Out-Null
if($global:objClientSettings.WMIWriteRepository -eq $true){
#basic test of WMI deems initial success
if($intRepositoryCorrupt -eq 0 -and (Test-CHWriteWMI "root\cimv2")){
#If SCCM client is installed, verify WMI core namespace health
if($global:blnSCCMInstalled -eq $true){
#continue testing by attempting write to all CCM namespaces
[array]$arrCCMNamespaces = gwmi -namespace root\ccm __namespace -recurse
[boolean]$blnStatus = $True
ForEach($arrCCMNamespace in $arrCCMNamespaces){
if(!(Test-CHWriteWMI "$($arrCCMNamespace.__NAMESPACE)\$($arrCCMNamespace.Name)")){
$blnStatus = $False
}
}
if(!($blnStatus)){
Write-CHLog "Test-CHWMIHealth" "Unable to write to one or more namespaces in the SCCM namespace root\ccm"
}
return $blnStatus
}
else{ return $true }
}
else{
Write-CHLog "Test-CHWMIHealth" "Failed to write to default WMI namespace or WMI is corrupt; rebuild of WMI is suggested"
return $False
}
}
}
Catch{
Write-CHLog "Test-CHWMIHealth" "Failed to get basic WMI information"
return $False
}
}
else{
Write-CHLog "Test-CHWMIHealth" "ERROR: WMI is corrupt; rebuild of WMI is suggested"
return $False
}
}
}#endregion Test-CHWMIHealth
#region Get-CHServiceStatus
Function Get-CHServiceStatus()
{
<#
.SYNOPSIS
Validate service status and start type.
.DESCRIPTION
Checks to make sure that a service start type and current status match what is supplied via command line parameter
.EXAMPLE
Get-CHServiceStatus -strServiceName BITS -strStartType DelayedAuto -strStatus Running
.PARAMETER strServiceName
String Value. The Name of the service in which to check status
.PARAMETER strStartType
The start type the service is expected to be in.
Automatic
Manual
Disabled
DelayedAuto
.PARAMETER strStatus
Checks the to validate the service is in a specific state of Running or Stopped. The value of NotMonitored will perform the check ignoring the state.
.DEPENDENT FUNCTIONS
Write-CHLog
#>
PARAM(
[Parameter(Mandatory=$True)][string]$strServiceName,
[Parameter(Mandatory=$True)][ValidateSet('Automatic','Manual','Disabled','DelayedAuto','NotDisabled')][string]$strStartType,
[Parameter(Mandatory=$True)][ValidateSet('Running','Stopped','NotMonitored')][string]$strStatus
)
#Convert friendly parameter to numeric values
Switch ($strStartType)
{
"DelayedAuto" {[int]$intExpectedStart = 2}
"Automatic" {[int]$intExpectedStart = 2}
"Manual" {[int]$intExpectedStart = 3}
"Disabled" {[int]$intExpectedStart = 4}
"NotDisabled" {[int]$intExpectedStart = 0}
}
#Bind to the Service object using PoSH Get-Service
$objService = Get-Service -Name $strServiceName -ErrorAction SilentlyContinue
#Check to make sure there is a service that was found.
if($objService){
#Validate that the Automatic Services are configured correctly
if($intExpectedStart -eq 2){
#Get the Delayed AutoStart value from the Registry as this is the only way to tell the difference between Automatic and DelayedAuto
[int]$intDelayedAutoStart = Get-CHRegistryValue "HKLM:\SYSTEM\CurrentControlSet\services\$strServiceName" "DelayedAutostart"
#Validate Automatic is not set for DelyedAutoStart
if($strStartType -eq "Automatic" -and $intDelayedAutoStart -eq 1){
Write-CHLog -strFunction "Get-CHServiceStatus" -strMessage "WARNING - $strServiceName service is set to Delayed AutoStart and not expected."
Return $False
}
#Validate Delayed Autostart is set correctly
if($strStartType -eq "DelayedAuto" -and $intDelayedAutoStart -ne 1){
Write-CHLog -strFunction "Get-CHServiceStatus" -strMessage "WARNING - $strServiceName is expecting Delayed Autostart, however is not configured correctly."
Return $False
}
}
#Get Start Type because the Get-Service does not show this and using WMI could be an issue on some machines.
# 2=Automatic, 3=Manual, 4=Disabled
[int]$intCurrentStart = Get-CHRegistryValue "HKLM:\SYSTEM\CurrentControlSet\services\$strServiceName" "Start"
#Check StartType and Status match what is expected
if(($intExpectedStart -eq $intCurrentStart -and $strStatus -eq $objService.Status) -or ($intExpectedStart -eq $intCurrentStart -and $strStatus -eq "NotMonitored") -or ($intCurrentStart -ne 4 -and $intExpectedStart -eq 0)){
Write-CHLog -strFunction "Get-CHServiceStatus" -strMessage "$strServiceName is configured correctly."
Return $True
}
else{
Write-CHLog -strFunction "Get-CHServiceStatus" -strMessage "WARNING - $strServiceName Service not configured correctly"
Write-CHLog -strFunction "Get-CHServiceStatus" -strMessage "WARNING - $strServiceName is expected to be set to $strStartType and currently $strStatus."
#Output some helpful information if the current start type does not match the expected start type
Switch ($intCurrentStart)
{
2 {Write-CHLog -strFunction "Get-CHServiceStatus" -strMessage "WARNING - $strServiceName is set to Automatic and status is currently $($objService.Status)"}
3 {Write-CHLog -strFunction "Get-CHServiceStatus" -strMessage "WARNING - $strServiceName is set to Manual and status is currently $($objService.Status)"}
4 {Write-CHLog -strFunction "Get-CHServiceStatus" -strMessage "WARNING - $strServiceName is set to Disabled and status is currently $($objService.Status)"}
}
Return $False
}
}
else{
Write-CHLog -strFunction "Get-CHServiceStatus" -strMessage "ERROR - $strServiceName service does not exist as an installed service on this computer."
Return $False
}
}#endregion Get-CHServiceStatus
#region Set-CHServiceStatus
Function Set-CHServiceStatus()
{
<#
.SYNOPSIS
Sets a service status and start type.
.DESCRIPTION
Sets the service start type and current status match what is supplied via command line parameter
.EXAMPLE
Set-CHServiceStatus -strServiceName BITS -strStartType Manual -strStatus Running
.PARAMETER strServiceName
String Value.The Name of the service in which to set
.PARAMETER strStartType
The start type the service is expected to be in.
Automatic
Manual
Disabled
DelayedAuto
.PARAMETER strStatus
The status of the desired service, should be either Running or Stopped.
.DEPENDENT FUNCTIONS
Write-CHLog
Get-CHServiceStatus
#>
PARAM(
[Parameter(Mandatory=$True)][string]$strServiceName,
[Parameter(Mandatory=$True)][ValidateSet('Automatic','Manual','Disabled','DelayedAuto')][String]$strStartType,
[Parameter(Mandatory=$True)][ValidateSet('Running','Stopped')][string]$strStatus
)
#Clear any errors
$Error.Clear()
#Convert friendly parameter to values for the SC command
Switch ($strStartType)
{
"DelayedAuto" {[string]$strStartTypeSC = "delayed-auto"}
"Automatic" {[string]$strStartTypeSC = "auto"}
"Manual" {[string]$strStartTypeSC = "demand"}
"Disabled" {[string]$strStartTypeSC = "disabled"}
}
#Configure the Windows Service Start type and Status
Try{
Write-CHLog -strFunction "Set-CHServiceStatus" -strMessage "Attempting to set $strServiceName to $strStartType and $strStatus"
#Run SC command because start-service does not support Auto delayed
[int]$intExitCode = (Start-Process -FilePath "$env:windir\system32\sc.exe" -ArgumentList "config $strServiceName start= $strStartTypeSC" -WindowStyle Hidden -PassThru -Wait).ExitCode
If($intExitCode -eq 0){
#Start or Stop Service based on request
If($strStatus -eq "Running") {Start-Service -Name $strServiceName -ErrorAction Stop }
If($strStatus -eq "Stopped") {Stop-Service -Name $strServiceName -ErrorAction Stop }
#Check the Service Status
$blnServiceStatus = Get-CHServiceStatus -strServiceName $strServiceName -strStartType $strStartType -strStatus $strStatus
If($blnServiceStatus){
Write-CHLog -strFunction "Set-CHServiceStatus" -strMessage "$strServiceName successfully set to $strStartType and $strStatus."
Return $True
}
Else{
Write-CHLog -strFunction "Set-CHServiceStatus" -strMessage "ERROR - $strServiceName Service was not configured correctly."
Return $False
}
}
Else{
Write-CHLog -strFunction "Set-CHServiceStatus" -strMessage "ERROR - Could not set $strServiceName to a starttype of $strStartType. Exit Code ($intExitCode)"
Return $False
}
}
Catch{
#Get first line of error only
[string]$strErrorMsg = ($Error[0].toString()).Split(".")[0]
#Catch any error and write tolog
Write-CHLog -strFunction "Set-CHServiceStatus" -strMessage "ERROR - $strServiceName Service not configured correctly. $strErrorMsg"
Return $False
}
}#endregion Set-CHServiceStatus
#region Invoke-CHWMIRebuild
Function Invoke-CHWMIRebuild (){
<#
.SYNOPSIS
Initiated when WMI Rebuild is required
.DESCRIPTION
In depth rebuild of Windows Management Instrumentation (WMI)
.EXAMPLE
Invoke-CHWMIRebuild
.EXAMPLE
Invoke-CHWMIRebuild
#>
if($global:blnDebug){ Write-CHLog "Invoke-CHWMIRebuild" "Information: Starting the process of rebuilding WMI" }
[string]$strWbemPath = "$($env:WINDIR)\system32\wbem"
[string]$strRepository = "$strWbemPath\Repository"
if($global:blnDebug){ Write-CHLog "Invoke-CHWMIRebuild" "Information: Stop SMS Agent Host if it exists" }
Try{
Get-Service -Name CcmExec -ErrorAction Stop | Stop-Service -ErrorAction Stop | Out-Null
if($global:blnDebug){ Write-CHLog "Invoke-CHWMIRebuild" "Information: Stop SMS Agent Host service was successful" }
}
Catch{
Write-CHLog "Invoke-CHWMIRebuild" "Warning: Stop SMS Agent Host service was not successful"
}
#stop CCMSETUP process and delete service if it exists
if($global:blnDebug){ Write-CHLog "Invoke-CHWMIRebuild" "Information: Stop CCMSETUP Service and delete if it exists" }
if((Get-Service -Name ccmsetup -ErrorAction SilentlyContinue) -ne $null){
Get-Process -Name ccmsetup -ErrorAction SilentlyContinue | Stop-Process -ErrorAction SilentlyContinue -Force | Out-Null
#delete the ccmsetup service
[object]$objStatus = Start-Process -FilePath "$env:windir\system32\sc.exe" -ArgumentList "delete ccmsetup" -WindowStyle Hidden -PassThru -Wait
if($objStatus.ExitCode -eq 0){
if($global:blnDebug){ Write-CHLog "Invoke-CHWMIRebuild" "Information: CCMSETUP service was deleted" }
}
else{
Write-CHLog "Invoke-CHWMIRebuild" "Warning: CCMSETUP service was not deleted; continuing to repair WMI"
}
#cleaning up variable
Remove-Variable "objStatus"
}
#uninstall SCCM client if the service exists
if(Get-Service ccmexec -ErrorAction SilentlyContinue){ Invoke-CHClientAction -strAction Uninstall }
#reset security on the WMI, Windows Update, and BITS services
[array]$arrServices = @("winmgmt","wuauserv","bits")
foreach($strService in $arrServices){
Write-CHLog "Invoke-CHWMIRebuild" "Information: The current security descriptor for the $strService Service is $(sc.exe sdshow $strService)"
Write-CHLog "Invoke-CHWMIRebuild" "Information: Setting default security descriptor on $strService to D:(A;;CCLCSWRPWPDTLOCRRC;;;SY)(A;;CCDCLCSWRPWPDTLOCRSDRCWDWO;;;BA)(A;;CCLCSWLOCRRC;;;AU)(A;;CCLCSWRPWPDTLOCRRC;;;PU)"
[object]$objStatus = Start-Process -FilePath "$env:windir\system32\sc.exe" -ArgumentList "sdset $strService D:(A;;CCLCSWRPWPDTLOCRRC;;;SY)(A;;CCDCLCSWRPWPDTLOCRSDRCWDWO;;;BA)(A;;CCLCSWLOCRRC;;;AU)(A;;CCLCSWRPWPDTLOCRRC;;;PU)" -WindowStyle Hidden -PassThru -Wait
Write-CHLog "Invoke-CHWMIRebuild" "Information: The exit code to set the security descriptor is $($objStatus.ExitCode)"
}
#cleaning up variable
Remove-Variable "objStatus"
#Re-enabling DCOM
if(Set-CHRegistryValue "HKLM:\SOFTWARE\Microsoft\OLE" -strRegValue "EnableDCOM" -strData "Y" -strDataType "string"){
if($global:blnDebug){ Write-CHLog "Invoke-CHWMIRebuild" "Information: Successfully enabled DCOM" }
}
else{ Write-CHLog "Invoke-CHWMIRebuild" "Warning: DCOM not enabled successfully" }
#Resetting DCOM Permissions
Write-CHLog "Invoke-CHWMIRebuild" "Information: Resetting DCOM Permissions"
[array]$arrRegEntries = @("DefaultLaunchPermission","MachineAccessRestriction","MachineLaunchRestriction")
foreach($strRegEntry in $arrRegEntries){
[object]$objStatus = Start-Process -FilePath "$env:windir\system32\reg.exe" -ArgumentList "delete HKLM\software\microsoft\ole /v $strRegEntry /f" -WindowStyle Hidden -PassThru -Wait
Write-CHLog "Invoke-CHWMIRebuild" "Information: The exit code to delete $strRegEntry from HKLM:\software\microsoft\ole is $($objStatus.ExitCode)"
}
#Rebuild WMI using WINMGMT utility (supported in each OS with version 6 or higher)
if($global:blnDebug){ Write-CHLog "Invoke-CHWMIRebuild" "Refreshing WMI ADAP" }
[object]$objStatus = Start-Process -FilePath "$strWbemPath\wmiadap.exe" -ArgumentList "/f" -WindowStyle Hidden -PassThru -Wait
Write-CHLog "Invoke-CHWMIRebuild" "Information: The exit code to Refresh WMI ADAP is $($objStatus.ExitCode)"
if($global:blnDebug){ Write-CHLog "Invoke-CHWMIRebuild" "Registering WMI" }
[object]$objStatus = Start-Process -FilePath "$env:windir\system32\regsvr32.exe" -ArgumentList "/s wmisvc.dll" -WindowStyle Hidden -PassThru -Wait
Write-CHLog "Invoke-CHWMIRebuild" "Information: The exit code to Register WMI is $($objStatus.ExitCode)"
if($global:blnDebug){ Write-CHLog "Invoke-CHWMIRebuild" "Resyncing Performance Counters" }
[object]$objStatus = Start-Process -FilePath "$strWbemPath\winmgmt.exe" -ArgumentList "/resyncperf" -WindowStyle Hidden -PassThru -Wait
Write-CHLog "Invoke-CHWMIRebuild" "Information: The exit code to Resync Performance Counters is $($objStatus.ExitCode)"
if($global:blnDebug){ Write-CHLog "Invoke-CHWMIRebuild" "Attempting salvage of WMI repository using winmgmt /salvagerepository" }
[object]$objStatus = Start-Process -FilePath "$strWbemPath\winmgmt.exe" -ArgumentList "/salvagerepository" -WindowStyle Hidden -PassThru -Wait
Write-CHLog "Invoke-CHWMIRebuild" "Information: The exit code to Salvage the WMI Repository is $($objStatus.ExitCode)"
#unregistering atl.dll
[object]$objStatus = Start-Process -FilePath "$env:windir\system32\regsvr32.exe" -ArgumentList "/u $env:windir\system32\atl.dll /s" -WindowStyle Hidden -PassThru -Wait
Write-CHLog "Invoke-CHWMIRebuild" "Information: The exit code to Unregister ATL.DLL is $($objStatus.ExitCode)"
#registering required DLLs
[array]$arrDLLs = @("scecli.dll","userenv.dll","atl.dll")
foreach($strDll in $arrDLLs){
[object]$objStatus = Start-Process -FilePath "$env:windir\system32\regsvr32.exe" -ArgumentList "/s $env:windir\system32\$strDll" -WindowStyle Hidden -PassThru -Wait
Write-CHLog "Invoke-CHWMIRebuild" "Information: The exit code to Register $strDLL is $($objStatus.ExitCode)"
}
#Register WMI Provider
[object]$objStatus = Start-Process -FilePath "$strWbemPath\wmiprvse.exe" -ArgumentList "/regserver" -WindowStyle Hidden -PassThru -Wait
Write-CHLog "Invoke-CHWMIRebuild" "Information: The exit code to Register WMI Provider is $($objStatus.ExitCode)"
#Restart WMI Service
Try{
Write-CHLog "Invoke-CHWMIRebuild" "Restarting the WMI Service"
[string]$strSvcName = "winmgmt"
# Get dependent services
[array]$arrDepSvcs = Get-Service -name $strSvcName -dependentservices | Where-Object {$_.Status -eq "Running"} | Select -Property Name
# Check to see if dependent services are started
if ($arrDepSvcs -ne $null) {
# Stop dependencies
foreach ($objDepSvc in $arrDepSvcs)
{
Write-CHLog "Invoke-CHWMIRebuild" "Stopping $($objDepSvc.Name) as it is a dependent of the WMI Service"
Stop-Service $objDepSvc.Name -ErrorAction Stop | Out-Null
do
{
[object]$objService = Get-Service -name $objDepSvc.Name | Select -Property Status
Start-Sleep -seconds 1
}
until ($objService.Status -eq "Stopped")
}
}
# Restart service
Restart-Service $strSvcName -force -ErrorAction Stop | Out-Null
do
{
$objService = Get-Service -name $strSvcName | Select -Property Status
Start-Sleep -seconds 1
}
until ($objService.Status -eq "Running")
# We check for Auto start flag on dependent services and start them even if they were stopped before
foreach ($objDepSvc in $arrDepSvcs)
{
$objStartMode = gwmi win32_service -filter "NAME = '$($objDepSvc.Name)'" | Select -Property StartMode
if ($objStartMode.StartMode -eq "Auto") {
Write-CHLog "Invoke-CHWMIRebuild" "Starting $($objDepSvc.Name) after restarting WMI Service"
Start-Service $objDepSvc.Name -ErrorAction Stop | Out-Null
do
{
$objService = Get-Service -name $objDepSvc.Name | Select -Property Status
Start-Sleep -seconds 1
}
until ($objService.Status -eq "Running")
}
}
}
Catch{
Write-CHLog "Invoke-CHWMIRebuild" "ERROR - Restart of WMI service failed"
}
Write-CHLog "Invoke-CHWMIRebuild" "ACTION: Rebuild of WMI completed; please reboot system"
#Run GPUpdate if on Domain
if((Get-CHRegistryValue "HKLM:\System\CurrentControlSet\Services\Tcpip\Parameters" "Domain") -ne ""){
gpupdate | Out-Null
}
Write-CHLog "Invoke-CHWMIRebuild" "Testing WMI Health post repair"
if(Test-CHWMIHealth -eq $False){
Write-CHLog "Invoke-CHWMIRebuild" "ERROR - WMI Verification failed; reseting the repository with winmgmt /resetrepository"
[object]$objStatus = Start-Process -FilePath "$strWbemPath\winmgmt.exe" -ArgumentList "/resetrepository" -WindowStyle Hidden -PassThru -Wait
Write-CHLog "Invoke-CHWMIRebuild" "Information: The exit code to Reset the WMI Repository is $($objStatus.ExitCode)"
if($objStatus.ExitCode -eq 0){
Write-CHLog "Invoke-CHWMIRebuild" "WMI reset successfully; verifying repository again"
if(Test-CHWMIHealth -eq $false){
Write-CHLog "Invoke-CHWMIRebuild" "ERROR - WMI Verification failed after reseting the repository with winmgmt /resetrepository"
[boolean]$blnWMIHealth = $false
}
else{
[boolean]$blnWMIHealth = $true
}
}
}
else{ [boolean]$blnWMIHealth = $true }
#increment WMI rebuild count by 1 and write back to registry; it is important to track this number no matter success or failure of the rebuild
[int]$intWMIRebuildCount = 1 + (Get-CHRegistryValue $global:strPFEKeyPath "PFE_WMIRebuildAttempts")
Set-CHRegistryValue $global:strPFEKeyPath "PFE_WMIRebuildAttempts" $intWMIRebuildCount "string"
Write-CHLog "Invoke-CHWMIRebuild" "Information: WMI has been rebuilt $intWMIRebuildCount times by the PFE Remediation for Configuration Manager script"
if($blnWMIHealth){
Write-CHLog "Invoke-CHWMIRebuild" "Information: WMI Verification successful after reseting the repository with winmgmt /resetrepository"
if($global:blnDebug){ Write-CHLog "Invoke-CHWMIRebuild" "Information: Detecting Microsoft Policy Platform installation; if installed will attempt to compile MOF/MFL files" }
if($global:blnDebug){ Write-CHLog "Invoke-CHWMIRebuild" "Information: This is done to prevent ccmsetup from erroring when trying to compile DiscoveryStatus.mof and there are issues with the root\Microsoft\PolicyPlatform namespace" }
if(Test-Path "$env:ProgramFiles\Microsoft Policy Platform" -ErrorAction SilentlyContinue){
[array]$arrMPPFiles = Get-ChildItem "$env:ProgramFiles\Microsoft Policy Platform" | where { ($_.Extension -eq ".mof" -or $_.Extension -eq ".mfl") -and $_.Name -notlike "*uninst*" } | foreach { $_.fullname }
foreach($strMPPFile in $arrMPPFiles){
[object]$objStatus = Start-Process -FilePath "$strWbemPath\mofcomp.exe" -ArgumentList """$strMPPFile""" -WindowStyle Hidden -PassThru -Wait
Write-CHLog "Invoke-CHWMIRebuild" "Information: The exit code to MOFCOMP $strMPPfile is $($objStatus.ExitCode)"
}
}
else{
Write-CHLog "Invoke-CHWMIRebuild" "Warning: Unable to get Microsoft Policy Platform files"
}
return $True
}
else { return $false }
}#endregion Invoke-CHWMIRebuild
#region Invoke-CHClientAction
Function Invoke-CHClientAction (){
<#
.SYNOPSIS
Install, uninstall, or repair the SCCM client
.DESCRIPTION
Function to install the most current version of the SCCM client
.EXAMPLE
Invoke-CHClientAction -strAction Install
.DEPENDENT FUNCTIONS
Write-CHLog
Set-CHRegistryValue
Get-CHRegistryValue
.PARAMETER strAction
The name of the client action to be taken
#>
param
(
[Parameter(Mandatory=$True,
ValueFromPipelineByPropertyName=$True)]
[ValidateSet('Install','Uninstall','Repair')][string]$strAction
)
Write-CHLog -strFunction "Invoke-CHClientAction" -strMessage "The client action $strAction has been initiated"
If(($global:objClientSettings.WorkstationRemediation -eq $TRUE -and $global:strOSType -eq 'workstation') -or ($global:objClientSettings.ServerRemediation -eq $TRUE -and $global:strOSType -eq 'server')) {
Write-CHLog -strFunction "Invoke-CHClientAction" -strMessage "Remediation enabled; beginning ConfigMgr client $strAction"
#Get current Date and Time
Set-CHRegistryValue -strRegKey $global:strPFEKeyPath -strRegValue "PFE_LastAction" -strData "Client $strAction" -strDataType string
Set-CHRegistryValue -strRegKey $global:strPFEKeyPath -strRegValue "PFE_LastDate" -strData (Get-Date -format yyyy-MM-dd) -strDataType string
Set-CHRegistryValue -strRegKey $global:strPFEKeyPath -strRegValue "PFE_LastTime" -strData (Get-Date -format HH:mm:ss) -strDataType string
Stop-Service -Name "CCMSetup" -Force -ErrorAction SilentlyContinue
Stop-Process -Name "CCMSetup" -Force -ErrorAction SilentlyContinue
Stop-Process -Name "CCMRestart" -Force -ErrorAction SilentlyContinue
if (Test-Path "$env:windir\ccmsetup\ccmsetup.exe")
{
If ((Get-Item "$env:windir\ccmsetup\ccmsetup.exe").VersionInfo.ProductVersion -ge $LatestSCCMVersion)
{
Write-CHLog -strFunction Invoke-CHClientAction -strMessage "$env:windir\ccmsetup\ccmsetup.exe is up to date, using it"
[string]$strClientActionCommand = "$env:windir\ccmsetup\ccmsetup.exe"
}
Else
{
Write-CHLog -strFunction Invoke-CHClientAction -strMessage "$env:windir\ccmsetup\ccmsetup.exe not up to date, using \\$PrimarySiteServer\Client$\ccmsetup.exe"
[string]$strClientActionCommand = "\\$PrimarySiteServer\Client$\ccmsetup.exe"
}
}
else
{
Write-CHLog -strFunction Invoke-CHClientAction -strMessage "$env:windir\ccmsetup\ccmsetup.exe not found, using \\$PrimarySiteServer\Client$\ccmsetup.exe"
[string]$strClientActionCommand = "\\$PrimarySiteServer\Client$\ccmsetup.exe" }
If ($ClientInstallationFailuresCount -gt '5')
{
Write-CHLog -strFunction "Invoke-CHClientAction" -strMessage "Installation has failed $ClientInstallationFailuresCount times, uninstalling"
$strAction = "Uninstall"
}
#Convert friendly parameter to values for the SC command
Switch ($strAction)
{
"Install" {[string]$strClientActionArgs = "$($global:objClientSettings.ExtraEXECommands) SMSSITECODE=$($global:strSiteCode) $($global:objClientSettings.ExtraMSICommands)"}
"Uninstall" {[string]$strClientActionArgs = "/Uninstall"}
"Repair" {[string]$strClientActionArgs = "$($global:objClientSettings.extraEXECommands) SMSSITECODE=$($global:strSiteCode) RESETKEYINFORMATION=TRUE REMEDIATE=TRUE $($global:objClientSettings.extraMSICommands)"}
}
Write-CHLog -strFunction "Invoke-CHClientAction" -strMessage "Starting Client $strAction with command line $strClientActionCommand $strClientActionArgs"
[int]$intClientActionExitCode = (Start-Process $strClientActionCommand -ArgumentList $strClientActionArgs -wait -NoNewWindow -PassThru ).ExitCode
if ($strAction -ne "Uninstall")
{
If ($ClientInstallationFailuresCount -gt '0')
{
Write-CHLog -strFunction "Invoke-CHClientAction" -strMessage "Installation has failed $ClientInstallationFailuresCount times"
}
if(($intClientActionExitCode -eq 0) -and ($strClientActionArgs.ToLower() -contains "/noservice")){
#Client install complete
Write-CHLog -strFunction "Invoke-CHClientAction" -strMessage "$strAction of ConfigMgr Client complete"
Set-CHRegistryValue $global:strPFEKeyPath -strRegValue "PFE_ClientInstallationFailures" -strData "0" -strDataType "string"
return $true
}
elseif(($intClientActionExitCode -eq 0) -and ($strClientActionArgs.ToLower() -notcontains "/noservice")){
#client installing
Write-CHLog -strFunction "Invoke-CHClientAction" -strMessage "$strAction of ConfigMgr Client has begun"
Start-Sleep -Seconds 30
[string]$strProcessID = Get-Process -name "ccmsetup" -ErrorAction SilentlyContinue | foreach {$_.Id}
if($strProcessID.Trim() -eq ""){
Write-CHLog -strFunction "Invoke-CHClientAction" -strMessage "No Process ID found for CCMSETUP"
Write-CHLog -strFunction "Invoke-CHClientAction" -strMessage "ERROR - CCMSETUP not launched successfully, validate command line is correct"
return $false
}
else{
Write-CHLog -strFunction "Invoke-CHClientAction" -strMessage "Monitoring Process ID $strProcessID for CCMSETUP to complete"
Write-CHLog -strFunction "Invoke-CHClientAction" -strMessage "ConfigMgr client $strAction is running"
Wait-Process -Id $strProcessID
Write-CHLog -strFunction "Invoke-CHClientAction" -strMessage "ConfigMgr client $strAction complete"
#Service Startup Checks
try{
Get-Process -name "ccmexec" -ErrorAction Stop | Out-Null
Get-Service -name "ccmexec" -ErrorAction Stop | Out-Null
return $true
}
catch{
Write-CHLog -strFunction "Invoke-CHClientAction" -strMessage "ERROR - Service check after client $strAction failed"
return $false
}
#Detect Application that needs to install
}
}
else{
#client install failed
Write-CHLog -strFunction "Invoke-CHClientAction" -strMessage "ERROR - $strAction of ConfigMgr Client has failed"
$ClientInstallationFailuresCount++
Set-CHRegistryValue $global:strPFEKeyPath -strRegValue "PFE_ClientInstallationFailures" -strData "$ClientInstallationFailuresCount" -strDataType "string"
return $false
}
}
else
{
if($intClientActionExitCode -eq 0) {
Write-CHLog -strFunction "Invoke-CHClientAction" -strMessage "System Center ConfigMgr Client successfully uninstalled"
Set-CHRegistryValue $global:strPFEKeyPath -strRegValue "PFE_ClientInstallationFailures" -strData "0" -strDataType "string"
$global:blnSCCMInstalled = $false
#If Policy Platform is installed, Remove it
Try{
[string]$strFilePath = Get-ChildItem HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall | where-object { $_.GetValue("DisplayName") -eq "Microsoft Policy Provider" } | ForEach-Object { $_.GetValue("UninstallString") }
[string]$strProcessName = $strFilePath.Substring(0,$strFilePath.IndexOf(' '))
[string]$strArgList = $strFilePath.Substring($strFilePath.IndexOf('/'),$strFilePath.Length-$strFilePath.IndexOf('/'))
[int]$intPolProvUninstall = (Start-Process $strProcessName -ArgumentList $strArgList -wait -NoNewWindow -PassThru ).ExitCode
If($intPolProvUninstall -eq 0) {
Write-CHLog -strFunction "Invoke-CHClientAction" -strMessage "Microsoft Policy Platform successfully uninstalled"
}
Else {
Write-CHLog -strFunction "Invoke-CHClientAction" -strMessage "ERROR - Microsoft Policy Platform failed to uninstall with exit code $intPolProvUninstall"
}
}
Catch {
Write-CHLog -strFunction "Invoke-CHClientAction" -strMessage "ERROR - Could not bind to registry to do uninstall of Microsoft Policy Platform. Either cannot access registry, or the MPP is not installed"
}
}
Else {
Write-CHLog -strFunction "Invoke-CHClientAction" -strMessage "ERROR - Failed to uninstall System Center ConfigMgr Client"
}
}
}
else {
Write-CHLog -strFunction "Invoke-CHClientAction" -strMessage "WARNING - Remediation has been disabled for this hardware type. Will not $strAction client"
return $false
}
#Update Registry with current status and date\time
Set-CHRegistryValue -strRegKey $global:strPFEKeyPath -strRegValue "PFE_LastAction" -strData "Client $strAction" -strDataType string
Set-CHRegistryValue -strRegKey $global:strPFEKeyPath -strRegValue "PFE_LastDate" -strData (Get-Date -format yyyy-MM-dd) -strDataType string
Set-CHRegistryValue -strRegKey $global:strPFEKeyPath -strRegValue "PFE_LastTime" -strData (Get-Date -format HH:mm:ss) -strDataType string
}#endregion Invoke-CHClientAction
#region Test-CHStaleLog
Function Test-CHStaleLog() {