-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRemove-KerberosTickets.ps1
More file actions
44 lines (43 loc) · 1.55 KB
/
Copy pathRemove-KerberosTickets.ps1
File metadata and controls
44 lines (43 loc) · 1.55 KB
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
Function Remove-KerberosTickets {
Param (
[Parameter(ValueFromPipeline=$True)]
[String[]]$Computername = 'localhost',
[System.Management.Automation.PSCredential]$Credential
)
BEGIN{
$Scriptblock = {
Function ConvertKerbSessionString{
Param($SessionString)
$LUID = [Convert]::ToString($SessionString.LogonID, 16)
$LUID = '0x' + $LUID
write-output $LUID
}
$SessionOutput = get-wmiobject -class Win32_LogonSession
$Kerbsessions = foreach ($String in $SessionOutput){ConvertKerbSessionString $String}
Foreach ($Session in $KerbSessions){
write-verbose "Clearing ticket cache for logon session $session"
c:\windows\system32\klist.exe -li $Session purge | out-null
}
}
}
PROCESS{
Foreach ($Computer in $Computername){
if ($Computer -ne 'localhost'){
Try {
If ($Credential){
$PSSession = New-pssession -ComputerName $Computer -Credential $Credential -ea stop
} else {
$PSSession = New-PSSession -ComputerName $Computer -ea stop
}
} Catch {
write-error "Unable to connect to $Computer via WSMAN"
return
}
invoke-command -ScriptBlock $Scriptblock -Session $PSSession
} else {
invoke-command -ScriptBlock $Scriptblock
}
}
}
END{}
}