1
0
mirror of https://github.com/jaapbrasser/SharedScripts.git synced 2025-12-24 21:51:38 +02:00

Allow multiple groups to be specified

This commit is contained in:
Jaap Brasser
2016-08-15 17:24:02 +02:00
parent 784f4b5623
commit 33d0adac18
2 changed files with 19 additions and 10 deletions

View File

@@ -15,9 +15,9 @@ The name of the local group
.NOTES
Name : Get-GroupMember.ps1
Author : Jaap Brasser
Version : 1.0.0
Version : 1.0.1
DateCreated: 2016-08-02
DateUpdated: 2016-08-02
DateUpdated: 2016-08-15
.LINK
http://www.jaapbrasser.com
@@ -42,12 +42,19 @@ Get-GroupMember -ComputerName 'Server01','Server02' -LocalGroup Administrators
Description
-----------
Gets the group members of the Administrators group on both Server01 and Server02
.EXAMPLE
Get-GroupMember -ComputerName 'Server01','Server02' -LocalGroup Administrators,Users
Description
-----------
Gets the group members of the Administrators and the Users groups on both Server01 and Server02
#>
[CmdletBinding()]
param(
[Parameter(Mandatory = $true)]
[Alias('Group')]
[string]
[string[]]
$LocalGroup,
[Alias('CN','Computer')]
[string[]]
@@ -57,14 +64,16 @@ Gets the group members of the Administrators group on both Server01 and Server02
foreach ($Computer in $ComputerName) {
Write-Verbose "Checking membership of localgroup: '$LocalGroup' on $Computer"
try {
([adsi]"WinNT://$Computer/$LocalGroup,group").psbase.Invoke('Members') | ForEach-Object {
New-Object -TypeName PSCustomObject -Property @{
ComputerName = $Computer
LocalGroup = $LocalGroup
Member = $_.GetType().InvokeMember('Name', 'GetProperty', $null, $_, $null)
foreach ($Group in $LocalGroup) {
([adsi]"WinNT://$Computer/$Group,group").psbase.Invoke('Members') | ForEach-Object {
New-Object -TypeName PSCustomObject -Property @{
ComputerName = $Computer
LocalGroup = $Group
Member = $_.GetType().InvokeMember('Name', 'GetProperty', $null, $_, $null)
}
}
Write-Verbose "Successfully checked membership of local group: '$LocalGroup' on $Computer"
}
Write-Verbose "Successfully checked membership of localgroup: '$LocalGroup' on $Computer"
} catch {
Write-Warning $_
}

View File

@@ -63,7 +63,7 @@ This command dot sources the script to ensure the Remove-ADAccountasLocalAdminis
Remove-ADAccountasLocalAdministrator -Computer Server01 -Trustee JaapBrasser
Description:
Will remove the the JaapBrasser account to the Administrators group on Server01
Will remove the the JaapBrasser account from the Administrators group on Server01
.EXAMPLE
Remove-ADAccountasLocalAdministrator -Computer 'Server01','Server02' -Trustee Contoso\HRManagers