forked from MrAnde7son/PowerShell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInvoke-WinRMRestriction.ps1
38 lines (34 loc) · 1.38 KB
/
Invoke-WinRMRestriction.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
<#
Author: Itamar Mizrahi (@MrAnde7son)
License: GNU v3
Required Dependencies: None
Optional Dependencies: None
#>
function Invoke-WinRMRestriction
{
<#
.SYNOPSIS
Denies access for a specified object to WinRM listener, meaning the specified object wouldn't be able to use winrm against the system.
Author: Itamar Mizrahi (@MrAnde7son)
License: GNU v3
Required Dependencies: None
Optional Dependencies: None
.DESCRIPTION
.PARAMETER SID
The SID of the object to remove permissions.
.EXAMPLE
PS C:\> Invoke-WinRMRestriction -SID
Removes permissions of a given object by its SID.
#>
[CmdletBinding()]
Param (
[Parameter(Mandatory=$true)]
[string]
$SID
)
$sddl = (Get-Item WSMAN:\localhost\Service\RootSDDL).Value
$SD = New-Object -TypeName System.Security.AccessControl.RawSecurityDescriptor -ArgumentList $sddl
$NewACE = New-Object System.Security.AccessControl.CommonAce([System.Security.AccessControl.AceFlags]::None,[System.Security.AccessControl.AceQualifier]::AccessDenied,268435456,$SID,$false,$null)
$SD.DiscretionaryAcl.InsertAce($SD.DiscretionaryAcl.Count,$NewACE)
Set-Item WSMan:\localhost\Service\RootSDDL -Value $SD.GetSddlForm([System.Security.AccessControl.AccessControlSections]::All) -Force
}