Skip to content

Instantly share code, notes, and snippets.

@darrenjrobinson
Last active January 21, 2019 22:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save darrenjrobinson/7d65c74d22a55483c0373c18bd39ac93 to your computer and use it in GitHub Desktop.
Save darrenjrobinson/7d65c74d22a55483c0373c18bd39ac93 to your computer and use it in GitHub Desktop.
# Get the input request
$in = Get-Content $req -Raw | ConvertFrom-Json
# Username for connection to MIM Sync Server via Function Application Settings
$username = $env:MIMServiceCredUser
# Password for connection to MIM Sync Server via Function Application Settings
$pw = $env:MIMServiceCredPassword
# Credentials password (encrypted)
$keypath = 'D:\home\site\wwwroot\MyMIMSearchFunction\bin\Keys\MyMIMSyncPassKey.key'
$password = $pw | ConvertTo-SecureString -key (Get-Content $keypath)
# Create PS Creds
$credentials = New-Object System.Management.Automation.PSCredential $Username,$password
# skipping cert check as we're using a self signed cert
$options = New-PsSessionOption –SkipCACheck -SkipCNCheck
# Setup scriptblock
$scriptblock = {param($o,$a,$v) get-mvobject -ObjectType $o $a $v }
# Connect to MIM Sync Server and execure the query
$obj = Invoke-Command $scriptblock -computer mymimsyncserver.westus.cloudapp.azure.com -useSSL -credential $credentials -SessionOption $options -argumentlist $in.objecttype,$in.attribute,$in.attributevalue
# Output result
Out-File -Encoding Ascii -FilePath $res -inputObject $obj.Attributes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment