Create a gist now

Instantly share code, notes, and snippets.

Embed
Search MIM Service via the Lithnet MIM Rest API and PowerShell
# Creds
$Username = "domain\user"
$Password = 'P@$$w0rd123'
$site_auth = "$($Username):$($Password)"
# Encode for Basic Authorization
$site_Bytes = [System.Text.Encoding]::utf8.GetBytes($site_auth)
$Site_EncodedAuth=[Convert]::ToBase64String($site_Bytes)
# Server URI
$uri = "https://mimdev.mydomain.com/v2/resources/"
# Search Query. Get all Person Objects
$objType = '?objectType=Person'
# Handle Self Sign Cert
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
# Search
$response = Invoke-WebRequest -Uri ($uri+$objType) -Method Get -Headers @{Authorization = "Basic $Site_EncodedAuth"} -ContentType "application/json"
$users = $response.Content | ConvertFrom-Json
$users.Results
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment