File tree Expand file tree Collapse file tree
Proactive Remediation/Service Startup Behavior Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ <#
2+ Version: 1.0
3+ Author: Florian Salzmann (scloud.work)
4+
5+ Description: Detects if the Smart Card Removal Policy service is not running or not set to Automatic.
6+
7+ Run this script using the logged-on credentials: No
8+ Enforce script signature check: No
9+ Run script in 64-bit PowerShell: Yes
10+ #>
11+
12+ $ServiceName = " SCPolicySvc"
13+
14+ $service = Get-Service - Name $ServiceName - ErrorAction SilentlyContinue
15+
16+ if (-not $service ) {
17+ Write-Host " Service $ServiceName not found."
18+ exit 1
19+ }
20+
21+ if ($service.StartType -ne " Automatic" -or $service.Status -ne " Running" ) {
22+ Write-Host " $ServiceName is not set to Automatic or not running."
23+ exit 1
24+ } else {
25+ Write-Host " $ServiceName is running and set to Automatic."
26+ exit 0
27+ }
Original file line number Diff line number Diff line change 1+ <#
2+ Version: 1.0
3+ Author: Florian Salzmann (scloud.work)
4+
5+ Description: Sets Smart Card Removal Policy service (SCPolicySvc) to Automatic and starts it.
6+
7+ Run this script using the logged-on credentials: No
8+ Enforce script signature check: No
9+ Run script in 64-bit PowerShell: Yes
10+ #>
11+
12+ $ServiceName = " SCPolicySvc"
13+
14+ $service = Get-Service - Name $ServiceName - ErrorAction SilentlyContinue
15+
16+ if ($service ) {
17+ try {
18+ Set-Service - Name $ServiceName - StartupType Automatic - ErrorAction Stop
19+ Write-Host " Successfully set $ServiceName to Automatic startup."
20+
21+ if ($service.Status -ne ' Running' ) {
22+ Start-Service - Name $ServiceName - ErrorAction Stop
23+ Write-Host " Successfully started $ServiceName ."
24+ } else {
25+ Write-Host " $ServiceName is already running."
26+ }
27+
28+ } catch {
29+ Write-Error " Error while configuring $ServiceName : $_ "
30+ }
31+ } else {
32+ Write-Warning " Service $ServiceName not found."
33+ }
You can’t perform that action at this time.
0 commit comments