Last active
July 4, 2019 06:54
-
-
Save darrenjrobinson/152c3f83cc596633e342299c7a66c100 to your computer and use it in GitHub Desktop.
Nightly FIM-MIM Sync and Service Config Backup. Associated blogpost https://blog.darrenjrobinson.com/automate-the-nightly-backup-of-your-development-fimmim-sync-and-portal-servers-configuration/
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
# Username for connection to MIM Sync Server via Function Application Settings | |
$username = $env:MIMSyncCredUser | |
# Password for connection to MIM Sync Server via Function Application Settings | |
$pw = $env:MIMSyncCredPassword | |
# Credentials password (encrypted) | |
$keypath = 'D:\home\site\wwwroot\MyDevMIMBackup\keys\MIMSync.key' | |
$password = $pw | ConvertTo-SecureString -key (Get-Content $keypath) | |
# Create 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 on your MIM Sync Server Firewall and in you Resource Group Network Security Group Config | |
# Using Self Signed Cert so skip CA Checks | |
$options = New-PsSessionOption –SkipCACheck -SkipCNCheck | |
# Setup scriptblock | |
$scriptblock = { | |
# Import LithnetMIISAutomation for MIM Sync Server Config Exports | |
Import-Module lithnetmiisautomation; | |
# Find the MA's | |
$managementagents = Get-ManagementAgent; | |
$managementagents | |
# My Root Backup Path | |
$BackupPath = "C:\Backup"; | |
$foldername = Get-Date -format dd-MM-yyyy-hh-mm; | |
$outputfilepath = "$BackupPath\$foldername"; | |
# Backup Folder based on date and time | |
$outputfilepath | |
# Create Backup Folders | |
if(!(Test-Path $outputfilepath)){ | |
$BackupFolder = New-Item -Path $outputfilepath -Type Directory ; | |
# MA Exports | |
$MAExports = New-Item -Path "$outputfilepath\MAExports" -Type Directory ; | |
# Extensions Exports | |
$MAExtensions = New-Item -Path "$outputfilepath\MAExtensions" -Type Directory ; | |
# SyncExport Exports | |
$SyncServer = New-Item -Path "$outputfilepath\ServerExport" -Type Directory ; | |
# Portal Config | |
$PortalExport = New-Item -Path "$outputfilepath\PortalExport" -Type Directory ; | |
} | |
# Export MA's | |
foreach ($ma in $managementagents.name){ | |
Export-ManagementAgent -File ($MAExports.FullName+"\$ma.xml") -MA $ma ; | |
} | |
# Export Sync Server | |
Export-MetaverseConfiguration -Path $SyncServer.FullName; | |
# Copy Extensions | |
$extlocation = get-itemproperty "hklm:\software\microsoft\forefront identity manager\2010\synchronization service" -erroraction stop | select -expand location ; | |
$extensionsfolder = join-path $extlocation "Synchronization Service" ; | |
$extensionsfolder = join-path $extensionsfolder "Extensions" ; | |
Copy-Item "$extensionsfolder\*" $MAExtensions.fullname -recurse -Force ; | |
# Portal | |
add-pssnapin FIMAutomation; | |
$portalConfig = Export-FIMConfig -uri http://localhost:5725/ResourceManagementService -portalConfig ; | |
$portalConfig | ConvertFrom-FIMResource -file ($PortalExport.FullName+"\PortalConfig.xml"); | |
} | |
# Connect to MIM Sync Server and execute our backup script from above | |
$results = Invoke-Command $scriptblock -computer mymimsyncserver.cloudapp.net -useSSL -credential $credentials -SessionOption $options | |
$results |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment