Groups/Get-GPPGroup.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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
function Get-GPPGroup { [OutputType('GPPItemGroup')] Param ( [Parameter(ParameterSetName = 'ByGPONameObjectName')] [Parameter(ParameterSetName = 'ByGPOIdObjectName')] [Parameter(ParameterSetName = 'ByGPPSectionObjectName')] [string]$Name, [Parameter(ParameterSetName = 'ByGPONameObjectLiteralName', Mandatory)] [Parameter(ParameterSetName = 'ByGPOIdObjectLiteralName', Mandatory)] [Parameter(ParameterSetName = 'ByGPPSectionObjectLiteralName', Mandatory)] [string]$LiteralName, [Parameter(ParameterSetName = 'ByGPONameObjectSID', Mandatory)] [Parameter(ParameterSetName = 'ByGPOIdObjectSID', Mandatory)] [Parameter(ParameterSetName = 'ByGPPSectionObjectSID', Mandatory)] [System.Security.Principal.SecurityIdentifier]$SID, [Parameter(ParameterSetName = 'ByGPONameObjectUID', Mandatory)] [Parameter(ParameterSetName = 'ByGPOIdObjectUID', Mandatory)] [Parameter(ParameterSetName = 'ByGPPSectionObjectUID', Mandatory)] [guid]$UID, [Parameter(ParameterSetName = 'ByGPONameObjectName', Mandatory)] [Parameter(ParameterSetName = 'ByGPONameObjectLiteralName', Mandatory)] [Parameter(ParameterSetName = 'ByGPONameObjectSID', Mandatory)] [Parameter(ParameterSetName = 'ByGPONameObjectUID', Mandatory)] [string]$GPOName, [Parameter(ParameterSetName = 'ByGPOIdObjectName', Mandatory)] [Parameter(ParameterSetName = 'ByGPOIdObjectLiteralName', Mandatory)] [Parameter(ParameterSetName = 'ByGPOIdObjectSID', Mandatory)] [Parameter(ParameterSetName = 'ByGPOIdObjectUID', Mandatory)] [guid]$GPOId, [Parameter(ParameterSetName = 'ByGPPSectionObjectName', Mandatory)] [Parameter(ParameterSetName = 'ByGPPSectionObjectLiteralName', Mandatory)] [Parameter(ParameterSetName = 'ByGPPSectionObjectSID', Mandatory)] [Parameter(ParameterSetName = 'ByGPPSectionObjectUID', Mandatory)] [GPPSection]$GPPSection, [Parameter(ParameterSetName = 'ByGPONameObjectName')] [Parameter(ParameterSetName = 'ByGPONameObjectLiteralName')] [Parameter(ParameterSetName = 'ByGPONameObjectSID')] [Parameter(ParameterSetName = 'ByGPONameObjectUID')] [Parameter(ParameterSetName = 'ByGPOIdObjectName')] [Parameter(ParameterSetName = 'ByGPOIdObjectLiteralName')] [Parameter(ParameterSetName = 'ByGPOIdObjectSID')] [Parameter(ParameterSetName = 'ByGPOIdObjectUID')] [GPPContext]$Context = $ModuleWideDefaultGPPContext ) if (-not $GPPSection) { if (-not $GPOId) { $GPOId = Convert-GPONameToID -Name $GPOName } $GPPSection = Get-GPPSection -GPOId $GPOId -Context $Context -Type ([GPPType]::Groups) } $Groups = $GPPSection.Members | Where-Object -FilterScript { $_ -is [GPPItemGroup] } if ($Groups) { $FilterScript = if ($UID) { { $_.uid -eq $UID } } elseif ($SID) { { $_.Properties.groupSid -eq $SID } } else { if ($LiteralName) { { $_.Properties.groupName -eq $LiteralName } } else { $FilterName = if ($Name) { $Name } else { '*' } { $_.Properties.groupName -like $FilterName } } } $Groups | Where-Object -FilterScript $FilterScript } } |