Last active
April 24, 2018 18:46
-
-
Save quonic/c3c696f818ae9be35ccae972e22c0455 to your computer and use it in GitHub Desktop.
AD Group assigner
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $Users = Get-ADUser | |
| $GroupData = Import-Clixml -Path ".\Groups.clixml" | |
| $GroupsToAdd = $Users | ForEach-Object { | |
| $User = $_ | |
| $Company = $GroupData.Companies | Where-Object {$_.Name -eq $User.Company} | |
| $Departments = $Company.Departments | Where-Object {$_.Name -eq $User.Department} | |
| $Departments.Groups | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # How it would be ran | |
| . .\SaveGroupData.ps1 | |
| . .\AssignGroups.ps1 | |
| $GroupsToAdd | |
| # Example with out the other scripts to show proof of concept | |
| $GroupData = @{ | |
| Companies = @( | |
| [PSCustomObject]@{ | |
| Name = "CompanyA" | |
| Departments = @( | |
| [PSCustomObject]@{ | |
| Name = "DepartmentA" | |
| Groups = @("Group1", "Group2") | |
| }, [PSCustomObject]@{ | |
| Name = "DepartmentB" | |
| Groups = @("Group3", "Group4") | |
| } | |
| , [PSCustomObject]@{ | |
| Name = "DepartmentB" | |
| Groups = @("Group1", "Group3") | |
| } | |
| ) | |
| }, | |
| [PSCustomObject]@{ | |
| Name = "CompanyB" | |
| Departments = @( | |
| [PSCustomObject]@{ | |
| Name = "DepartmentA" | |
| Groups = @("Group4", "Group8") | |
| }, [PSCustomObject]@{ | |
| Name = "DepartmentB" | |
| Groups = @("Group5", "Group9") | |
| } | |
| , [PSCustomObject]@{ | |
| Name = "DepartmentB" | |
| Groups = @("Group1", "Group7") | |
| } | |
| ) | |
| } | |
| ) | |
| } | |
| $Users = [PSCustomObject]@{ | |
| Name = "Spyingwind" | |
| Department = "DepartmentA" | |
| Company = "CompanyB" | |
| } | |
| $GroupsToAdd = $Users | ForEach-Object { | |
| $User = $_ | |
| $Company = $GroupData.Companies | Where-Object {$_.Name -eq $User.Company} | |
| $Departments = $Company.Departments | Where-Object {$_.Name -eq $User.Department} | |
| $Departments.Groups | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $Groups = Get-ADGroup | |
| $GroupData = @{ | |
| Companies = @( | |
| [PSCustomObject]@{ | |
| Name = "CompanyA" | |
| Departments = @( | |
| [PSCustomObject]@{ | |
| Name = "DepartmentA" | |
| Groups = $Groups | Where-Object {$_.Name -in @("Group1", "Group2")} | |
| }, [PSCustomObject]@{ | |
| Name = "DepartmentB" | |
| Groups = $Groups | Where-Object {$_.Name -in @("Group3", "Group4")} | |
| } | |
| , [PSCustomObject]@{ | |
| Name = "DepartmentB" | |
| Groups = $Groups | Where-Object {$_.Name -in @("Group1", "Group3")} | |
| } | |
| ) | |
| }, | |
| [PSCustomObject]@{ | |
| Name = "CompanyB" | |
| Departments = @( | |
| [PSCustomObject]@{ | |
| Name = "DepartmentA" | |
| Groups = $Groups | Where-Object {$_.Name -in @("Group4", "Group8")} | |
| }, [PSCustomObject]@{ | |
| Name = "DepartmentB" | |
| Groups = $Groups | Where-Object {$_.Name -in @("Group5", "Group9")} | |
| } | |
| , [PSCustomObject]@{ | |
| Name = "DepartmentB" | |
| Groups = $Groups | Where-Object {$_.Name -in @("Group1", "Group7")} | |
| } | |
| ) | |
| } | |
| ) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $Data = . .\GetMyGroups.ps1 | |
| $Data | Export-Clixml -Path ".\Groups.clixml" -Force |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment