8
8
[Diagnostics.CodeAnalysis.SuppressMessageAttribute (' PSReviewUnusedParameter' , ' ' , Justification = ' Parameter is used' )]
9
9
[CmdletBinding ()]
10
10
param (
11
- [string ] $OtherWellKnownObjectsContainer
11
+ [switch ] $OtherWellKnownObjects
12
12
)
13
13
14
14
function IsAdministrator {
@@ -196,6 +196,80 @@ function Get-ExchangeAdSetupObjects {
196
196
return $hash
197
197
}
198
198
199
+ Function Test-OtherWellKnownObjects {
200
+ [CmdletBinding ()]
201
+ param ()
202
+
203
+ $rootDSE = [ADSI ](" LDAP://RootDSE" )
204
+ $exchangeContainerPath = (" CN=Microsoft Exchange,CN=Services," + $rootDSE.configurationNamingContext )
205
+
206
+ ldifde - d $exchangeContainerPath - p Base - l otherWellKnownObjects -f ExchangeContainerOriginal.txt
207
+
208
+ [array ]$content = Get-Content .\ExchangeContainerOriginal.txt
209
+
210
+ if ($null -eq $content -or
211
+ $content.Count -eq 0 ) {
212
+ throw " Failed to export ExchangeContainerOriginal.txt file"
213
+ }
214
+
215
+ $owkoLine = " otherWellKnownObjects:"
216
+ $inOwkoLine = $false
217
+ $outputLines = New-Object ' System.Collections.Generic.List[string]'
218
+ $outputLines.Add ($content [0 ])
219
+ $outputLines.Add (" changeType: modify" )
220
+ $outputLines.Add (" replace: otherWellKnownObjects" )
221
+
222
+ $index = 0
223
+ while ($index -lt $content.Count ) {
224
+ $line = $content [$index ++ ]
225
+
226
+ if ($line.Trim () -eq $owkoLine ) {
227
+
228
+ if ($null -ne $testStringLine -and
229
+ $null -ne $possibleAdd ) {
230
+
231
+ if (! ($testStringLine -like " *CN=Deleted Objects*" )) {
232
+ $outputLines.AddRange ($possibleAdd )
233
+ } else {
234
+ Write-Host " Found object to remove: $testStringLine "
235
+ }
236
+ }
237
+ $inOwkoLine = $true
238
+ $possibleAdd = New-Object ' System.Collections.Generic.List[string]'
239
+ $possibleAdd.Add ($line )
240
+ [string ]$testStringLine = $line
241
+ continue
242
+ }
243
+
244
+ if ($inOwkoLine ) {
245
+ $possibleAdd.Add ($line )
246
+ $testStringLine += $line
247
+ }
248
+
249
+ if ($index -eq $content.Count ) {
250
+
251
+ if (! ($testStringLine -like " *CN=Deleted Objects*" )) {
252
+ $outputLines.AddRange ($possibleAdd )
253
+ } else {
254
+ Write-Host " Found object to remove: $testStringLine "
255
+ }
256
+ }
257
+ }
258
+
259
+ if ([string ]::IsNullOrEmpty($outputLines [-1 ])) {
260
+ $outputLines [-1 ] = " -"
261
+ } else {
262
+ $outputLines.Add (" -" )
263
+ }
264
+
265
+ $outputLines | Out-File - FilePath " ExchangeContainerImport.txt"
266
+
267
+ Write-Host (" `r`n Verify the results in ExchangeContainerImport.txt. Then run the following command:" )
268
+ Write-Host (" `r`n`t ldifde -i -f ExchangeContainerImport.txt" )
269
+ Write-Host (" `r`n Run Setup.exe again afterwards." )
270
+ return
271
+ }
272
+
199
273
Function MainUse {
200
274
$whoamiOutput = whoami / all
201
275
@@ -277,85 +351,11 @@ Function MainUse {
277
351
278
352
Function Main {
279
353
280
- if (! [string ]::IsNullOrEmpty($OtherWellKnownObjectsContainer )) {
281
-
282
- ldifde - d $OtherWellKnownObjectsContainer - p Base - l otherWellKnownObjects -f ExchangeContainerOriginal.txt
283
-
284
- [array ]$content = Get-Content .\ExchangeContainerOriginal.txt
285
-
286
- if ($null -eq $content -or
287
- $content.Count -eq 0 ) {
288
- throw " Failed to export ExchangeContainerOriginal.txt file"
289
- }
290
-
291
- $owkoLine = " otherWellKnownObjects:"
292
- $inOwkoLine = $false
293
- $outputLines = New-Object ' System.Collections.Generic.List[string]'
294
- $outputLines.Add ($content [0 ])
295
- $outputLines.Add (" changeType: modify" )
296
- $outputLines.Add (" replace: otherWellKnownObjects" )
297
-
298
- Function Test-DeleteObject ([string ]$TestLine ) {
299
-
300
- if ($TestLine.Contains (" CN=Deleted Objects" )) {
301
- return $true
302
- }
303
-
304
- return $false
305
- }
306
-
307
- $index = 0
308
- while ($index -lt $content.Count ) {
309
- $line = $content [$index ++ ]
310
-
311
- if ($line.Trim () -eq $owkoLine ) {
312
-
313
- if ($null -ne $testStringLine -and
314
- $null -ne $possibleAdd ) {
315
-
316
- if (! (Test-DeleteObject $testStringLine )) {
317
- $outputLines.AddRange ($possibleAdd )
318
- } else {
319
- Write-Host " Found object to remove: $testStringLine "
320
- }
321
- }
322
- $inOwkoLine = $true
323
- $possibleAdd = New-Object ' System.Collections.Generic.List[string]'
324
- $possibleAdd.Add ($line )
325
- [string ]$testStringLine = $line
326
- continue
327
- }
328
-
329
- if ($inOwkoLine ) {
330
- $possibleAdd.Add ($line )
331
- $testStringLine += $line
332
- }
333
-
334
- if ($index -eq $content.Count ) {
335
-
336
- if (! (Test-DeleteObject $testStringLine )) {
337
- $outputLines.AddRange ($possibleAdd )
338
- } else {
339
- Write-Host " Found object to remove: $testStringLine "
340
- }
341
- }
342
- }
343
-
344
- if ([string ]::IsNullOrEmpty($outputLines [-1 ])) {
345
- $outputLines [-1 ] = " -"
346
- } else {
347
- $outputLines.Add (" -" )
348
- }
349
-
350
- $outputLines | Out-File - FilePath " ExchangeContainerImport.txt"
351
-
352
- Write-Host (" `r`n Verify the results in ExchangeContainerImport.txt. Then run the following command:" )
353
- Write-Host (" `t ldifde -i -f ExchangeContainerImport.txt" )
354
- Write-Host (" Run Setup.exe again afterwards." )
355
- return
354
+ if ($OtherWellKnownObjects ) {
355
+ Test-OtherWellKnownObjects
356
+ } else {
357
+ MainUse
356
358
}
357
-
358
- MainUse
359
359
}
360
360
361
- Main
361
+ Main
0 commit comments