Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <#
- .NOTES
- ===========================================================================
- Created on: 18-3-2018
- Created by: Chris Twiest
- Organization: Workspace-Guru.com
- ===========================================================================
- .DESCRIPTION
- This script will read all Groups below a Base OU, then add these groups to a CSV file.
- This CSV is then imported to your LiquidWare ProfileUnity Server.
- It will then create a Filter object for every group in the CSV.
- #>
- $BaseOU = "OU=Applications,dc=COMPANY,dc=COM"
- $WorkingDirectory = "C:\Temp"
- import-module ActiveDirectory
- $ChildGroups = Get-ADGroup -Filter * -SearchBase $baseOU
- $TestWorkingDirectory = $WorkingDirectory | Test-Path
- if ($TestWorkingDirectory -eq $False)
- {
- New-Item -ItemType Directory -Path $WorkingDirectory
- }
- $TestWorkingDirectoryFilter = "$WorkingDirectory\Filters" | test-path
- if ($TestWorkingDirectoryFilter -eq $False)
- {
- New-Item -ItemType Directory -Path "$WorkingDirectory\Filters"
- }
- $CSVFile = "$WorkingDirectory\Filters\Groupfilters.csv"
- $TestCSVFile = $CSVFile | Test-Path
- if ($TestCSVFile -eq $True)
- {
- Remove-Item -Path $CSVFile -Force
- }
- foreach ($ChildGroup in $ChildGroups) {
- $ChildGroupName = $ChildGroup.Name
- $filtername = "Group="+"$ChildGroupName"
- $ChildGroupSam = $ChildGroup.SamAccountName
- #DATA CSV
- $csvtable = New-Object PSobject
- $csvtable | Add-Member -Type NoteProperty -Name Name -Value $filtername
- $csvtable | Add-Member -Type NoteProperty -Name Comments -Value "Added With PowerShell"
- $csvtable | Add-Member -Type NoteProperty -Name RuleAggregate -Value 0
- $csvtable | Add-Member -Type NoteProperty -Name FilterConditionType -Value 0
- $csvtable | Add-Member -Type NoteProperty -Name FilterMatchType -Value 0
- $csvtable | Add-Member -Type NoteProperty -Name Filtervalue -Value $ChildGroupSam
- $csvtable | Add-Member -Type NoteProperty -Name MachineClasses -Value 62
- $csvtable | Add-Member -Type NoteProperty -Name OperatingSystems -Value 4094
- $csvtable | Add-Member -Type NoteProperty -Name SystemEvents -Value 3
- $csvtable | Add-Member -Type NoteProperty -Name Connections -Value 60
- $CSVtable | Export-Csv -Append -NoTypeInformation -Path $CSVFile
- }
- function connect-ProfileUnityServer{
- ##Ignore-SSL Library Code
- add-type @"
- using System.Net;
- using System.Security.Cryptography.X509Certificates;
- public class TrustAllCertsPolicy : ICertificatePolicy {
- public bool CheckValidationResult(
- ServicePoint srvPoint, X509Certificate certificate,
- WebRequest request, int certificateProblem) {
- return true;
- }
- }
- "@
- [System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy
- ##Get Creds
- [string]$global:servername= Read-Host -Prompt 'FQDN of ProfileUnity Server Name'
- $user = Read-Host "Enter Username"
- $pass = Read-Host -assecurestring "Enter Password"
- $pass2=[Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($pass))
- #Connect to Server
- Invoke-WebRequest https://"$servername":8000/authenticate -Body "username=$user&password=$pass2" -Method Post -SessionVariable session
- $global:session=$session
- }
- Connect-ProfileUnityServer
- $lists=import-csv $CSVFile
- Foreach ($item in $lists){
- #FilterRules Hashing
- $FilterRules=@{ConditionType=$item.FilterConditionType; MatchType=$item.FilterMatchType; Value=$item.Filtervalue}
- $FilterRules=@($FilterRules)
- ##Make New FilterSettings
- $newFilter=[pscustomobject]@{
- Name=$item.Name;
- Comments=$item.Comments;
- RuleAggregate=$item.RuleAggregate;
- FilterRules=$FilterRules;
- MachineClasses=$item.MachineClasses;
- OperatingSystems=$item.OperatingSystems;
- SystemEvents=$item.SystemEvents;
- Connections=$item.Connections;
- }
- Invoke-WebRequest https://"$servername":8000/api/filter -ContentType "application/json" -Method Post -WebSession $session -Body($NewFilter | ConvertTo-Json -Depth 10)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement