-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Get-ADLocalAdminGroup.ps1
48 lines (47 loc) · 1.5 KB
/
Get-ADLocalAdminGroup.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
function Get-ADLocalAdminGroup {
<#
.Synopsis
Get AD Local Admin group for corresponding computer account
.DESCRIPTION
Local Admin rights are granted via GPP using "OU ac-%computername%-LocalAdmin"
AD accounts are created in Resource OU in AD and user added to those groups.
.EXAMPLE
Get-ADLocalAdminGroup L9018210
Get-ADLocalAdminGroup $machines
.EXAMPLE
$machines | Get-LocalAdminGroup
#>
[CmdletBinding()]
Param (
[Parameter(Mandatory=$true,
ValueFromPipeline=$true)]
[string[]]$Computername
)
Process {
foreach ($computer in $computername) {
$groupname = "OU ac-{0}-LocalAdmin" -f $computer
try {
$group = get-adgroup $groupname -Properties members
[pscustomobject]@{
Computername = $computer
Groupname = $group.name
GroupExists = 'Yes'
Members = if (($group.members).count -lt 1) {
'No Members'
}
else {
(Get-ADGroupMember $groupname).samaccountname -join ","
}
}
}
catch {
[pscustomobject]@{
Computername = $computer
Groupname = $null
GroupExists = 'No'
Members = 'No Members'
}
}
}
}
}