├── ADGrouper ├── ADGrouper.psd1 ├── ADGrouper.psm1 ├── Private │ ├── Expand-Account.ps1 │ ├── Get-ADObjectClass.ps1 │ ├── Get-ADSIObject.ps1 │ ├── Get-PropertyOrder.ps1 │ └── powershell-yaml │ │ ├── LICENSE │ │ ├── Load-Assemblies.ps1 │ │ ├── README.md │ │ ├── lib │ │ ├── net35 │ │ │ ├── LICENSE │ │ │ ├── LICENSE-libyaml │ │ │ ├── YamlDotNet.dll │ │ │ ├── YamlDotNet.pdb │ │ │ └── YamlDotNet.xml │ │ └── net45 │ │ │ ├── LICENSE │ │ │ ├── LICENSE-libyaml │ │ │ ├── YamlDotNet.dll │ │ │ ├── YamlDotNet.pdb │ │ │ └── YamlDotNet.xml │ │ ├── powershell-yaml.psd1 │ │ └── powershell-yaml.psm1 ├── Public │ ├── Expand-ADDynamicGroup.ps1 │ ├── Get-ADDynamicGroup.ps1 │ └── Invoke-ADGrouper.ps1 └── en-US │ └── about_ADGrouper.help.txt ├── Build ├── Start-Build.ps1 ├── build.requirements.psd1 ├── deploy.psdeploy.ps1 ├── helpers │ └── Install-PSDepend.ps1 └── psake.ps1 ├── LICENSE ├── README.md ├── Tests ├── ADGrouper.Tests.ps1 └── Data │ ├── override.yaml │ └── simple.yaml └── appveyor.yml /ADGrouper/ADGrouper.psd1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RamblingCookieMonster/ADGrouper/1664a72bb35362d74272cc186015d3b3d245dbe1/ADGrouper/ADGrouper.psd1 -------------------------------------------------------------------------------- /ADGrouper/ADGrouper.psm1: -------------------------------------------------------------------------------- 1 | #Module vars 2 | $ModulePath = $PSScriptRoot 3 | 4 | #Get public and private function definition files. 5 | $Public = Get-ChildItem $PSScriptRoot\Public\*.ps1 -ErrorAction SilentlyContinue 6 | $Private = Get-ChildItem $PSScriptRoot\Private\*.ps1 -ErrorAction SilentlyContinue 7 | [string[]]$PrivateModules = Get-ChildItem $PSScriptRoot\Private -ErrorAction SilentlyContinue | 8 | Where-Object {$_.PSIsContainer} | 9 | Select -ExpandProperty FullName 10 | 11 | # Dot source the files 12 | Foreach($import in @($Public + $Private)) 13 | { 14 | Try 15 | { 16 | . $import.fullname 17 | } 18 | Catch 19 | { 20 | Write-Error "Failed to import function $($import.fullname): $_" 21 | } 22 | } 23 | 24 | # Load up dependency modules 25 | foreach($Module in $PrivateModules) 26 | { 27 | Try 28 | { 29 | Import-Module $Module -ErrorAction Stop 30 | } 31 | Catch 32 | { 33 | Write-Error "Failed to import module $Module`: $_" 34 | } 35 | } 36 | 37 | Export-ModuleMember -Function $Public.Basename -------------------------------------------------------------------------------- /ADGrouper/Private/Expand-Account.ps1: -------------------------------------------------------------------------------- 1 | function Expand-Account { 2 | [cmdletbinding()] 3 | param( 4 | $Identity, 5 | $Type, 6 | [switch]$Recurse, 7 | [switch]$Expand 8 | ) 9 | if($Type -eq 'Group' -and $Expand) 10 | { 11 | $params = @{ 12 | Identity = $Identity 13 | } 14 | if($Recurse) 15 | { 16 | $params.add('Recursive', $True) 17 | } 18 | (Get-ADGroupMember @params).samaccountname # TODO: Consider non-ActiveDirectory module implementation 19 | } 20 | else 21 | { 22 | $Identity 23 | } 24 | } -------------------------------------------------------------------------------- /ADGrouper/Private/Get-ADObjectClass.ps1: -------------------------------------------------------------------------------- 1 | function Get-ADObjectClass { 2 | [cmdletbinding()] 3 | param( 4 | $sAMAccountName, 5 | $IncludeType = $True 6 | ) 7 | if($IncludeType) 8 | { 9 | $Type = ( Get-ADSIObject $sAMAccountName -Property objectClass ).objectClass 10 | if($Type.count -gt 0) 11 | { 12 | switch ($Type[-1]) 13 | { 14 | 'user' {'User'} 15 | 'group' {'Group'} 16 | Default { Write-Warning "sAMAccountName [$sAMAccountName] is an unsupported type, [$($Type -join ', ')]"} 17 | } 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /ADGrouper/Private/Get-ADSIObject.ps1: -------------------------------------------------------------------------------- 1 | function Get-ADSIObject { 2 | <# 3 | .SYNOPSIS 4 | Get AD object (user, group, etc.) via ADSI. 5 | 6 | .DESCRIPTION 7 | Get AD object (user, group, etc.) via ADSI. 8 | 9 | Invoke a specify an LDAP Query, or search based on samaccountname and/or objectcategory 10 | 11 | .FUNCTIONALITY 12 | Active Directory 13 | 14 | .PARAMETER samAccountName 15 | Specific samaccountname to filter on 16 | 17 | .PARAMETER ObjectCategory 18 | Specific objectCategory to filter on 19 | 20 | .PARAMETER Query 21 | LDAP filter to invoke 22 | 23 | .PARAMETER Path 24 | LDAP Path. e.g. contoso.com, DomainController1 25 | 26 | LDAP:// is prepended when omitted 27 | 28 | .PARAMETER Property 29 | Specific properties to query for 30 | 31 | .PARAMETER Limit 32 | If specified, limit results to this size 33 | 34 | .PARAMETER Credential 35 | Credential to use for query 36 | 37 | If specified, the Path parameter must be specified as well. 38 | 39 | .PARAMETER As 40 | SearchResult = results directly from DirectorySearcher 41 | DirectoryEntry = Invoke GetDirectoryEntry against each DirectorySearcher object returned 42 | PSObject (Default) = Create a PSObject with expected properties and types 43 | 44 | .EXAMPLE 45 | Get-ADSIObject jdoe 46 | # Find an AD object with the samaccountname jdoe 47 | 48 | .EXAMPLE 49 | Get-ADSIObject -Query "(&(objectCategory=Group)(samaccountname=domain admins))" 50 | # Find an AD object meeting the specified criteria 51 | 52 | .EXAMPLE 53 | Get-ADSIObject -Query "(objectCategory=Group)" -Path contoso.com 54 | # List all groups at the root of contoso.com 55 | 56 | .EXAMPLE 57 | Echo jdoe, cmonster | Get-ADSIObject -property mail -ObjectCategory User | Select -expandproperty mail 58 | # Find an AD object for a few users, extract the mail property only 59 | 60 | .EXAMPLE 61 | $DirectoryEntry = Get-ADSIObject TESTUSER -as DirectoryEntry 62 | $DirectoryEntry.put(‘Title’,’Test’) 63 | $DirectoryEntry.setinfo() 64 | 65 | #Get the AD object for TESTUSER in a usable form (DirectoryEntry), set the title attribute to Test, and make the change. 66 | 67 | .LINK 68 | https://gallery.technet.microsoft.com/scriptcenter/Get-ADSIObject-Portable-ae7f9184 69 | 70 | #> 71 | [cmdletbinding(DefaultParameterSetName='SAM')] 72 | Param( 73 | [Parameter( Position=0, 74 | Mandatory = $true, 75 | ValueFromPipeline=$true, 76 | ValueFromPipelineByPropertyName=$true, 77 | ParameterSetName='SAM')] 78 | [string[]]$samAccountName = "*", 79 | 80 | [Parameter( Position=1, 81 | ParameterSetName='SAM')] 82 | [string[]]$ObjectCategory = "*", 83 | 84 | [Parameter( ParameterSetName='Query', 85 | Mandatory = $true )] 86 | [string]$Query = $null, 87 | 88 | [string]$Path = $Null, 89 | 90 | [string[]]$Property = $Null, 91 | 92 | [int]$Limit, 93 | 94 | [System.Management.Automation.PSCredential]$Credential, 95 | 96 | [validateset("PSObject","DirectoryEntry","SearchResult")] 97 | [string]$As = "PSObject" 98 | ) 99 | 100 | Begin 101 | { 102 | #Define parameters for creating the object 103 | $Params = @{ 104 | TypeName = "System.DirectoryServices.DirectoryEntry" 105 | ErrorAction = "Stop" 106 | } 107 | 108 | #If we have an LDAP path, add it in. 109 | if($Path){ 110 | 111 | if($Path -notlike "^LDAP") 112 | { 113 | $Path = "LDAP://$Path" 114 | } 115 | 116 | $Params.ArgumentList = @($Path) 117 | 118 | #if we have a credential, add it in 119 | if($Credential) 120 | { 121 | $Params.ArgumentList += $Credential.UserName 122 | $Params.ArgumentList += $Credential.GetNetworkCredential().Password 123 | } 124 | } 125 | elseif($Credential) 126 | { 127 | Throw "Using the Credential parameter requires a valid Path parameter" 128 | } 129 | 130 | #Create the domain entry for search root 131 | Try 132 | { 133 | Write-Verbose "Bound parameters:`n$($PSBoundParameters | Format-List | Out-String )`nCreating DirectoryEntry with parameters:`n$($Params | Out-String)" 134 | $DomainEntry = New-Object @Params 135 | } 136 | Catch 137 | { 138 | Throw "Could not establish DirectoryEntry: $_" 139 | } 140 | $DomainName = $DomainEntry.name 141 | 142 | #Set up the searcher 143 | $Searcher = New-Object -TypeName System.DirectoryServices.DirectorySearcher 144 | $Searcher.PageSize = 1000 145 | $Searcher.SearchRoot = $DomainEntry 146 | if($Limit) 147 | { 148 | $Searcher.SizeLimit = $limit 149 | } 150 | if($Property) 151 | { 152 | foreach($Prop in $Property) 153 | { 154 | $Searcher.PropertiesToLoad.Add($Prop) | Out-Null 155 | } 156 | } 157 | 158 | #Define a function to get ADSI results from a specific query 159 | Function Get-ADSIResult 160 | { 161 | [cmdletbinding()] 162 | param( 163 | [string[]]$Property = $Null, 164 | [string]$Query, 165 | [string]$As, 166 | $Searcher 167 | ) 168 | 169 | #Invoke the query 170 | $Results = $null 171 | $Searcher.Filter = $Query 172 | $Results = $Searcher.FindAll() 173 | 174 | #If SearchResult, just spit out the results. 175 | if($As -eq "SearchResult") 176 | { 177 | $Results 178 | } 179 | #If DirectoryEntry, invoke GetDirectoryEntry 180 | elseif($As -eq "DirectoryEntry") 181 | { 182 | $Results | ForEach-Object { $_.GetDirectoryEntry() } 183 | } 184 | #Otherwise, get properties from the object 185 | else 186 | { 187 | $Results | ForEach-Object { 188 | 189 | #Get the keys. They aren't an array, so split them up, remove empty, and trim just in case I screwed something up... 190 | $object = $_ 191 | #cast to array of strings or else PS2 breaks when we select down the line 192 | [string[]]$properties = ($object.properties.PropertyNames) -split "`r|`n" | Where-Object { $_ } | ForEach-Object { $_.Trim() } 193 | 194 | #Filter properties if desired 195 | if($Property) 196 | { 197 | $properties = $properties | Where-Object {$Property -Contains $_} 198 | } 199 | 200 | #Build up an object to output. Loop through each property, extract from ResultPropertyValueCollection 201 | #Create the object, PS2 compatibility. can't just pipe to select, props need to exist 202 | $hash = @{} 203 | foreach($prop in $properties) 204 | { 205 | $hash.$prop = $null 206 | } 207 | $Temp = New-Object -TypeName PSObject -Property $hash | Select -Property $properties 208 | 209 | foreach($Prop in $properties) 210 | { 211 | Try 212 | { 213 | $Temp.$Prop = foreach($item in $object.properties.$prop) 214 | { 215 | $item 216 | } 217 | } 218 | Catch 219 | { 220 | Write-Warning "Could not get property '$Prop': $_" 221 | } 222 | } 223 | $Temp 224 | } 225 | } 226 | } 227 | } 228 | Process 229 | { 230 | #Set up the query as defined, or look for a samaccountname. Probably a cleaner way to do this... 231 | if($PsCmdlet.ParameterSetName -eq 'Query'){ 232 | Write-Verbose "Working on Query '$Query'" 233 | Get-ADSIResult -Searcher $Searcher -Property $Property -Query $Query -As $As 234 | } 235 | else 236 | { 237 | foreach($AccountName in $samAccountName) 238 | { 239 | #Build up the LDAP query... 240 | $QueryArray = @( "(samAccountName=$AccountName)" ) 241 | if($ObjectCategory) 242 | { 243 | [string]$TempString = ( $ObjectCategory | ForEach-Object {"(objectCategory=$_)"} ) -join "" 244 | $QueryArray += "(|$TempString)" 245 | } 246 | $Query = "(&$($QueryArray -join ''))" 247 | Write-Verbose "Working on built Query '$Query'" 248 | Get-ADSIResult -Searcher $Searcher -Property $Property -Query $Query -As $As 249 | } 250 | } 251 | } 252 | End 253 | { 254 | $Searcher = $null 255 | $DomainEntry = $null 256 | } 257 | } -------------------------------------------------------------------------------- /ADGrouper/Private/Get-PropertyOrder.ps1: -------------------------------------------------------------------------------- 1 | #function to extract properties 2 | Function Get-PropertyOrder { 3 | <# 4 | .SYNOPSIS 5 | Gets property order for specified object 6 | 7 | .DESCRIPTION 8 | Gets property order for specified object 9 | 10 | .PARAMETER InputObject 11 | A single object to convert to an array of property value pairs. 12 | 13 | .PARAMETER Membertype 14 | Membertypes to include 15 | 16 | .PARAMETER ExcludeProperty 17 | Specific properties to exclude 18 | 19 | .FUNCTIONALITY 20 | PowerShell Language 21 | #> 22 | [cmdletbinding()] 23 | param( 24 | [Parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromRemainingArguments=$false)] 25 | [PSObject]$InputObject, 26 | 27 | [validateset("AliasProperty", "CodeProperty", "Property", "NoteProperty", "ScriptProperty", 28 | "Properties", "PropertySet", "Method", "CodeMethod", "ScriptMethod", "Methods", 29 | "ParameterizedProperty", "MemberSet", "Event", "Dynamic", "All")] 30 | [string[]]$MemberType = @( "NoteProperty", "Property", "ScriptProperty" ), 31 | 32 | [string[]]$ExcludeProperty = $null 33 | ) 34 | 35 | begin { 36 | 37 | if($PSBoundParameters.ContainsKey('inputObject')) { 38 | $firstObject = $InputObject[0] 39 | } 40 | } 41 | process{ 42 | 43 | #we only care about one object... 44 | $firstObject = $InputObject 45 | } 46 | end{ 47 | 48 | #Get properties that meet specified parameters 49 | $firstObject.psobject.properties | 50 | Where-Object { $memberType -contains $_.memberType } | 51 | Select -ExpandProperty Name | 52 | Where-Object{ -not $excludeProperty -or $excludeProperty -notcontains $_ } 53 | } 54 | } #Get-PropertyOrder -------------------------------------------------------------------------------- /ADGrouper/Private/powershell-yaml/LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright 2016 Cloudbase Solutions SRL 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /ADGrouper/Private/powershell-yaml/Load-Assemblies.ps1: -------------------------------------------------------------------------------- 1 | # Copyright 2016 Cloudbase Solutions Srl 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may 4 | # not use this file except in compliance with the License. You may obtain 5 | # a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | # License for the specific language governing permissions and limitations 13 | # under the License. 14 | # 15 | 16 | $here = Split-Path -Parent $MyInvocation.MyCommand.Path 17 | 18 | function Initialize-Assemblies { 19 | $libDir = Join-Path $here "lib" 20 | $assemblies = @{ 21 | "portable" = Join-Path $libDir "net45\YamlDotNet.dll"; 22 | "released" = Join-Path $libDir "net35\YamlDotNet.dll"; 23 | } 24 | 25 | try { 26 | [YamlDotNet.Serialization.Serializer] | Out-Null 27 | } catch [System.Management.Automation.RuntimeException] { 28 | try { 29 | return [Microsoft.PowerShell.CoreCLR.AssemblyExtensions]::LoadFrom($assemblies["portable"]) 30 | } catch [System.Management.Automation.RuntimeException] { 31 | return [Reflection.Assembly]::LoadFrom($assemblies["released"]) 32 | } 33 | } 34 | } 35 | 36 | Initialize-Assemblies | Out-Null 37 | -------------------------------------------------------------------------------- /ADGrouper/Private/powershell-yaml/README.md: -------------------------------------------------------------------------------- 1 | # powershell-yaml 2 | 3 | This powershell module is a thin wrapper on top of [YamlDotNet](https://github.com/aaubry/YamlDotNet "YamlDotNet") that serializes and un-serializes simple powershell objects to and from YAML. It was tested on powershell versions 4 and 5 and supports [Nano Server](https://technet.microsoft.com/en-us/library/mt126167.aspx Nano). 4 | 5 | The ```lib``` folder contains the YamlDotNet assemblies. They are not really required, just a fall-back in case your system does not already have them installed and loaded. Feel free to remove the ```lib``` folder if you prefer to add the required assemblies yourself. 6 | 7 | ## ConvertTo-Yaml 8 | 9 | ```powershell 10 | Import-Module powershell-yaml 11 | 12 | PS C:\> $yaml = ConvertTo-Yaml @{"hello"="world"; "anArray"=@(1,2,3); "nested"=@{"array"=@("this", "is", "an", "array")}} 13 | PS C:\> $yaml 14 | anArray: 15 | - 1 16 | - 2 17 | - 3 18 | nested: 19 | array: 20 | - this 21 | - is 22 | - an 23 | - array 24 | hello: world 25 | ``` 26 | 27 | ## ConvertFrom-Yaml 28 | 29 | ### Single YAML document 30 | 31 | ```powershell 32 | Import-Module powershell-yaml 33 | 34 | PS C:\> $yaml = @" 35 | anArray: 36 | - 1 37 | - 2 38 | - 3 39 | nested: 40 | array: 41 | - this 42 | - is 43 | - an 44 | - array 45 | hello: world 46 | "@ 47 | 48 | PS C:\> $obj = ConvertFrom-Yaml $yaml 49 | PS C:\> $obj 50 | 51 | Name Value 52 | ---- ----- 53 | anArray {1, 2, 3} 54 | nested {array} 55 | hello world 56 | 57 | PS C:\> $obj.GetType() 58 | 59 | IsPublic IsSerial Name BaseType 60 | -------- -------- ---- -------- 61 | True True Hashtable System.Object 62 | ``` 63 | 64 | ### Multiple YAML documents 65 | 66 | Unserializing multiple documents results in an array representing the contents of each document. The result of this does not translate back to the same documents if you pass it back through ConvertTo-Yaml. 67 | 68 | ```powershell 69 | Import-Module powershell-yaml 70 | 71 | PS C:\> $yaml = @" 72 | --- 73 | anArray: 74 | - 1 75 | - 2 76 | - 3 77 | nested: 78 | array: 79 | - this 80 | - is 81 | - an 82 | - array 83 | hello: world 84 | --- 85 | second: document 86 | goodbye: world 87 | "@ 88 | 89 | PS C:\> $obj = ConvertFrom-Yaml $yaml -AllDocuments 90 | PS C:\> $obj 91 | 92 | Name Value 93 | ---- ----- 94 | anArray {1, 2, 3} 95 | nested {array} 96 | hello world 97 | goodbye world 98 | second document 99 | 100 | PS C:\> $obj.GetType() 101 | 102 | IsPublic IsSerial Name BaseType 103 | -------- -------- ---- -------- 104 | True True Object[] System.Array 105 | 106 | PS C:\> $obj[0] 107 | 108 | Name Value 109 | ---- ----- 110 | anArray {1, 2, 3} 111 | nested {array} 112 | hello world 113 | 114 | PS C:\> $obj[1] 115 | 116 | Name Value 117 | ---- ----- 118 | goodbye world 119 | second document 120 | ``` 121 | 122 | ## Running the tests. 123 | 124 | Before running the associated unit tests; please make sure you have 125 | [Pester](https://github.com/pester/pester) installed, as it is the testing 126 | framework of choice. 127 | 128 | After Pester is up and running, the tests may be ran by simply entering the 129 | tests directory and running `Invoke-Pester`: 130 | 131 | ``` 132 | PS C:\> git clone https://github.com/cloudbase/powershell-yaml.git $HOME\powershell-yaml 133 | PS C:\> cd $HOME\powershell-yaml 134 | PS C:\Users\Guest\powershell-yaml> powershell.exe -NonInteractive -Command {Invoke-Pester} 135 | ``` 136 | -------------------------------------------------------------------------------- /ADGrouper/Private/powershell-yaml/lib/net35/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014 Antoine Aubry and contributors 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of 4 | this software and associated documentation files (the "Software"), to deal in 5 | the Software without restriction, including without limitation the rights to 6 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 7 | of the Software, and to permit persons to whom the Software is furnished to do 8 | so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | SOFTWARE. 20 | 21 | -------------------------------------------------------------------------------- /ADGrouper/Private/powershell-yaml/lib/net35/LICENSE-libyaml: -------------------------------------------------------------------------------- 1 | Copyright (c) 2006 Kirill Simonov 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of 4 | this software and associated documentation files (the "Software"), to deal in 5 | the Software without restriction, including without limitation the rights to 6 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 7 | of the Software, and to permit persons to whom the Software is furnished to do 8 | so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | SOFTWARE. 20 | -------------------------------------------------------------------------------- /ADGrouper/Private/powershell-yaml/lib/net35/YamlDotNet.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RamblingCookieMonster/ADGrouper/1664a72bb35362d74272cc186015d3b3d245dbe1/ADGrouper/Private/powershell-yaml/lib/net35/YamlDotNet.dll -------------------------------------------------------------------------------- /ADGrouper/Private/powershell-yaml/lib/net35/YamlDotNet.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RamblingCookieMonster/ADGrouper/1664a72bb35362d74272cc186015d3b3d245dbe1/ADGrouper/Private/powershell-yaml/lib/net35/YamlDotNet.pdb -------------------------------------------------------------------------------- /ADGrouper/Private/powershell-yaml/lib/net45/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014 Antoine Aubry and contributors 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of 4 | this software and associated documentation files (the "Software"), to deal in 5 | the Software without restriction, including without limitation the rights to 6 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 7 | of the Software, and to permit persons to whom the Software is furnished to do 8 | so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | SOFTWARE. 20 | 21 | -------------------------------------------------------------------------------- /ADGrouper/Private/powershell-yaml/lib/net45/LICENSE-libyaml: -------------------------------------------------------------------------------- 1 | Copyright (c) 2006 Kirill Simonov 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of 4 | this software and associated documentation files (the "Software"), to deal in 5 | the Software without restriction, including without limitation the rights to 6 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 7 | of the Software, and to permit persons to whom the Software is furnished to do 8 | so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | SOFTWARE. 20 | -------------------------------------------------------------------------------- /ADGrouper/Private/powershell-yaml/lib/net45/YamlDotNet.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RamblingCookieMonster/ADGrouper/1664a72bb35362d74272cc186015d3b3d245dbe1/ADGrouper/Private/powershell-yaml/lib/net45/YamlDotNet.dll -------------------------------------------------------------------------------- /ADGrouper/Private/powershell-yaml/lib/net45/YamlDotNet.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RamblingCookieMonster/ADGrouper/1664a72bb35362d74272cc186015d3b3d245dbe1/ADGrouper/Private/powershell-yaml/lib/net45/YamlDotNet.pdb -------------------------------------------------------------------------------- /ADGrouper/Private/powershell-yaml/powershell-yaml.psd1: -------------------------------------------------------------------------------- 1 | # Copyright 2016 Cloudbase Solutions Srl 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may 4 | # not use this file except in compliance with the License. You may obtain 5 | # a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | # License for the specific language governing permissions and limitations 13 | # under the License. 14 | # 15 | # Module manifest for module 'powershell-yaml' 16 | # 17 | # Generated by: Gabriel Adrian Samfira 18 | # 19 | # Generated on: 10/01/2016 20 | # 21 | 22 | @{ 23 | 24 | # Script module or binary module file associated with this manifest. 25 | RootModule = 'powershell-yaml.psm1' 26 | 27 | # Version number of this module. 28 | ModuleVersion = '0.1' 29 | 30 | # ID used to uniquely identify this module 31 | GUID = '6a75a662-7f53-425a-9777-ee61284407da' 32 | 33 | # Author of this module 34 | Author = 'Gabriel Adrian Samfira','Alessandro Pilotti' 35 | 36 | # Company or vendor of this module 37 | CompanyName = 'Cloudbase Solutions SRL' 38 | 39 | # Copyright statement for this module 40 | Copyright = '(c) 2016 Cloudbase Solutions SRL. All rights reserved.' 41 | 42 | # Description of the functionality provided by this module 43 | Description = 'Powershell module for serializing and deserializing YAML' 44 | 45 | # Minimum version of the Windows PowerShell engine required by this module 46 | PowerShellVersion = '3.0' 47 | 48 | # Script files (.ps1) that are run in the caller's environment prior to importing this module. 49 | ScriptsToProcess = @("Load-Assemblies.ps1") 50 | 51 | # Functions to export from this module 52 | FunctionsToExport = "ConvertTo-Yaml","ConvertFrom-Yaml" 53 | 54 | } 55 | -------------------------------------------------------------------------------- /ADGrouper/Private/powershell-yaml/powershell-yaml.psm1: -------------------------------------------------------------------------------- 1 | # Copyright 2016 Cloudbase Solutions Srl 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may 4 | # not use this file except in compliance with the License. You may obtain 5 | # a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | # License for the specific language governing permissions and limitations 13 | # under the License. 14 | # 15 | 16 | function Get-YamlDocuments { 17 | [CmdletBinding()] 18 | Param( 19 | [Parameter(Mandatory=$true, ValueFromPipeline=$true)] 20 | [string]$Yaml 21 | ) 22 | PROCESS { 23 | $stringReader = new-object System.IO.StringReader($Yaml) 24 | $yamlStream = New-Object "YamlDotNet.RepresentationModel.YamlStream" 25 | $yamlStream.Load([System.IO.TextReader] $stringReader) 26 | $stringReader.Close() 27 | return $yamlStream 28 | } 29 | } 30 | 31 | function Convert-ValueToProperType { 32 | [CmdletBinding()] 33 | Param( 34 | [Parameter(Mandatory=$true,ValueFromPipeline=$true)] 35 | [System.Object]$Value 36 | ) 37 | PROCESS { 38 | if (!($Value -is [string])) { 39 | return $Value 40 | } 41 | $types = @([int], [long], [double], [boolean], [datetime]) 42 | foreach($i in $types){ 43 | try { 44 | return $i::Parse($Value) 45 | } catch { 46 | continue 47 | } 48 | } 49 | return $Value 50 | } 51 | } 52 | 53 | function Convert-YamlMappingToHashtable { 54 | [CmdletBinding()] 55 | Param( 56 | [Parameter(Mandatory=$true, ValueFromPipeline=$true)] 57 | [YamlDotNet.RepresentationModel.YamlMappingNode]$Node 58 | ) 59 | PROCESS { 60 | $ret = @{} 61 | foreach($i in $Node.Children.Keys) { 62 | $ret[$i.Value] = Convert-YamlDocumentToPSObject $Node.Children[$i] 63 | } 64 | return $ret 65 | } 66 | } 67 | 68 | function Convert-YamlSequenceToArray { 69 | [CmdletBinding()] 70 | Param( 71 | [Parameter(Mandatory=$true, ValueFromPipeline=$true)] 72 | [YamlDotNet.RepresentationModel.YamlSequenceNode]$Node 73 | ) 74 | PROCESS { 75 | $ret = [System.Collections.Generic.List[object]](New-Object "System.Collections.Generic.List[object]") 76 | foreach($i in $Node.Children){ 77 | $ret.Add((Convert-YamlDocumentToPSObject $i)) 78 | } 79 | return $ret 80 | } 81 | } 82 | 83 | function Convert-YamlDocumentToPSObject { 84 | [CmdletBinding()] 85 | Param( 86 | [Parameter(Mandatory=$true, ValueFromPipeline=$true)] 87 | [System.Object]$Node 88 | ) 89 | PROCESS { 90 | switch($Node.GetType().FullName){ 91 | "YamlDotNet.RepresentationModel.YamlMappingNode"{ 92 | return Convert-YamlMappingToHashtable $Node 93 | } 94 | "YamlDotNet.RepresentationModel.YamlSequenceNode" { 95 | return Convert-YamlSequenceToArray $Node 96 | } 97 | "YamlDotNet.RepresentationModel.YamlScalarNode" { 98 | return (Convert-ValueToProperType $Node.Value) 99 | } 100 | } 101 | } 102 | } 103 | 104 | function Convert-HashtableToDictionary { 105 | Param( 106 | [Parameter(Mandatory=$true,ValueFromPipeline=$true)] 107 | [hashtable]$Data 108 | ) 109 | foreach($i in $($data.Keys)) { 110 | $Data[$i] = Convert-PSObjectToGenericObject $Data[$i] 111 | } 112 | return $Data 113 | } 114 | 115 | function Convert-ListToGenericList { 116 | Param( 117 | [Parameter(Mandatory=$true,ValueFromPipeline=$true)] 118 | [array]$Data 119 | ) 120 | for($i=0; $i -lt $Data.Count; $i++) { 121 | $Data[$i] = Convert-PSObjectToGenericObject $Data[$i] 122 | } 123 | return ,$Data 124 | } 125 | 126 | function Convert-PSCustomObjectToDictionary { 127 | Param( 128 | [Parameter(Mandatory=$true,ValueFromPipeline=$true)] 129 | [PSCustomObject]$Data 130 | ) 131 | $ret = [System.Collections.Generic.Dictionary[string,object]](New-Object 'System.Collections.Generic.Dictionary[string,object]') 132 | foreach ($i in $Data.psobject.properties) { 133 | $ret[$i.Name] = Convert-PSObjectToGenericObject $i.Value 134 | } 135 | return $ret 136 | } 137 | 138 | function Convert-PSObjectToGenericObject { 139 | Param( 140 | [Parameter(Mandatory=$true,ValueFromPipeline=$true)] 141 | [System.Object]$Data 142 | ) 143 | # explicitly cast object to its type. Without this, it gets wrapped inside a powershell object 144 | # which causes YamlDotNet to fail 145 | $data = $data -as $data.GetType().FullName 146 | switch($data.GetType()) { 147 | ($_.FullName -eq "System.Management.Automation.PSCustomObject") { 148 | return Convert-PSCustomObjectToDictionary $data 149 | } 150 | default { 151 | if (([System.Collections.IDictionary].IsAssignableFrom($_))){ 152 | return Convert-HashtableToDictionary $data 153 | } elseif (([System.Collections.IList].IsAssignableFrom($_))) { 154 | return Convert-ListToGenericList $data 155 | } 156 | return $data 157 | } 158 | } 159 | } 160 | 161 | function ConvertFrom-Yaml { 162 | [CmdletBinding()] 163 | Param( 164 | [Parameter(Mandatory=$false, ValueFromPipeline=$true)] 165 | [string]$Yaml, 166 | [switch]$AllDocuments=$false 167 | ) 168 | PROCESS { 169 | if(!$Yaml){ 170 | return 171 | } 172 | $documents = Get-YamlDocuments -Yaml $Yaml 173 | if (!$documents.Count) { 174 | return 175 | } 176 | if($documents.Count -eq 1){ 177 | return Convert-YamlDocumentToPSObject $documents[0].RootNode 178 | } 179 | if(!$AllDocuments) { 180 | return Convert-YamlDocumentToPSObject $documents[0].RootNode 181 | } 182 | $ret = @() 183 | foreach($i in $documents) { 184 | $ret += Convert-YamlDocumentToPSObject $i.RootNode 185 | } 186 | return $ret 187 | } 188 | } 189 | 190 | function ConvertTo-Yaml { 191 | [CmdletBinding()] 192 | Param( 193 | [Parameter(Mandatory=$false,ValueFromPipeline=$true)] 194 | [System.Object]$Data, 195 | [Parameter(Mandatory=$false)] 196 | [string]$OutFile, 197 | [switch]$Force=$false 198 | ) 199 | BEGIN { 200 | $d = [System.Collections.Generic.List[object]](New-Object "System.Collections.Generic.List[object]") 201 | } 202 | PROCESS { 203 | if($data -ne $null) { 204 | $d.Add($data) 205 | } 206 | } 207 | END { 208 | if($d -eq $null -or $d.Count -eq 0){ 209 | return 210 | } 211 | if($d.Count -eq 1) { 212 | $d = $d[0] 213 | } 214 | $norm = Convert-PSObjectToGenericObject $d 215 | if($OutFile) { 216 | $parent = Split-Path $OutFile 217 | if(!(Test-Path $parent)) { 218 | Throw "Parent folder for specified path does not exist" 219 | } 220 | if((Test-Path $OutFile) -and !$Force){ 221 | Throw "Target file already exists. Use -Force to overwrite." 222 | } 223 | $wrt = New-Object "System.IO.StreamWriter" $OutFile 224 | } else { 225 | $wrt = New-Object "System.IO.StringWriter" 226 | } 227 | try { 228 | $serializer = New-Object "YamlDotNet.Serialization.Serializer" 0 229 | $serializer.Serialize($wrt, $norm) 230 | } finally { 231 | $wrt.Close() 232 | } 233 | if($OutFile){ 234 | return 235 | }else { 236 | return $wrt.ToString() 237 | } 238 | } 239 | } 240 | 241 | Export-ModuleMember -Function * -Alias * 242 | -------------------------------------------------------------------------------- /ADGrouper/Public/Expand-ADDynamicGroup.ps1: -------------------------------------------------------------------------------- 1 | Function Expand-ADDynamicGroup { 2 | <# 3 | .SYNOPSIS 4 | Expand dynamic security group definition to describe actions to take 5 | 6 | .DESCRIPTION 7 | Expand dynamic security group definition to describe actions to take 8 | 9 | Takes the output of Get-ADDynamicGroup and expands this into an array of actions with the following properties: 10 | 11 | Group # The target group we will take this action on 12 | Account # The account we will act on for this target group 13 | Action # The action we will take on thie target group and account pair 14 | Type # If IncludeType parameter is specified, whether the account is a group or a user 15 | Definition # The raw input we parsed from Get-ADDynamicGroup 16 | 17 | .FUNCTIONALITY 18 | Active Directory 19 | 20 | .PARAMETER InputObject 21 | Dynamic group definition generated by Get-ADDynamicGroup 22 | 23 | .PARAMETER IncludeType 24 | If specified, parse the AD type for each AD account to be added or removed from the target group 25 | 26 | .EXAMPLE 27 | Get-ADDynamicGroup $Yaml | Expand-ADDynamicGroup 28 | 29 | .EXAMPLE 30 | Get-ADDynamicGroup $Yaml | Expand-ADDynamicGroup -IncludeType 31 | 32 | .LINK 33 | Get-ADDynamicGroup 34 | 35 | .LINK 36 | Invoke-ADGrouper 37 | 38 | .LINK 39 | about_ADGrouper 40 | #> 41 | [cmdletbinding()] 42 | param( 43 | [parameter(ValueFromPipeline= $True, 44 | Position = 0)] 45 | [PSTypeName('adgrouper.group')] 46 | [psobject[]]$InputObject, 47 | [switch]$IncludeType 48 | ) 49 | begin 50 | { 51 | function Get-Params { 52 | param($Target, $Account) 53 | $Props = Get-PropertyOrder $Account 54 | $ThisRecurse = if($Props -contains 'Recurse') {$Account.Recurse} else {$Target.Recurse} 55 | $ThisExpand = if($Props -contains 'Expand') {$Account.Expand} else {$Target.Expand} 56 | 57 | @{ 58 | Identity = $Account.Account 59 | Recurse = $ThisRecurse 60 | Expand = $ThisExpand 61 | } 62 | } 63 | } 64 | process 65 | { 66 | Write-Verbose "Expanding $($InputObject | Out-String)" 67 | foreach($Group in $InputObject) 68 | { 69 | $Excludes = New-Object System.Collections.ArrayList 70 | $Includes = New-Object System.Collections.ArrayList 71 | 72 | foreach($ADObject in @( $Group.Exclude | Where {$_.Account})) 73 | { 74 | $Type = $null 75 | $Type = Get-ADObjectClass -sAMAccountName $ADObject.Account 76 | if($Type) 77 | { 78 | $Params = Get-Params -Target $Group -Account $ADObject 79 | Write-Verbose "Expanding removal of $($ADObject.account) with type [$Type] and expand [$($Group.Expand)]" 80 | [void]$Excludes.AddRange( @(Expand-Account @Params -Type $Type ) ) 81 | } 82 | else 83 | { 84 | Write-Warning "No type found for $($ADObject.Account) exclude, skipping" 85 | } 86 | } 87 | foreach($ADObject in @( $Group.Include | Where {$_.Account})) 88 | { 89 | $Type = $null 90 | $Type = Get-ADObjectClass -sAMAccountName $ADObject.Account 91 | if($Type) 92 | { 93 | $Params = Get-Params -Target $Group -Account $ADObject 94 | Write-Verbose "Expanding inclusion of $($ADObject.account) with type [$Type], expand [$($Params.Expand)], recurse [$($Params.Recurse)]" 95 | [void]$Includes.AddRange( @(Expand-Account @Params -Type $Type) ) 96 | } 97 | else 98 | { 99 | Write-Warning "No type found for $($ADObject.Account) include, skipping" 100 | } 101 | } 102 | foreach($Query in @( $Group.IncludeQuery | Where {$_}) ) 103 | { 104 | $DiscoveredAccounts = $null 105 | [string[]]$DiscoveredAccounts = Get-ADSIObject -Query $Query | Select -ExpandProperty sAMAccountName | Where {$_} 106 | if($DiscoveredAccounts.count -gt 0) 107 | { 108 | Write-Verbose "Including $($DiscoveredAccounts.count) accounts from query [$Query]" 109 | [void]$Includes.AddRange( $DiscoveredAccounts ) 110 | } 111 | else 112 | { 113 | Write-Verbose "No accounts found for IncludeQuery [$Query]" 114 | } 115 | } 116 | foreach($Query in @( $Group.ExcludeQuery | Where {$_}) ) 117 | { 118 | $DiscoveredAccounts = $null 119 | [string[]]$DiscoveredAccounts = Get-ADSIObject -Query $Query | Select -ExpandProperty sAMAccountName | Where {$_} 120 | if($DiscoveredAccounts.count -gt 0) 121 | { 122 | Write-Verbose "Excluding $($DiscoveredAccounts.count) accounts from query [$Query]" 123 | [void]$Excludes.AddRange( $DiscoveredAccounts ) 124 | } 125 | else 126 | { 127 | Write-Verbose "No accounts found for ExcludeQuery [$Query]" 128 | } 129 | } 130 | $ExplicitExcludes = $Excludes | Sort -Unique 131 | $Includes = $Includes | Where {$ExplicitExcludes -notcontains $_} | Select -Unique 132 | $Existing = Expand-Account -Type Group -Identity $Group.TargetGroup -Expand 133 | 134 | # If an item was explicitly excluded, we remove it, regardless of purge or source includes 135 | $ToRemove = $Existing | Where {$ExplicitExcludes -contains $_} | Sort -Unique 136 | 137 | # If an items was not explicitly excluded, and not included in source groups, remove those accounts 138 | $ToRemoveIfPurge = $Existing | Where {$Includes -notcontains $_ -and $ToRemove -notcontains $_} | Sort -Unique 139 | 140 | # Only add accounts if they were not explicitly included, and not already in the group 141 | $ToAdd = $Includes | Where {$Existing -notcontains $_ -and $ToRemove -notcontains $_ -and $ToRemoveIfPurge -notcontains $_} | Sort -Unique 142 | 143 | if($Group.Purge -and $null -notlike $ToRemoveIfPurge) 144 | { 145 | foreach($Account in $ToRemoveIfPurge) 146 | { 147 | [pscustomobject]@{ 148 | PSTypeName = 'adgrouper.action' 149 | Group = $Group.TargetGroup 150 | Account = $Account 151 | Action = 'Remove' 152 | Type = Get-ADObjectClass -sAMAccountName $Account -IncludeType $IncludeType 153 | Definition = $Group 154 | } 155 | } 156 | } 157 | foreach($Account in $ToAdd) 158 | { 159 | [pscustomobject]@{ 160 | PSTypeName = 'adgrouper.action' 161 | Group = $Group.TargetGroup 162 | Account = $Account 163 | Action = 'Add' 164 | Type = Get-ADObjectClass -sAMAccountName $Account -IncludeType $IncludeType 165 | Definition = $Group 166 | } 167 | } 168 | foreach($Account in $ToRemove) 169 | { 170 | [pscustomobject]@{ 171 | PSTypeName = 'adgrouper.action' 172 | Group = $Group.TargetGroup 173 | Account = $Account 174 | Action = 'Remove' 175 | Type = Get-ADObjectClass -sAMAccountName $Account -IncludeType $IncludeType 176 | Definition = $Group 177 | } 178 | } 179 | } 180 | } 181 | } -------------------------------------------------------------------------------- /ADGrouper/Public/Get-ADDynamicGroup.ps1: -------------------------------------------------------------------------------- 1 | Function Get-ADDynamicGroup { 2 | <# 3 | .SYNOPSIS 4 | Parse yaml describing dynamic security groups 5 | 6 | .DESCRIPTION 7 | Parse yaml describing dynamic security groups 8 | 9 | This parses the yaml without hitting Active Directory 10 | 11 | .FUNCTIONALITY 12 | Active Directory 13 | 14 | .PARAMETER InputObject 15 | Yaml dynamic group definition 16 | 17 | .PARAMETER Path 18 | Path to yaml containing dynamic group definition 19 | 20 | .EXAMPLE 21 | Get-ADDynamicGroup $Yaml 22 | 23 | .LINK 24 | https://github.com/RamblingCookieMonster/ADGrouper 25 | 26 | .LINK 27 | Expand-ADDynamicGroup 28 | 29 | .LINK 30 | Invoke-ADGrouper 31 | 32 | .LINK 33 | about_ADGrouper 34 | #> 35 | [cmdletbinding( DefaultParameterSetName = 'yaml' )] 36 | param( 37 | [parameter(ParameterSetName = 'yaml', 38 | ValueFromPipeline = $True)] 39 | [string]$InputObject, 40 | 41 | [parameter(ParameterSetName = 'file', 42 | Position = 0, 43 | ValueFromPipelineByPropertyName = $True)] 44 | [Alias('FullName')] 45 | [string[]]$Path 46 | ) 47 | begin 48 | { 49 | function Parse-Option { 50 | param($Target, $Name, $Type) 51 | $ThisItem = $Target.$Type.get_item($Name) 52 | $ThisRecurse = if($ThisItem -is [hashtable] -and $ThisItem.ContainsKey('Recurse')) {$ThisItem.Recurse} else {$Recurse} 53 | $ThisPurge = if($ThisItem -is [hashtable] -and $ThisItem.ContainsKey('Purge')) {$ThisItem.Purge} else {$Purge} 54 | $ThisExpand = if($ThisItem -is [hashtable] -and $ThisItem.ContainsKey('Expand')) {$ThisItem.Expand} else {$Expand} 55 | [pscustomobject]@{ 56 | Account = $Name 57 | Recurse = $ThisRecurse 58 | Purge = $ThisPurge 59 | Expand = $ThisExpand 60 | } 61 | } 62 | } 63 | process 64 | { 65 | $ToProcess = [System.Collections.ArrayList]@() 66 | if($PSCmdlet.ParameterSetName -eq 'file') 67 | { 68 | foreach($File in $Path) 69 | { 70 | $ToProcess.AddRange( @(Get-Content $File -Raw) ) 71 | } 72 | } 73 | else 74 | { 75 | [void]$ToProcess.Add($InputObject) 76 | } 77 | 78 | $ValuesForTrue = '1', 'True', 'Yes', $True 79 | foreach($Yaml in $ToProcess) 80 | { 81 | $Groups = ConvertFrom-Yaml -Yaml $Yaml 82 | foreach($GroupName in $Groups.keys) 83 | { 84 | $Group = $Groups[$GroupName] 85 | 86 | # Parse global options 87 | $Recurse = $False 88 | if($null -eq $Group.Recurse -or $ValuesForTrue -contains $Group.Recurse) 89 | { 90 | $Recurse = $True 91 | } 92 | $Expand = $False 93 | if($null -eq $Group.Expand -or $ValuesForTrue -contains $Group.Expand) 94 | { 95 | $Expand = $True 96 | } 97 | $Purge = $False 98 | if($ValuesForTrue -contains $Group.Purge) 99 | { 100 | $Purge = $True 101 | } 102 | $IncludeQuery = $null 103 | if($Group.IncludeQuery) 104 | { 105 | $IncludeQuery = $Group.IncludeQuery 106 | } 107 | $ExcludeQuery = $null 108 | if($Group.ExcludeQuery) 109 | { 110 | $ExcludeQuery = $Group.ExcludeQuery 111 | } 112 | 113 | $Include = $null 114 | if($Group.Include) { 115 | $Include = $Group.Include.keys | Foreach { 116 | Parse-Option -Target $Group -Name $_ -Type Include 117 | } 118 | } 119 | $Exclude = $null 120 | if($Group.Exclude) { 121 | $Exclude = $Group.Exclude.keys | Foreach { 122 | Parse-Option -Target $Group -Name $_ -Type Exclude 123 | } 124 | } 125 | 126 | [pscustomobject]@{ 127 | PSTypeName = 'adgrouper.group' 128 | TargetGroup = $GroupName 129 | Recurse = $Recurse 130 | Purge = $Purge 131 | Expand = $Expand 132 | IncludeQuery = $IncludeQuery 133 | Include = $Include 134 | Exclude = $Exclude 135 | ExcludeQuery = $ExcludeQuery 136 | } 137 | } 138 | } 139 | } 140 | } 141 | -------------------------------------------------------------------------------- /ADGrouper/Public/Invoke-ADGrouper.ps1: -------------------------------------------------------------------------------- 1 | Function Invoke-ADGrouper { 2 | <# 3 | .SYNOPSIS 4 | Adjust AD group membership based on yaml config files 5 | 6 | .DESCRIPTION 7 | Adjust AD group membership based on yaml config files 8 | 9 | YAML schema: 10 | 11 | 'Target Group': # Target security group we are populating 12 | Purge: # Whether to remove existing accounts in the groupthat aren't included in this definition. Defaults to false 13 | Recurse: # Whether to recurse membership when source is a group. Defaults to true 14 | Expand: # Whether to expand to individual accounts within the group, or use the group explicitly. Defaults to true 15 | Exclude: # Accounts to exclude from this group 16 | BadUser: # Exclude account 17 | BadGroup: # Exclude account with overriden Recurse 18 | - Recurse: False 19 | ExcludeQuery: # One or more LDAP queries whose resulting accounts are excluded from the target group 20 | - '(b=a)' 21 | Include: # Accounts to include in this group 22 | GoodGroup: # Include account with global settings 23 | GoodGroup2: # Include account with overriden Expand and Recurse 24 | - Expand: False 25 | - Recurse: False 26 | IncludeQuery: # One or more LDAP queries whose resulting accounts are included in the target group 27 | - '(a=b)' 28 | - '(c=d)' 29 | 30 | .FUNCTIONALITY 31 | Active Directory 32 | 33 | .PARAMETER InputObject 34 | Yaml dynamic group definition 35 | 36 | .PARAMETER Path 37 | Path to yaml containing dynamic group definition 38 | 39 | .PARAMETER Logfile 40 | If specified, output the set of actions taken, in a file compatible with -ReverseLog 41 | 42 | .PARAMETER ReverseLog 43 | If specified, take the specified -Logfile, and reverse the actions taken (add accounts that were removed from groups, remove accounts added to groups) 44 | 45 | .EXAMPLE 46 | Invoke-ADGrouper -Path $Yaml -Whatif 47 | 48 | # See what Invoke-ADGrouper would do with yaml, without doing it 49 | 50 | .Example 51 | Invoke-ADGrouper -Path \\Path\To\example.yaml -Confirm:$False -Force 52 | 53 | # Run example.yaml through Invoke-ADGrouper without confirmation 54 | 55 | .LINK 56 | Get-ADDynamicGroup 57 | 58 | .LINK 59 | Expand-ADDynamicGroup 60 | 61 | .LINK 62 | about_ADGrouper 63 | #> 64 | [cmdletbinding( DefaultParameterSetName = 'yaml', 65 | SupportsShouldProcess=$True, 66 | ConfirmImpact='High')] 67 | param( 68 | [parameter(ParameterSetName = 'yaml', 69 | ValueFromPipeline = $True)] 70 | [string]$InputObject, 71 | 72 | [parameter(ParameterSetName = 'file', 73 | Position = 0, 74 | ValueFromPipelineByPropertyName = $True)] 75 | [Alias('FullName')] 76 | [string[]]$Path, 77 | 78 | [switch]$Force, 79 | 80 | [parameter(ParameterSetName = 'ReverseLog', 81 | Mandatory = $True)] 82 | [parameter(ParameterSetName = 'yaml')] 83 | [parameter(ParameterSetName = 'file')] 84 | [string]$LogFile, 85 | 86 | [parameter(ParameterSetName = 'ReverseLog')] 87 | [switch]$ReverseLog 88 | ) 89 | begin 90 | { 91 | $RejectAll = $false 92 | $ConfirmAll = $false 93 | } 94 | process 95 | { 96 | if($PSCmdlet.ParameterSetName -eq 'ReverseLog') 97 | { 98 | 99 | $ToChange = Import-Csv -Path $LogFile 100 | foreach($Change in $ToChange){ 101 | if(-not $Change.'Group') 102 | { 103 | Write-Warning "Skipping [$Change]: No Group specified" 104 | continue 105 | } 106 | if(-not $Change.'Account') 107 | { 108 | Write-Warning "Skipping [$Change]: No Account specified" 109 | continue 110 | } 111 | if('Add', 'Remove' -notcontains $Change.'Action') 112 | { 113 | Write-Warning "Skipping [$Change]: No valid Action specified" 114 | continue 115 | } 116 | if($Change.Action -eq 'Add') {$Change.Action = 'Remove'} 117 | if($Change.Action -eq 'Remove') {$Change.Action = 'Add'} 118 | } 119 | } 120 | else 121 | { 122 | $ToProcess = [System.Collections.ArrayList]@() 123 | if($PSCmdlet.ParameterSetName -eq 'file') 124 | { 125 | foreach($File in $Path) 126 | { 127 | $ToProcess.AddRange( @(Get-Content $File -Raw) ) 128 | } 129 | } 130 | else 131 | { 132 | [void]$ToProcess.Add($InputObject) 133 | } 134 | Write-Verbose ($ToProcess | Out-String) 135 | $ToExpand = $ToProcess | Get-ADDynamicGroup 136 | $ToChange = Expand-ADDynamicGroup -InputObject $ToExpand 137 | } 138 | foreach($Change in $ToChange) 139 | { 140 | $Todo = "[{0}] [{1}] to/from [{2}]" -f $Change.Action, $Change.Account, $Change.Group 141 | if($PSCmdlet.ShouldProcess( "Group changed '$Todo'", "Group change '$Todo'?", "Changing group membership" )) 142 | { 143 | if($Force -or $PSCmdlet.ShouldContinue("Are you REALLY sure you want to change '$Todo'?", "Removing '$Todo'", [ref]$ConfirmAll, [ref]$RejectAll)) 144 | { 145 | Try 146 | { 147 | $Status = 'Success' 148 | switch ($Change.Action) 149 | { 150 | 'Add' { 151 | Add-ADGroupMember -Identity $Change.Group -Members $Change.Account -ErrorAction Stop 152 | } 153 | 'Remove' { 154 | Remove-ADGroupMember -Identity $Change.Group -Members $Change.Account -ErrorAction Stop 155 | } 156 | } 157 | } 158 | catch 159 | { 160 | $Status = "Error: $_" 161 | Write-Warning $_ 162 | } 163 | finally 164 | { 165 | $Change | Select *, @{label='Status';expression={ $Status}} | Export-CSV -Path $LogFile -NoTypeInformation -Append -Force 166 | } 167 | } 168 | } 169 | } 170 | } 171 | } -------------------------------------------------------------------------------- /ADGrouper/en-US/about_ADGrouper.help.txt: -------------------------------------------------------------------------------- 1 | TOPIC 2 | about_ADGrouper 3 | 4 | SHORT DESCRIPTION 5 | ADGrouper helps create dynamic AD security group membership via yaml 6 | 7 | DETAILED DESCRIPTION 8 | ADGrouper helps create dynamic AD security group membership via yaml 9 | 10 | Certain solutions don't support nested security groups, 11 | or perform better without nested security groups. 12 | ADGrouper allows you to define expected group membership 13 | based on groups or users to include, recursion, LDAP queries, and more. 14 | 15 | Schema 16 | ====== 17 | 18 | ADGrouper uses yaml. We read yaml files with the following expected syntax: 19 | 20 | 'Target Group': # Target security group we are populating 21 | Purge: # Whether to remove existing accounts in the groupthat aren't included in this definition. Defaults to false 22 | Recurse: # Whether to recurse membership when source is a group. Defaults to true 23 | Expand: # Whether to expand to individual accounts within the group, or use the group explicitly. Defaults to true 24 | Exclude: # Accounts to exclude from this group 25 | BadUser: # Exclude account 26 | BadGroup: # Exclude account with overriden Recurse 27 | - Recurse: False 28 | ExcludeQuery: # One or more LDAP queries whose resulting accounts are excluded from the target group 29 | - '(b=a)' 30 | Include: # Accounts to include in this group 31 | GoodGroup: # Include account with global settings 32 | GoodGroup2: # Include account with overriden Expand and Recurse 33 | - Expand: False 34 | - Recurse: False 35 | IncludeQuery: # One or more LDAP queries whose resulting accounts are included in the target group 36 | - '(a=b)' 37 | - '(c=d)' 38 | 39 | Example 40 | ======= 41 | 42 | AD contains the following groups: 43 | * TargetGroup 44 | * ManualAccount1 45 | * Account1 46 | * AccountX 47 | * SourceGroup1 48 | * Account1 49 | * Account2 50 | * Account3 51 | * SourceGroup2 52 | * AccountX 53 | * SourceGroupRaw 54 | * RestrictedUsers 55 | * Account2 56 | 57 | We want... 58 | * TargetGroup to include anyone who is ever added to SourceGroup1 and SourceGroup2 59 | * To ensure no users from RestrictedUsers are in TargetGroup 60 | * To add SourceGroupRaw to TargetGroup as a nested group 61 | * To remove any accounts manually added to TargetGroup (i.e. mirror/purge) 62 | * Given the above... This means: 63 | * Removing ManualAccount1 from TargetGroup (purge, and account is not in any include definition) 64 | * Adding Account3 to TargetGroup (in SourceGroup1, not in TargetGroup) 65 | * Adding SourceGroupRaw to TargetGroup (set to not expand, not in TargetGroup) 66 | 67 | Yaml to accomplish this: 68 | 69 | TargetGroup: 70 | Purge: True 71 | Exclude: 72 | RestrictedUsers: 73 | Include: 74 | SourceGroup1: 75 | SourceGroup2: 76 | SourceGroupRaw: 77 | Expand: False 78 | 79 | Here's how we do this in PowerShell: 80 | 81 | # Assuming example yaml has content above 82 | # Review info before querying AD: 83 | Get-ADDynamicGroup \\Path\To\Example.yaml 84 | 85 | TargetGroup : TargetGroup 86 | Recurse : True 87 | Purge : True 88 | Expand : True 89 | IncludeQuery : 90 | Include : {@{Account=SourceGroup1; Recurse=True; Purge=True; Expand=True}, 91 | @{Account=SourceGroup2; Recurse=True; Purge=True; Expand=True}, 92 | @{Account=SourceGroupRaw; Recurse=True; Purge=True; Expand=False}} 93 | Exclude : @{Account=RestrictedUsers; Recurse=True; Purge=True; Expand=True} 94 | ExcludeQuery : 95 | 96 | # Now, let's see what would actually change 97 | $Yaml | Get-ADDynamicGroup | Expand-ADDynamicGroup 98 | 99 | Group : TargetGroup 100 | Account : ManualAccount1 101 | Action : Remove 102 | Type : 103 | 104 | Group : TargetGroup 105 | Account : Account3 106 | Action : Add 107 | Type : 108 | 109 | Group : TargetGroup 110 | Account : SourceGroupRaw 111 | Action : Add 112 | Type : 113 | 114 | # Perfect, this is exactly what I want! Let's whatif, just in case. 115 | $Yaml | Invoke-ADGrouper -WhatIf 116 | 117 | What if: Group changed '[Remove] [ManualAccount1] to/from [TargetGroup]' 118 | What if: Group changed '[Add] [Account3] to/from [TargetGroup]' 119 | What if: Group changed '[Add] [SourceGroupRaw] to/from [TargetGroup]' 120 | 121 | # Let's make the change! You might schedule this to run on some interval 122 | # In case it isn't obvious, keep your yaml files very secure, and use source control : ) 123 | $Yaml | Invoke-ADGrouper -Confirm:$False -Force 124 | 125 | # And did it work? 126 | Get-ADGroupMember TargetGroup | Select -ExpandProperty SamAccountName 127 | 128 | SourceGroupRaw 129 | Account1 130 | Account3 131 | AccountX 132 | 133 | # Perfect! 134 | 135 | SEE ALSO 136 | https://github.com/RamblingCookieMonster/ADGrouper -------------------------------------------------------------------------------- /Build/Start-Build.ps1: -------------------------------------------------------------------------------- 1 | param( 2 | $Task = 'Default' 3 | ) 4 | 5 | # dependencies 6 | Get-PackageProvider -Name NuGet -ForceBootstrap | Out-Null 7 | if(-not (Get-Module -ListAvailable PSDepend)) 8 | { 9 | & (Resolve-Path "$PSScriptRoot\helpers\Install-PSDepend.ps1") 10 | } 11 | Import-Module PSDepend 12 | $null = Invoke-PSDepend -Path "$PSScriptRoot\build.requirements.psd1" -Install -Import -Force 13 | 14 | Set-BuildEnvironment 15 | 16 | Invoke-psake $PSScriptRoot\psake.ps1 -taskList $Task -nologo 17 | exit ( [int]( -not $psake.build_success ) ) -------------------------------------------------------------------------------- /Build/build.requirements.psd1: -------------------------------------------------------------------------------- 1 | @{ 2 | # Some defaults for all dependencies 3 | PSDependOptions = @{ 4 | Target = '$ENV:USERPROFILE\Documents\WindowsPowerShell\Modules' 5 | AddToPath = $True 6 | } 7 | 8 | # Grab some modules without depending on PowerShellGet 9 | 'psake' = @{ DependencyType = 'PSGalleryNuget' } 10 | 'PSDeploy' = @{ DependencyType = 'PSGalleryNuget' } 11 | 'BuildHelpers' = @{ DependencyType = 'PSGalleryNuget' } 12 | 'Pester' = @{ DependencyType = 'PSGalleryNuget' } 13 | } -------------------------------------------------------------------------------- /Build/deploy.psdeploy.ps1: -------------------------------------------------------------------------------- 1 | # Generic module deployment. 2 | # 3 | # ASSUMPTIONS: 4 | # 5 | # * folder structure either like: 6 | # 7 | # - RepoFolder 8 | # - This PSDeploy file 9 | # - ModuleName 10 | # - ModuleName.psd1 11 | # 12 | # OR the less preferable: 13 | # - RepoFolder 14 | # - RepoFolder.psd1 15 | # 16 | # * Nuget key in $ENV:NugetApiKey 17 | # 18 | # * Set-BuildEnvironment from BuildHelpers module has populated ENV:BHPSModulePath and related variables 19 | 20 | # Publish to gallery with a few restrictions 21 | if( 22 | $env:BHPSModulePath -and 23 | $env:BHBuildSystem -ne 'Unknown' -and 24 | $env:BHBranchName -eq "master" -and 25 | $env:BHCommitMessage -match '!deploy' 26 | ) 27 | { 28 | Deploy Module { 29 | By PSGalleryModule { 30 | FromSource $ENV:BHPSModulePath 31 | To PSGallery 32 | WithOptions @{ 33 | ApiKey = $ENV:NugetApiKey 34 | } 35 | } 36 | } 37 | } 38 | else 39 | { 40 | "Skipping deployment: To deploy, ensure that...`n" + 41 | "`t* You are in a known build system (Current: $ENV:BHBuildSystem)`n" + 42 | "`t* You are committing to the master branch (Current: $ENV:BHBranchName) `n" + 43 | "`t* Your commit message includes !deploy (Current: $ENV:BHCommitMessage)" | 44 | Write-Host 45 | } 46 | 47 | # Publish to AppVeyor if we're in AppVeyor 48 | if( 49 | $env:BHPSModulePath -and 50 | $env:BHBuildSystem -eq 'AppVeyor' 51 | ) 52 | { 53 | Deploy DeveloperBuild { 54 | By AppVeyorModule { 55 | FromSource $ENV:BHPSModulePath 56 | To AppVeyor 57 | WithOptions @{ 58 | Version = $env:APPVEYOR_BUILD_VERSION 59 | } 60 | } 61 | } 62 | } -------------------------------------------------------------------------------- /Build/helpers/Install-PSDepend.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Bootstrap PSDepend 4 | 5 | .DESCRIPTION 6 | Bootstrap PSDepend 7 | 8 | Why? No reliance on PowerShellGallery 9 | 10 | * Downloads nuget to your ~\ home directory 11 | * Creates $Path (and full path to it) 12 | * Downloads module to $Path\PSDepend 13 | * Moves nuget.exe to $Path\PSDepend (skips nuget bootstrap on initial PSDepend import) 14 | 15 | .PARAMETER Path 16 | Module path to install PSDepend 17 | 18 | Defaults to Profile\Documents\WindowsPowerShell\Modules 19 | 20 | .EXAMPLE 21 | .\Install-PSDepend.ps1 -Path C:\Modules 22 | 23 | # Installs to C:\Modules\PSDepend 24 | #> 25 | [cmdletbinding()] 26 | param( 27 | [string]$Path = $( Join-Path ([Environment]::GetFolderPath('MyDocuments')) 'WindowsPowerShell\Modules') 28 | ) 29 | $ExistingProgressPreference = "$ProgressPreference" 30 | $ProgressPreference = 'SilentlyContinue' 31 | try { 32 | # Bootstrap nuget if we don't have it 33 | if(-not ($NugetPath = (Get-Command 'nuget.exe' -ErrorAction SilentlyContinue).Path)) { 34 | $NugetPath = Join-Path $ENV:USERPROFILE nuget.exe 35 | if(-not (Test-Path $NugetPath)) { 36 | Invoke-WebRequest -uri 'https://dist.nuget.org/win-x86-commandline/latest/nuget.exe' -OutFile $NugetPath 37 | } 38 | } 39 | 40 | # Bootstrap PSDepend, re-use nuget.exe for the module 41 | if($path) { $null = mkdir $path -Force } 42 | $NugetParams = 'install', 'PSDepend', '-Source', 'https://www.powershellgallery.com/api/v2/', 43 | '-ExcludeVersion', '-NonInteractive', '-OutputDirectory', $Path 44 | & $NugetPath @NugetParams 45 | Move-Item -Path $NugetPath -Destination "$(Join-Path $Path PSDepend)\nuget.exe" -Force 46 | } 47 | finally { 48 | $ProgressPreference = $ExistingProgressPreference 49 | } -------------------------------------------------------------------------------- /Build/psake.ps1: -------------------------------------------------------------------------------- 1 | # PSake makes variables declared here available in other scriptblocks 2 | # Init some things 3 | Properties { 4 | # Find the build folder based on build system 5 | $ProjectRoot = $ENV:BHProjectPath 6 | if(-not $ProjectRoot) 7 | { 8 | $ProjectRoot = Resolve-Path "$PSScriptRoot\.." 9 | } 10 | 11 | $Timestamp = Get-Date -UFormat "%Y%m%d-%H%M%S" 12 | $PSVersion = $PSVersionTable.PSVersion.Major 13 | $TestFile = "TestResults_PS$PSVersion`_$TimeStamp.xml" 14 | $lines = '----------------------------------------------------------------------' 15 | 16 | $Verbose = @{} 17 | if($ENV:BHCommitMessage -match "!verbose") 18 | { 19 | $Verbose = @{Verbose = $True} 20 | } 21 | } 22 | 23 | Task Default -Depends Test 24 | 25 | Task Init { 26 | $lines 27 | Set-Location $ProjectRoot 28 | "Build System Details:" 29 | Get-Item ENV:BH* 30 | "`n" 31 | } 32 | 33 | Task Test -Depends Init { 34 | $lines 35 | "`n`tSTATUS: Testing with PowerShell $PSVersion" 36 | 37 | # Gather test results. Store them in a variable and file 38 | $TestResults = Invoke-Pester -Path $ProjectRoot\Tests -PassThru -OutputFormat NUnitXml -OutputFile "$ProjectRoot\$TestFile" 39 | 40 | # In Appveyor? Upload our tests! #Abstract this into a function? 41 | If($ENV:BHBuildSystem -eq 'AppVeyor') 42 | { 43 | (New-Object 'System.Net.WebClient').UploadFile( 44 | "https://ci.appveyor.com/api/testresults/nunit/$($env:APPVEYOR_JOB_ID)", 45 | "$ProjectRoot\$TestFile" ) 46 | } 47 | 48 | Remove-Item "$ProjectRoot\$TestFile" -Force -ErrorAction SilentlyContinue 49 | 50 | # Failed tests? 51 | # Need to tell psake or it will proceed to the deployment. Danger! 52 | if($TestResults.FailedCount -gt 0) 53 | { 54 | Write-Error "Failed '$($TestResults.FailedCount)' tests, build failed" 55 | } 56 | "`n" 57 | } 58 | 59 | Task Build -Depends Test { 60 | $lines 61 | 62 | # Load the module, read the exported functions, update the psd1 FunctionsToExport 63 | Set-ModuleFunctions 64 | 65 | # Bump the module version 66 | Try 67 | { 68 | $Version = Get-NextPSGalleryVersion -Name $env:BHProjectName -ErrorAction Stop 69 | Update-Metadata -Path $env:BHPSModuleManifest -PropertyName ModuleVersion -Value $Version -ErrorAction stop 70 | } 71 | Catch 72 | { 73 | "Failed to update version for '$env:BHProjectName': $_.`nContinuing with existing version" 74 | } 75 | } 76 | 77 | Task Deploy -Depends Build { 78 | $lines 79 | 80 | $Params = @{ 81 | Path = "$ProjectRoot\Build" 82 | Force = $true 83 | Recurse = $false # We keep psdeploy artifacts, avoid deploying those : ) 84 | } 85 | Invoke-PSDeploy @Verbose @Params 86 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Warren Frame 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ADGrouper 2 | 3 | This is a module to define and populate dynamic AD security groups based on a yaml config file. 4 | 5 | Certain solutions don't support nested security groups, or perform better without nested security groups. ADGrouper allows you to define expected group membership based on groups or users to include, recursion, LDAP queries, and more. 6 | 7 | This is a work in progress; it's not fully featured or tested, and there may be breaking changes. Silly blog post pending. 8 | 9 | Pull requests and other contributions would be welcome! 10 | 11 | ## Instructions 12 | 13 | ```powershell 14 | # Install with PowerShell 5 or PowerShellGet module 15 | Install-Module ADGrouper 16 | 17 | # Instaell via GitHub 18 | # Download the repository 19 | # Unblock the zip 20 | # Extract the ADGrouper folder to a module path (e.g. $env:USERPROFILE\Documents\WindowsPowerShell\Modules\) 21 | 22 | # Import the module. 23 | Import-Module ADGrouper 24 | #Alternatively, Import-Module \\Path\To\ADGrouper 25 | 26 | # Get commands in the module 27 | Get-Command -Module ADGrouper 28 | 29 | # Get help 30 | Get-Help Invoke-ADGrouper -Full 31 | Get-Help about_ADGrouper 32 | ``` 33 | 34 | ### Prerequisites 35 | 36 | * PowerShell 3 or later 37 | * ActiveDirectory module ([#1](https://github.com/RamblingCookieMonster/ADGrouper/issues/1)) 38 | * Target groups already exist ([#4](https://github.com/RamblingCookieMonster/ADGrouper/issues/4)) 39 | * These yaml files are locked down, ideally in source control, and your team members know which groups are affected (maybe they have a clear OU or description) 40 | 41 | ## ADGrouper Yaml Schema 42 | 43 | ADGrouper uses yaml. We read yaml files with the following expected syntax: 44 | 45 | ```yaml 46 | 'Target Group': # Target security group we are populating 47 | Purge: # Whether to remove existing accounts in the groupthat aren't included in this definition. Defaults to false 48 | Recurse: # Whether to recurse membership when source is a group. Defaults to true 49 | Expand: # Whether to expand to individual accounts within the group, or use the group explicitly. Defaults to true 50 | Exclude: # Accounts to exclude from this group 51 | BadUser: # Exclude account 52 | BadGroup: # Exclude account with overriden Recurse 53 | - Recurse: False 54 | ExcludeQuery: # One or more LDAP queries whose resulting accounts are excluded from the target group 55 | - '(b=a)' 56 | Include: # Accounts to include in this group 57 | GoodGroup: # Include account with global settings 58 | GoodGroup2: # Include account with overriden Expand and Recurse 59 | - Expand: False 60 | - Recurse: False 61 | IncludeQuery: # One or more LDAP queries whose resulting accounts are included in the target group 62 | - '(a=b)' 63 | - '(c=d)' 64 | ``` 65 | 66 | ## Example 67 | 68 | Here are some groups and their users that we have in AD: 69 | 70 | * TargetGroup 71 | * ManualAccount1 72 | * Account1 73 | * AccountX 74 | * SourceGroup1 75 | * Account1 76 | * Account2 77 | * Account3 78 | * SourceGroup2 79 | * AccountX 80 | * SourceGroupRaw 81 | * RestrictedUsers 82 | * Account2 83 | 84 | And here's what we actually want: 85 | 86 | * TargetGroup to include anyone who is ever added to SourceGroup1 and SourceGroup2 87 | * To ensure no users from RestrictedUsers are in TargetGroup 88 | * To add SourceGroupRaw to TargetGroup as a nested group 89 | * To remove any accounts manually added to TargetGroup (i.e. mirror/purge) 90 | 91 | So! Here's what we want to actually happen: 92 | 93 | * Remove ManualAccount1 from TargetGroup (purge, and account is not in any include definition) 94 | * Add Account3 to TargetGroup (in SourceGroup1, not in TargetGroup) 95 | * Add SourceGroupRaw to TargetGroup (set to not expand, not in TargetGroup) 96 | 97 | Here's some yaml we'll use to accomplish this: 98 | 99 | ```yaml 100 | TargetGroup: 101 | Purge: True 102 | Exclude: 103 | RestrictedUsers: 104 | Include: 105 | SourceGroup1: 106 | SourceGroup2: 107 | SourceGroupRaw: 108 | Expand: False 109 | ``` 110 | 111 | Let's see how this works! 112 | 113 | ```powershell 114 | # Assuming example yaml has content above 115 | # Review info before querying AD: 116 | Get-ADDynamicGroup \\Path\To\Example.yaml 117 | 118 | # TargetGroup : TargetGroup 119 | # Recurse : True 120 | # Purge : True 121 | # Expand : True 122 | # IncludeQuery : 123 | # Include : {@{Account=SourceGroup1; Recurse=True; Purge=True; Expand=True}, 124 | # @{Account=SourceGroup2; Recurse=True; Purge=True; Expand=True}, 125 | # @{Account=SourceGroupRaw; Recurse=True; Purge=True; Expand=False}} 126 | # Exclude : @{Account=RestrictedUsers; Recurse=True; Purge=True; Expand=True} 127 | # ExcludeQuery : 128 | 129 | # Now, let's see what would actually change 130 | $Yaml | Get-ADDynamicGroup | Expand-ADDynamicGroup 131 | 132 | # Group : TargetGroup 133 | # Account : ManualAccount1 134 | # Action : Remove 135 | # Type : 136 | 137 | # Group : TargetGroup 138 | # Account : Account3 139 | # Action : Add 140 | # Type : 141 | 142 | # Group : TargetGroup 143 | # Account : SourceGroupRaw 144 | # Action : Add 145 | # Type : 146 | 147 | # Perfect, this is exactly what I want! Let's whatif, just in case. 148 | $Yaml | Invoke-ADGrouper -WhatIf 149 | 150 | # What if: Group changed '[Remove] [ManualAccount1] to/from [TargetGroup]' 151 | # What if: Group changed '[Add] [Account3] to/from [TargetGroup]' 152 | # What if: Group changed '[Add] [SourceGroupRaw] to/from [TargetGroup]' 153 | 154 | # Let's make the change! You might schedule this to run on some interval 155 | # In case it isn't obvious, keep your yaml files very secure, and use source control : ) 156 | $Yaml | Invoke-ADGrouper -Confirm:$False -Force 157 | 158 | # And did it work? 159 | Get-ADGroupMember TargetGroup | Select -ExpandProperty SamAccountName 160 | 161 | # SourceGroupRaw 162 | # Account1 163 | # Account3 164 | # AccountX 165 | 166 | # Yep! 167 | ``` 168 | 169 | ## Notes 170 | 171 | A huge thanks to cloudbase for open sourcing their [PowerShell-Yaml module](https://github.com/cloudbase/powershell-yaml). This is the only yaml module that (1) is in the PowerShell Gallery, and (2) converts to and from yaml. 172 | -------------------------------------------------------------------------------- /Tests/ADGrouper.Tests.ps1: -------------------------------------------------------------------------------- 1 | $PSVersion = $PSVersionTable.PSVersion.Major 2 | if(-not $ENV:BHProjectPath) 3 | { 4 | Set-BuildEnvironment -Path $PSScriptRoot\.. 5 | } 6 | Remove-Module $ENV:BHProjectName -ErrorAction SilentlyContinue 7 | Import-Module (Join-Path $ENV:BHProjectPath $ENV:BHProjectName) -Force 8 | 9 | # Verbose output for non-master builds on appveyor 10 | # Handy for troubleshooting. 11 | # Splat @Verbose against commands as needed (here or in pester tests) 12 | $Verbose = @{} 13 | if($ENV:BHBranchName -notlike "master" -or $env:BHCommitMessage -match "!verbose") 14 | { 15 | $Verbose.add("Verbose",$True) 16 | } 17 | 18 | Describe "$ModuleName PS$PSVersion" { 19 | Context 'Strict mode' { 20 | 21 | Set-StrictMode -Version latest 22 | 23 | It 'Should load' { 24 | $Module = Get-Module $ENV:BHProjectName 25 | $Module.Name | Should be $ENV:BHProjectName 26 | $Module.ExportedCommands.Keys -contains 'Invoke-ADGrouper' | Should Be $True 27 | } 28 | } 29 | } 30 | 31 | Describe "Get-ADDynamicGroup PS$PSVersion" { 32 | 33 | It 'Should parse a simple yaml file with expected defaults' { 34 | $Simple = Get-ADDynamicGroup -Path (Join-Path $ENV:BHProjectPath 'Tests/Data/simple.yaml') 35 | $Simple.TargetGroup | Should Be 'target_group' 36 | $Simple.Recurse | Should Be $True 37 | $Simple.Purge | Should Be $False 38 | $Simple.Expand | Should Be $True 39 | $Simple.IncludeQuery | Should Be '(a=b)' 40 | $Simple.ExcludeQuery | Should Be '(b=a)' 41 | $Simple.Exclude.Account | Should Be 'bad_account' 42 | $Simple.Include.Account -Contains 'source group' | should be $True 43 | $Simple.Include.Account -Contains 'good_account' | should be $True 44 | $include = $Simple.Include | Where {$_.Account -eq 'source group'} 45 | $include.Recurse | Should Be $True 46 | $include.Purge | Should Be $False 47 | $include.Expand | Should Be $True 48 | } 49 | 50 | It 'Should allow overrides of options' { 51 | $override = Get-ADDynamicGroup -Path (Join-Path $ENV:BHProjectPath 'Tests/Data/override.yaml') 52 | $override.TargetGroup | Should Be 'target_group2' 53 | $override.Recurse | Should Be $False 54 | $override.Purge | Should Be $True 55 | $override.Expand | Should Be $False 56 | $override.IncludeQuery | Should Be '(c=d)' 57 | $override.ExcludeQuery | Should Be '(d=c)' 58 | $override.Exclude.Account | Should Be 'bad_account2' 59 | $override.Include.Account -Contains 'source group2' | should be $True 60 | $override.Include.Account -Contains 'source group3' | should be $True 61 | $override.Include.Account -Contains 'good_account2' | should be $True 62 | $includeoverride = $override.Include | Where {$_.Account -eq 'source group2'} 63 | $includeoverride.Recurse | Should Be $True 64 | $includeoverride.Purge | Should Be $False 65 | $includeoverride.Expand | Should Be $True 66 | $includeglobal = $override.Include | Where {$_.Account -eq 'source group3'} 67 | $includeglobal.Recurse | Should Be $False 68 | $includeglobal.Purge | Should Be $True 69 | $includeglobal.Expand | Should Be $False 70 | } 71 | 72 | It "Should handle multiple files" { 73 | $Files = (Join-Path $ENV:BHProjectPath 'Tests/Data/simple.yaml'), 74 | (Join-Path $ENV:BHProjectPath 'Tests/Data/override.yaml') 75 | $multiple = Get-ADDynamicGroup -Path $Files 76 | $multiple.count | Should Be 2 77 | 78 | $simple = $multiple | Where {$_.targetgroup -like 'target_group'} 79 | $Simple.TargetGroup | Should Be 'target_group' 80 | $Simple.Recurse | Should Be $True 81 | $Simple.Purge | Should Be $False 82 | $Simple.Expand | Should Be $True 83 | $Simple.IncludeQuery | Should Be '(a=b)' 84 | $Simple.ExcludeQuery | Should Be '(b=a)' 85 | $Simple.Exclude.Account | Should Be 'bad_account' 86 | $Simple.Include.Account -Contains 'source group' | should be $True 87 | $Simple.Include.Account -Contains 'good_account' | should be $True 88 | $include = $Simple.Include | Where {$_.Account -eq 'source group'} 89 | $include.Recurse | Should Be $True 90 | $include.Purge | Should Be $False 91 | $include.Expand | Should Be $True 92 | 93 | $override = $multiple | Where {$_.targetgroup -like 'target_group2'} 94 | $override.TargetGroup | Should Be 'target_group2' 95 | $override.Recurse | Should Be $False 96 | $override.Purge | Should Be $True 97 | $override.Expand | Should Be $False 98 | $override.IncludeQuery | Should Be '(c=d)' 99 | $override.ExcludeQuery | Should Be '(d=c)' 100 | $override.Exclude.Account | Should Be 'bad_account2' 101 | $override.Include.Account -Contains 'source group2' | should be $True 102 | $override.Include.Account -Contains 'source group3' | should be $True 103 | $override.Include.Account -Contains 'good_account2' | should be $True 104 | $includeoverride = $override.Include | Where {$_.Account -eq 'source group2'} 105 | $includeoverride.Recurse | Should Be $True 106 | $includeoverride.Purge | Should Be $False 107 | $includeoverride.Expand | Should Be $True 108 | $includeglobal = $override.Include | Where {$_.Account -eq 'source group3'} 109 | $includeglobal.Recurse | Should Be $False 110 | $includeglobal.Purge | Should Be $True 111 | $includeglobal.Expand | Should Be $False 112 | 113 | } 114 | 115 | It 'Supports yaml input' { 116 | $Files = (Join-Path $ENV:BHProjectPath 'Tests/Data/simple.yaml'), 117 | (Join-Path $ENV:BHProjectPath 'Tests/Data/override.yaml') 118 | $multiple = $Files | Foreach {Get-Content $_ -Raw} | Get-ADDynamicGroup 119 | $multiple.count | Should Be 2 120 | 121 | $simple = $multiple | Where {$_.targetgroup -like 'target_group'} 122 | $Simple.TargetGroup | Should Be 'target_group' 123 | $Simple.Recurse | Should Be $True 124 | $Simple.Purge | Should Be $False 125 | $Simple.Expand | Should Be $True 126 | $Simple.IncludeQuery | Should Be '(a=b)' 127 | $Simple.ExcludeQuery | Should Be '(b=a)' 128 | $Simple.Exclude.Account | Should Be 'bad_account' 129 | $Simple.Include.Account -Contains 'source group' | should be $True 130 | $Simple.Include.Account -Contains 'good_account' | should be $True 131 | $include = $Simple.Include | Where {$_.Account -eq 'source group'} 132 | $include.Recurse | Should Be $True 133 | $include.Purge | Should Be $False 134 | $include.Expand | Should Be $True 135 | 136 | $override = $multiple | Where {$_.targetgroup -like 'target_group2'} 137 | $override.TargetGroup | Should Be 'target_group2' 138 | $override.Recurse | Should Be $False 139 | $override.Purge | Should Be $True 140 | $override.Expand | Should Be $False 141 | $override.IncludeQuery | Should Be '(c=d)' 142 | $override.ExcludeQuery | Should Be '(d=c)' 143 | $override.Exclude.Account | Should Be 'bad_account2' 144 | $override.Include.Account -Contains 'source group2' | should be $True 145 | $override.Include.Account -Contains 'source group3' | should be $True 146 | $override.Include.Account -Contains 'good_account2' | should be $True 147 | $includeoverride = $override.Include | Where {$_.Account -eq 'source group2'} 148 | $includeoverride.Recurse | Should Be $True 149 | $includeoverride.Purge | Should Be $False 150 | $includeoverride.Expand | Should Be $True 151 | $includeglobal = $override.Include | Where {$_.Account -eq 'source group3'} 152 | $includeglobal.Recurse | Should Be $False 153 | $includeglobal.Purge | Should Be $True 154 | $includeglobal.Expand | Should Be $False 155 | } 156 | } 157 | 158 | -------------------------------------------------------------------------------- /Tests/Data/override.yaml: -------------------------------------------------------------------------------- 1 | 'target_group2': 2 | Recurse: False 3 | Expand: False 4 | Purge: True 5 | Include: 6 | good_account2: 7 | 'source group2': 8 | Recurse: True 9 | Expand: True 10 | Purge: False 11 | 'source group3': 12 | IncludeQuery: 13 | - '(c=d)' 14 | ExcludeQuery: 15 | - '(d=c)' 16 | Exclude: 17 | - bad_account2: 18 | -------------------------------------------------------------------------------- /Tests/Data/simple.yaml: -------------------------------------------------------------------------------- 1 | 'target_group': 2 | Include: 3 | good_account: 4 | 'source group': 5 | IncludeQuery: 6 | - '(a=b)' 7 | ExcludeQuery: 8 | - '(b=a)' 9 | Exclude: 10 | bad_account: 11 | -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | # See http://www.appveyor.com/docs/appveyor-yml for many more options 2 | 3 | #Publish to PowerShell Gallery with this key 4 | environment: 5 | NuGetApiKey: 6 | secure: oqMFzG8F65K5l572V7VzlZIWU7xnSYDLtSXECJAAURrXe8M2+BAp9vHLT+1h1lR0 7 | 8 | # Allow WMF5 (i.e. PowerShellGallery functionality) 9 | os: WMF 5 10 | 11 | # Skip on updates to the readme. 12 | # We can force this by adding [skip ci] or [ci skip] anywhere in commit message 13 | skip_commits: 14 | message: /updated readme.*|update readme.*s/ 15 | 16 | build: false 17 | 18 | #Kick off the CI/CD pipeline 19 | test_script: 20 | - ps: . .\build\Start-Build.ps1 -Task Deploy --------------------------------------------------------------------------------