-
Notifications
You must be signed in to change notification settings - Fork 3
/
LocalGroupRights.psm1
44 lines (37 loc) · 1.8 KB
/
LocalGroupRights.psm1
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
#Joe Rodriguez
#version 1.0
Function Get-LocalGroupRights {
Param (
[Parameter(Mandatory = $true,Position=0)][string] $ComputerName,
[Parameter(Position=1)][string] $Group = 'Administrators'
)
$GroupInfo = [ADSI] "WinNT://$ComputerName/$Group,group"
$Members = $GroupInfo.psbase.Invoke("Members")
$Members | %{ $_.GetType().InvokeMember("Name", 'GetProperty', $null, $_, $null) }
}
#Get-LocalGroupRights -ComputerName Computer001
Function Add-LocalGroupRights {
Param (
[Parameter(Mandatory = $true,Position=0,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true)][string] $ComputerName,
[Parameter(Mandatory = $true,Position=1,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true)][string] $Name,
[Parameter(Mandatory = $true, Position = 2)][ValidateSet("User", "Group")] $Type,
[Parameter(Position = 3)] $Group = 'Administrators'
)
$GroupInfo = [ADSI] "WinNT://$ComputerName/$Group,group"
$ToAdd = [ADSI] "WinNT://AD.JOEROD.COM/$Name,$Type"
$GroupInfo.Add($ToAdd.Path)
}
#Add-LocalGroupRights -ComputerName Computer001 -Name joerod -Type User
Function Remove-LocalGroupRights {
Param (
[Parameter(Mandatory = $true,Position=0,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true)][string] $ComputerName,
[Parameter(Mandatory = $true,Position=1,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true)][string] $Name,
[Parameter(Mandatory = $true, Position = 2)][ValidateSet("User", "Group")] $Type,
[Parameter(Position = 3)] $Group = 'Administrators'
)
$GroupInfo = [ADSI] "WinNT://$ComputerName/$Group,group"
$ToRemove = [ADSI] "WinNT://AD.JOEROD.COM/$Name,$Type"
$GroupInfo.Remove($ToRemove.Path)
}
#Remove-LocalGroupRights -ComputerName Computer001 -Name joerod -Type User