-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathReset-SccmAgent.ps1
83 lines (59 loc) · 2.08 KB
/
Reset-SccmAgent.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
<#
.SYNOPSIS
This cmdlet is used to clear the SCCM cache and restart the SCCM service which runs all the Actions in Configuration Manager
.DESCRIPTION
Clear the SCCM cache and restart the CcmExec service
.PARAMETER ServiceName
Define the SCCM service name to restart. Default value is CcmExec
.PARAMETER Path
Define a path to the SCCM Cache parent directory. Default value is C:\Windows\ccmcache
.EXAMPLE
Reset-SccmAgent
# This example restarts the CcmExec service and deletes the cache files in C:\Windows\ccmcache
.EXAMPLE
Reset-SccmAgent -ServiceName -Path C:\Windows\ccmcache
# This example restarts the CcmExec service and deletes the cache files in C:\Windows\ccmcache
.NOTES
Author: Robert H. Osborne
Alias: tobor
Contact: [email protected]
.INPUTS
None
.OUTPUTS
None
.LINK
https://osbornepro.com
https://btpssecpack.osbornepro.com
https://writeups.osbornepro.com
https://github.com/OsbornePro
https://github.com/tobor88
https://www.powershellgallery.com/profiles/tobor
https://www.hackthebox.eu/profile/52286
https://www.linkedin.com/in/roberthosborne/
https://www.credly.com/users/roberthosborne/badges
#>
Function Reset-SccmAgent {
[CmdletBinding()]
param(
[Parameter(
Position=0,
Mandatory=$False)] # End Parameter
[ValidateScript({Get-Service -Name $_})]
[String]$ServiceName = 'CcmExec',
[Parameter(
Position=1,
Mandatory=$False
#HelpMessage="Define the SCCM directory containing cache files EXAMPLE: C:\Windows\ccmcache"
)] # End Parameter
[ValidateScript({Test-Path -Path $_})]
[String]$Path = "C:\Windows\ccmcache"
) # End param
Write-Verbose "Restarting the $ServiceName service"
Restart-Service -Name $ServiceName -Force -Confirm:$False -PassThru
Try {
Write-Verbose "Deleting the file $Path"
Remove-Item -Path $Path -Recurse -Force -ErrorAction Stop
} Catch {
Write-Error $_.Exception.Message
} # End Catch
} # End Reset-SccmAgent