Last active
November 17, 2016 19:31
-
-
Save darrenjrobinson/66192d26abe62d1d3d0ef577bb3dac40 to your computer and use it in GitHub Desktop.
This file contains 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
$in = Get-Content $req -Raw | ConvertFrom-Json | |
$in.objecttype | |
$in.attribute | |
$in.attributevalue | |
$in.set | |
# Import the Lithnet Resource Management Powershell Module | |
import-module 'D:\home\site\wwwroot\MIMMetaverseSearch\bin\LithnetRMA\1.0.6088\LithnetRMA.psd1' | |
# Username for connection to MIM Service via Function Application Settings | |
$username = $env:MIMServiceCredUser | |
# Password for connection to MIM Service via Function Application Settings | |
$pw = $env:MIMServiceCredPassword | |
# Credentials password (encrypted) | |
$keypath = 'D:\home\site\wwwroot\MIMFunction\bin\Keys\MyPassKey.key' | |
$password = $pw | ConvertTo-SecureString -key (Get-Content $keypath) | |
# Created PS Creds | |
$credentials = New-Object System.Management.Automation.PSCredential $Username,$password | |
# Connect to the FIM Sync Server | |
# Will require an inbound rule for TCP 5786 (or your MIM Sync Firewall) in you Resource Group Network Security Group Config | |
$options = New-PsSessionOption –SkipCACheck -SkipCNCheck | |
# Setup scriptblock | |
$scriptblock = {param($o,$a,$v) get-mvobject -ObjectType $o $a $v } | |
# Connect to MIM Sync Server and execute the query | |
$results = Invoke-Command $scriptblock -computer mymimsync.westus.cloudapp.azure.com -useSSL -credential $credentials -SessionOption $options -argumentlist $in.objecttype,$in.attribute,$in.attributevalue | |
# how many did we find ? | |
$results.count | |
# Connect to the FIM service instance | |
# Will require an inbound rule for TCP 5725 (or your MIM Service Server Port) in you Resource Group Network Security Group Config | |
Set-ResourceManagementClient -BaseAddress http://mymimportal.westus.cloudapp.azure.com:5725 -Credentials $credentials | |
# Get the Set if it exists otherwise create it based on the Set name from the input | |
Try { | |
$set = Get-Resource -ObjectType Set DisplayName $in.set | |
} | |
catch { | |
$set = New-Resource -ObjectType Set | |
$set.DisplayName = $in.set | |
Save-Resource $set | |
} | |
# Get the Set so we can update the membership | |
$set = Get-Resource -ObjectType Set DisplayName $in.set | |
# Get the list of the users loginID's from the Metaverse based on the results from the query | |
$users = @() | |
$results | foreach { | |
$user = $_ | |
$users += $user.Attributes.uid | |
} | |
$users = $users.Replace("uid:","") | |
# Add the users to the Set after getting their ObjectID from the MIM Service | |
$users | foreach { | |
[string]$user = $_ | |
$user | |
$object = Get-Resource -ObjectType Person AccountName $user | |
$objectID = $object.ObjectID | |
$set.ExplicitMember += $objectID.Value | |
} | |
Save-Resource $set | |
# Return the members added to the set | |
Out-File -Encoding Ascii -FilePath $res -inputObject $users |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment