Skip to content

Commit 5187220

Browse files
committed
Service Startup Behavior in Intune
1 parent bf4cba0 commit 5187220

2 files changed

Lines changed: 60 additions & 0 deletions

File tree

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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+
}

0 commit comments

Comments
 (0)