Skip to content

Instantly share code, notes, and snippets.

@darrenjrobinson
Last active January 17, 2018 01:43
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/d97d75149c9f71ea404768b75fdbc3bc to your computer and use it in GitHub Desktop.
Save darrenjrobinson/d97d75149c9f71ea404768b75fdbc3bc to your computer and use it in GitHub Desktop.
Azure Powershell Time Function App to Generate FIM/MIM Documentation
# Username for connection to MIM Service via Function Application Settings
$username = $env:MIMSyncCredUser
$username
# Password for connection to MIM Service via Function Application Settings
$pw = $env:MIMSyncCredPassword
# Credentials password (encrypted)
$keypath = 'D:\home\site\wwwroot\myFunctionApp\keys\MIMSync.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 = {
# Import LithnetMIISAutomation for MIM Sync Server Config Exports
Import-Module lithnetmiisautomation
$MIMDocumenterPath = "C:\FIMDoco"
$MIMDocumenterScript = '\InvokeDocumenter-Customer.ps1'
$foldername = Get-Date -format dd-MM-yyyy;
$ReportPrefix = "$($MIMDocumenterPath)\Report\Customer_Dev_$($foldername)"
$outputfilepath = "$($MIMDocumenterPath)\Data\Customer\Dev\$($foldername)"
$outputfilepath
$BackupFolder = New-Item -Path $outputfilepath -Type Directory
# SyncServer Config Export
$SyncServer = New-Item -Path "$outputfilepath\SyncConfig" -Type Directory
# Portal Config Exports
$PortalExport = New-Item -Path "$outputfilepath\ServiceConfig" -Type Directory
# Export Sync Server
Export-MetaverseConfiguration -Path $SyncServer.FullName
# Load FIMAutomation Snapins
add-pssnapin FIMAutomation
# Portal Schema
$portalSchema = Export-FIMConfig -uri http://localhost:5725/ResourceManagementService -schemaConfig -customConfig "/SynchronizationFilter" ;
$portalSchema | ConvertFrom-FIMResource -file "$($PortalExport.Fullname)\Schema.xml"
# Portal Policy
$portalPolicy = Export-FIMConfig -uri http://localhost:5725/ResourceManagementService -policyConfig -portalConfig -MessageSize 9999999 ;
$portalPolicy | ConvertFrom-FIMResource -file "$($PortalExport.Fullname)\Policy.xml"
# Generate Report
invoke-expression -Command "$($MIMDocumenterPath)$($MIMDocumenterScript)"
# Create Report Directory
$Report = New-Item -Path "$outputfilepath\Report" -Type Directory
# Copy the Report to the folder associated with the configs
Copy-Item "$($ReportPrefix)_AppliedTo_MIM-SP1-Base_4.4.1302.0_Consolidated_report.html" "$($outputfilepath)\Report"
}
# Connect to MIM Sync Server and execute our documentation generation script
$results = Invoke-Command $scriptblock -computer customer-mimdev1server.australiaeast.cloudapp.azure.com -useSSL -credential $credentials -SessionOption $options
$results
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment