Workspace-Guru

ADGroupstoFilters

Mar 1st, 2018
1,164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <#  
  2.     .NOTES
  3.     ===========================================================================
  4.      Created on:    1-3-2018
  5.      Created by:    Chris Twiest
  6.      Organization:  Workspace-Guru.com      
  7.     ===========================================================================
  8.     .DESCRIPTION
  9.     This script will create JSON files for LiquidWare ProfileUnity Filter Management.
  10.     You fill in a base OU and the script will get all security groups in this OU.
  11.     For each security group in the OU it will create a JSON file.
  12.     This JSON file will contain the Condition User Group Membership filter information based on the security group.
  13.     You can then import the JSON files under Filter Management.
  14. #>
  15.  
  16.  
  17. $BaseOU = "OU=Groups,dc=Domain,dc=com"
  18. $WorkingDirectory = "C:\Temp"
  19.  
  20. import-module ActiveDirectory
  21.  
  22. $ChildGroups = Get-ADGroup -Filter * -SearchBase $baseOU
  23.                            
  24. $TestWorkingDirectory = $WorkingDirectory | Test-Path
  25.                            
  26. if ($TestWorkingDirectory -eq $False)
  27. {
  28.     New-Item -ItemType Directory -Path $WorkingDirectory
  29. }
  30.  
  31. New-Item -ItemType Directory -Path "$WorkingDirectory\Filters"
  32.  
  33. foreach ($ChildGroup in $ChildGroups) {
  34.  
  35. $ChildGroupName = $ChildGroup.Name
  36. $filename = "Group="+"$ChildGroupName"
  37. $ChildGroupSam = $ChildGroup.SamAccountName
  38.  
  39. New-Item -ItemType file -Path "$WorkingDirectory\Filters\$Filename.json"
  40.  
  41. $file = "$WorkingDirectory\Filters\$Filename.json"
  42.  
  43. $contentfile = '{
  44.  "DateExported": "2018-03-01T12:34:30.9207481Z",
  45.  "ProuVersion": "6.7.0.6422",
  46.  "Configurations": [],
  47.  "Filters": [
  48.    {
  49.      "Comments": "",
  50.      "Connections": 60,
  51.      "FilterRules": [
  52.        {
  53.          "ConditionType": 0,
  54.          "MatchType": 0,
  55.          "Value": "'
  56. $contentfile2 = $ChildGroupSam
  57. $contentfile3 = '" }
  58.      ],
  59.      "MachineClasses": 62,
  60.      "Name": "'
  61. $contentfile4 = $Filename
  62. $Contentfile5 = '",
  63.      "OperatingSystems": 4094,
  64.      "RuleAggregate": 0,
  65.      "SystemEvents": 3,
  66.      "CreatedBy": "admin",
  67.      "DateCreated": "2018-03-01T12:32:14Z",
  68.      "DateLastModified": "2018-03-01T12:34:25.535Z",
  69.      "Disabled": false,
  70.      "LastModifiedBy": "admin",
  71.      "Id": "5a97f2ce6db5560804ba9b2f"
  72.    }
  73.  ],
  74.  "PortabilityRulesets": [],
  75.  "Templates": []
  76. }'
  77.  
  78. $content = $contentfile + $contentfile2 + $contentfile3 + $contentfile4 + $Contentfile5
  79. Add-Content $file $content
  80.  
  81. }
Advertisement
Add Comment
Please, Sign In to add comment