-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMIM_Backup_Functions.ps1
More file actions
281 lines (231 loc) · 10.6 KB
/
MIM_Backup_Functions.ps1
File metadata and controls
281 lines (231 loc) · 10.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
#####################################################################################
# Written by: Dave Hodge, MCS
# Purpose:
#####################################################################################
#######################################
# Variables
#######################################
$Backup_Location = "C:\Code"
$FIMSYNC_InstallDir = "C:\Program Files\Microsoft Forefront Identity Manager\2010"
$MIM_Environment = "Source"
$Domain = "CONTOSO"
$SVC_FIMSYNC = "SVC_MIMSYNC"
$PWD = ""
Function Create_Folder
{ Param([string]$Path)
if((test-path "$Path") -eq $false)
{
write-host "Create Folder: $Path"
mkdir $Path | out-null
}
}
Function ZipFolder
{ PARAM([string]$strPath)
#######################################
#Get the Date for Stamping the files...
#######################################
$a = Get-Date -format d
$a = $a.Replace("/","_")
#######################################
#Remove the UNC Formatting....
#######################################
if ($($strPath.subString(0,2)) -eq "\\")
{
$strFile = $strPath.ToUpper().Substring(2,$strPath.Length -2)
}
else
{
$strFile = $strPath.ToUpper().Replace("C:\","C_")
}
$strFile = "$strFile" + "_" + "$a"
$strFile = "$strFile.zip"
$strFile = $strFile.Replace("\","_")
#write-host "$strfile"
Compress-Archive -Path "$strPath" -DestinationPath "$Backup_Location\$strFile" -CompressionLevel Optimal -Force
}
Function Export_MIM_Configuration
{
Param([string]$Environment,[string]$Type, [string[]]$params)
# ExportSchema.ps1
# Copyright © 2009 Microsoft Corporation
# The purpose of this script is to export the current schema configuration
# in the pilot environment.
# The script stores the configuration into file "schema.xml" in the current directory.
# Please note you will need to rename the file to pilot_schema.xml or production_schema.xml.
# See the documentation for more information.
# Dave Hodge - Modified from original example to provide remoting capabilities & current folder capabilities
if(@(get-pssnapin | where-object {$_.Name -eq "FIMAutomation"} ).count -eq 0) {add-pssnapin FIMAutomation}
#$curDir = (get-location).path
$filename = "$($Backup_Location)\MIM_SERVICE_CONFIG\$($Environment)_$($type).xml"
write-host ""
write-host "############################################" -foregroundcolor green
Write-Host "Exporting $Type objects from $Environment..." -foregroundcolor green
write-host "############################################" -foregroundcolor green
Write-Host ""
Write-Host ""
Write-Host ""
Write-Host ""
$ProgressPreference = "SilentlyContinue"
$strCommand = "Export-FIMConfig $params"
$objects = invoke-expression "$strCommand"
$ProgressPreference = "Continue"
if ($objects -eq $null)
{
Write-Host "Export did not successfully retrieve configuration from FIM. Please review any error messages and ensure that the arguments to Export-FIMConfig are correct."
}
else
{
$objects | ConvertFrom-FIMResource -file $filename
Write-Host ""
Write-Host ""
Write-Host ""
Write-Host ""
Write-Host ""
Write-Host ""
Write-Host ""
Write-Host ""
Write-Host ""
Write-Host ""
Write-Host "Exported " $objects.Count " objects from $Environment"
Write-Host "File is saved as: " $filename
if($objects.Count -gt 0)
{
Write-Host "Export complete."
Write-Host ""
Write-Host "Note: The percentage exported may remain on the screen at less than 100%, but the export is complete...." -Foregroundcolor Red
}
else
{
Write-Host "While export completed, there were no resources. Please ensure that the arguments to Export-FIMConfig are correct."
}
}
}
Function Export_Schema
{
$ArgumentList = New-Object System.Collections.ArrayList
[void]$ArgumentList.Add("-schemaConfig")
[void]$ArgumentList.Add("-customConfig ""/SynchronizationFilter""")
[void]$ArgumentList.Add("-uri http://localhost:5725")
Export_MIM_Configuration $MIM_Environment "Schema" "$ArgumentList"
}
Function Export_Config
{
$ArgumentList = New-Object System.Collections.ArrayList
[void]$ArgumentList.Add("-portalConfig")
[void]$ArgumentList.Add("-MessageSize 9999999")
[void]$ArgumentList.Add("-uri http://localhost:5725")
Export_MIM_Configuration $MIM_Environment "Config" "$ArgumentList"
}
Function Export_Policy
{
$ArgumentList = New-Object System.Collections.ArrayList
[void]$ArgumentList.Add("-policyConfig")
[void]$ArgumentList.Add("-MessageSize 9999999")
[void]$ArgumentList.Add("-uri http://localhost:5725")
Export_MIM_Configuration $MIM_Environment "Policy" "$ArgumentList"
}
#########################################################
# Get Current Directory
#########################################################
$dir = (get-location).path
#######################################
# Cleanup previous runs...
#######################################
if((test-path "$Backup_Location") -eq $false)
{
write-host "Remove old runs"
Remove-Item -Path "$Backup_Location" -Recurse -Force | out-null
}
#######################################
# Create folder locations
#######################################
Create_Folder "$Backup_Location"
Create_Folder "$Backup_Location\MIM_SERVICE_CONFIG"
Create_Folder "$Backup_Location\MIM_SYNC_CONFIG"
Create_Folder "$Backup_Location\MIM_SYNC_DB_KEY"
Create_Folder "$Backup_Location\MIM_SYNC_TASK_SCHEDULER"
Start-sleep -milliseconds 1000
#######################################
# Back Script files
#######################################
#ZipFolder \\SERVER01\c$\code\scripts
#ZipFolder "C:\code\MIM Foundation - Resources"
#########################################################
# Switch to the Sync Engine Bin Folder
#########################################################
c:
cd "$FIMSYNC_InstallDir\Synchronization Service\Bin"
#########################################################
#Export Encryption Key
#https://technet.microsoft.com/en-us/library/jj590361(v=ws.10).aspx
#########################################################
Write-host "###############################################" -foregroundcolor green
Write-host "# Exporting MIM Sync Encryption Key............" -foregroundcolor green
Write-host "###############################################" -foregroundcolor green
###################################################################
# Get Password for service account...
###################################################################
$PWD = Read-Host -Prompt "Enter the password for $SVC_FIMSYNC account"
.\miiskmu.exe /e "$Backup_Location\MIM_SYNC_DB_KEY\MIM_SYNC_ENCRYPTION_KEY.bin" /u:"$($Domain)\$($SVC_FIMSYNC)" "$PWD" /q
Write-host "###############################################" -foregroundcolor green
Write-host "# Creating zip file for MIM Sync Encryption Key" -foregroundcolor green
Write-host "###############################################" -foregroundcolor green
ZipFolder "$Backup_Location\MIM_SYNC_DB_KEY"
#########################################################
# Export MIM Sync Config
#########################################################
Write-host "###############################################" -foregroundcolor green
Write-host "# Exporting for MIM Sync Config................" -foregroundcolor green
Write-host "###############################################" -foregroundcolor green
.\svrexport "$Backup_Location\MIM_SYNC_CONFIG"
sleep 1
Write-host "###############################################" -foregroundcolor green
Write-host "# Creating zip file for MIM Sync Config Files.." -foregroundcolor green
Write-host "###############################################" -foregroundcolor green
ZipFolder "$Backup_Location\MIM_SYNC_CONFIG"
cd "D:\MIM\Config Backup"
#########################################################
# Export MIM Sync Source Code
#########################################################
Write-host "###############################################" -foregroundcolor green
Write-host "# Creating zip file for MIM SourceCode folder.." -foregroundcolor green
Write-host "###############################################" -foregroundcolor green
ZipFolder "$FIMSYNC_InstallDir\Synchronization Service\SourceCode"
#########################################################
# Export MIM Sync Compiled Binaries
#########################################################
Write-host "###############################################" -foregroundcolor green
Write-host "# Creating zip file for MIM Compiled Binaries.." -foregroundcolor green
Write-host "###############################################" -foregroundcolor green
ZipFolder "$FIMSYNC_InstallDir\Synchronization Service\Extensions"
#######################################
# Export MIM Service Configuration files
#######################################
Write-host "###############################################" -foregroundcolor green
Write-host "# Exporting MIM Service configuration.........." -foregroundcolor green
Write-host "###############################################" -foregroundcolor green
Export_Schema
Export_Config
Export_Policy
Write-host "###############################################" -foregroundcolor green
Write-host "# Creating zip file for MIM Service files......" -foregroundcolor green
Write-host "###############################################" -foregroundcolor green
ZipFolder "$Backup_Location\MIM_SERVICE_CONFIG"
Write-host "###############################################" -foregroundcolor green
Write-host "# Exporting Scheduled Task......" -foregroundcolor green
Write-host "###############################################" -foregroundcolor green
Export-ScheduledTask -taskname "synchronization jobs" -taskpath "\" | Out-File -FilePath "D:\MIM\Config Backup\MIM_SYNC_TASK_SCHEDULER\Synchronization Jobs.Xml"
Write-host "###############################################" -foregroundcolor green
Write-host "# Creating zip file for Scheduled Task......" -foregroundcolor green
Write-host "###############################################" -foregroundcolor green
ZipFolder "$Backup_Location\MIM_SYNC_TASK_SCHEDULER"
Exit
#######################################
# FIM Sync Jobs
# - Scripts
# - Export of Scheduled Task
#######################################
#export-scheduledtask
# #schtasks /Query /XML /TN "Test Task" > "$Backup_Location\Sync_SyncJobs_Tasks\Task.xml"
# #schtasks /Query /XML /TN "Test Task" > "$Backup_Location\Sync_SyncJobs_Tasks\Task2.xml"
# "Get-ChildItem D:\Scripts\Sync\Sync_Jobs | ""$Backup_Location\Sync_SyncJobs_$a.zip"""