-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFIMAF2Visio_2019.ps1
More file actions
1419 lines (1279 loc) · 57.2 KB
/
FIMAF2Visio_2019.ps1
File metadata and controls
1419 lines (1279 loc) · 57.2 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
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#region Functions
#Evaluates inputs and determines if defaults are used
Function CheckInputs([ref]$FilePath,[ref]$ObjectFilter)
{
Try
{
If ($Inputs.Count -eq 0)
{
#No args - output message with example to console and proceed with defaults
"`r`nThere are no arguments. Exiting" | Write-Host
"`r`n`r`nInputs`r`n------" | Write-Host
"File Path (Required) Path to exported FIM Sync Engine Configuration `r`n" | Write-Host
"Object filter (Optional) Filter used to select which objects are drawn" | Write-Host
" Default - *`r`n" | Write-Host
"`r`n`r`nExamples`r`n--------" | Write-Host
"ScriptName.ps1 `"C:\FIM Config`"`r`n" | Write-Host
"ScriptName.ps1 `"C:\FIM Config`" `"Person`"`r`n" | Write-Host
Exit
}
ElseIf ($Inputs.Count -eq 1)
{
#Only 1 input - used for File Path
#defaults used for FollowFilterReferences and MPR Filter
$FilePath.Value = $Inputs[0]
"`r`nThere's only 1 argument. It will be used as the File Path" | Write-Host
"`r`n`r`nFile Path - $($FilePath.Value)" | Write-Host
"Object Filter - *" | Write-Host
}
ElseIf ($Inputs.Count -eq 2)
{
#2 inputs provided
$FilePath.Value = $Inputs[0]
$ObjectFilter.Value = $Inputs[1].Split(',')
"`r`nFile Path - $($FilePath.Value)" | Write-Host
"Object Filter - $($ObjectFilter.Value)" | Write-Host
}
Else
{
#More than 2 inputs detected
"ERROR - more than two arguments were passed" | Write-Host
Exit
}
}
Catch
{
"Error within CheckInputs function`r`n" | Write-Host
"`r`n`r`nInputs`r`n------" | Write-Host
$Inputs | Write-Host
"`r`nStack Trace is`r`n`r`n$($Error)`r`n`r`n" | Write-Host
$Error.Clear()
}
}
#Starts Visio Application
Function StartVisio
{
Try
{
$application = New-Object -ComObject Visio.Application
$application
}
Catch
{
"Error in StartVisio function - Please ensure Visio 2010 is installed on PC where script is located" | Write-Host
"`r`n`r`nStack trace is`r`n`r`n$($Error)`r`n`r`n" | Write-Host
Exit
}
}
#Opens Visio template file
Function AddNewPageFromTemplate
{
Try
{
#document class is Microsoft.Office.Interop.Visio.DocumentClass
$Documents = $Application.Documents
#Visio 2016
$Document = $Documents.Add("BASIC_U.VSSX")
$Document = $Documents.Add("ARROWS_U.VSSX")
#Visio 2013 or 2010 ????
#$Document = $Documents.Add("BASIC_U.VSS")
#Visio 2016 Template BASICD_U.VSTX
$Document = $Documents.Add("C:\Program Files\Microsoft Office\root\Office16\Visio Content\1033\BASICD_U.VSTX")
$Document.printlandscape = $true
}
Catch
{
"Error in AddNewPageFromTemplate function" | Write-Host
"BASICD_U.VST template may not be available" | Write-Host
"`r`n`r`nStack trace is`r`n`r`n$($Error)`r`n`r`n" | Write-Host
$Error.Clear()
}
}
#Gets top edge of shape object passed to it
Function GetTopEdge($Shape)
{
#Find top of shape
#Formula breakdown
#(Shape height * .5) gets distance from center of shape to top/bottom edge
#PinY is center of the shape
#center of the shape + distance to top edge is location of top edge
$Shape.Cells("PinY").ResultIU + ($Shape.Cells("height").ResultIU * .5)
}
#Gets bottom edge of shape object passed to it
Function GetBottomEdge($Shape)
{
#Find bottom of shape
#Formula breakdown
#(Shape height * .5) gets distance from center of shape to top/bottom edge
#PinY is center of the shape
#center of the shape - distance to bottom edge is location of bottom edge
$Shape.Cells("PinY").ResultIU - ($Shape.Cells("height").ResultIU * .5)
}
#Gets left edge of shape object passed to it
Function GetLeftEdge($Shape)
{
#Find Left edge of shape
#Formula breakdown
#(shape width * .5) is distance from center of shape to left/right edge
#PinX is vertical center of shape
#Center of shape - distance to left edge is location of left edge
$Shape.Cells("PinX").ResultIU - ($Shape.Cells("width").ResultIU * .5)
}
#Gets right edge of shape object passed to it
Function GetRightEdge($Shape)
{
#Find Right edge of shape
#Formula breakdown
#(shape width * .5) is distance from center of shape to left/right edge
#PinX is vertical center of shape
#Center of shape + distance to right edge is location of right edge
$Shape.Cells("PinX").ResultIU + ($Shape.Cells("width").ResultIU * .5)
}
#Sizes shape to fix text within it
Function ShapeFitText($Shape)
{
Try
{
#make shape as wide as text box
$ShapeWidth = $Shape.cells("width")
$ShapeWidth.Formula = "TEXTWIDTH(theText)"
#make shape as high as text box
$ShapeHeight = $Shape.cells("height")
$ShapeHeight.Formula = "TEXTHEIGHT(theText,width)"
}
Catch
{
"Error in ShapeFitText function" | Write-Host
"Shape is " + $Shape | Write-Host
"Page is " + $Page | Write-Host
"`r`n`r`nStack trace is`r`n`r`n$($Error)`r`n`r`n" | Write-Host
$Error.Clear()
}
}
#Centers shape horizontally on page
Function HCenterShapeOnPage($LocalPage,$Shape)
{
Try
{
$Width = $LocalPage.pagesheet.cells("pagewidth").resultIU
$Shape.cells("PinX").resultIU = $Width/2
}
Catch
{
"Error in HCenterShapeOnPage function" | Write-Host
"Page is " + $LocalPage.Name | Write-Host
"`r`n`r`nStack trace is`r`n`r`n$($Error)`r`n`r`n" | Write-Host
$Error.Clear()
}
}
#Centers shape vertically on page
Function VCenterShapeOnPage($LocalPage,$Shape)
{
Try
{
$Height = $LocalPage.pagesheet.cells("pageheight").resultIU
$Shape.cells("PinY").resultIU = $Height/2
}
Catch
{
"Error in VCenterShapeOnPage function" | Write-Host
"Page is " + $LocalPage.Name | Write-Host
"`r`n`r`nStack trace is`r`n`r`n$($Error)`r`n`r`n" | Write-Host
$Error.Clear()
}
}
#Moves shape's top edge to top page margin
Function AlignShapeTopWithTopMargin($LocalPage,$Shape)
{
Try
{
$ShapeTop = GetTopEdge $Shape
# -.25 accounts for top/bottom margins
$PageHeight = ($LocalPage.pagesheet.cells("pageheight").resultIU - .25)
#PinY is in center of shape
#formula breakdown
#(Top of shape - top of page) is distance above top of the page that the shape is
#PinY - (Top of shape - top of page) is location PinY needs to be for top of shape to equal top of page
$Shape.cells("pinY").resultIU = $Shape.cells("PinY").resultIU - ($ShapeTop - $Pageheight)
}
Catch
{
"Error in AlignShapetopWithTopMargin function" | Write-Host
"Page is " + $LocalPage.Name | Write-Host
"`r`n`r`nStack trace is`r`n`r`n$($Error)`r`n`r`n" | Write-Host
$Error.Clear()
}
}
#Moves shape's left edge to left margin
Function AlignShapeLeftWithLeftMargin($LocalPage,$Shape)
{
Try
{
$ShapeLeft = GetLeftEdge $Shape
#PinX is in center of shape
#formula breakdown
#(left edge of shape * -1) is distance left of the page that the shape is
#PinX - (left edge of shape * -1) is location PinX needs to be for left edge of shape to equal left edge of page
# + .25 moves PinX left enough for left edge of shape to align with left margin
$Shape.cells("pinX").resultIU = $Shape.cells("PinX").resultIU + ($ShapeLeft * -1) + 0.25
}
Catch
{
"Error in AlignShapeLeftWithLeftMargin function" | Write-Host
"Page is " + $LocalPage.Name | Write-Host
"`r`n`r`nStack trace is`r`n`r`n$($Error)`r`n`r`n" | Write-Host
$Error.Clear()
}
}
#Resets Grig and Ruler so that bottom left corner is always 0,0
Function ResetGridAndRuler($LocalPage)
{
Try
{
$LocalPage.PageSheet.cells("XRulerOrigin").ResultIU = 0
$LocalPage.PageSheet.cells("XGridOrigin").ResultIU = 0
$LocalPage.PageSheet.cells("YRulerOrigin").ResultIU = 0
$LocalPage.PageSheet.cells("YGridOrigin").ResultIU = 0
}
Catch
{
"Error in ResetGrigAndRuler function" | Write-Host
"Page is " + $LocalPage.Name | Write-Host
"`r`n`r`nStack trace is`r`n`r`n$($Error)`r`n`r`n" | Write-Host
$Error.Clear()
}
}
#Creates Shape
Function AddShape($LocalPage, $Text)
{
Try
{
$Shape = $Page.Drop($RectangleStencil,5.5,4.25)
$Shape.Text = $Text
$Shape.Cells("Para.HorzAlign").ResultIU = 0
ShapeFitText $Shape
$Shape
}
Catch
{
"Error in AddShape function" | Write-Host
"Object name is " + ($Text.SubString(0,$Text.Indexof([char]10))) | Write-Host
"Page is " + $LocalPage.Name | Write-Host
"`r`n`r`nStack trace is`r`n`r`n$($Error)`r`n`r`n" | Write-Host
$Error.Clear()
$Shape
}
}
#Gets left edge of shape with left edge furthest left
Function GetLeftMostEdge
{
Try
{
$LeftEdge = $Page.PageSheet.Cells("pagewidth").ResultIU
$r = 1
While (($r-1) -lt $Page.Shapes.Count)
{
#connectors exist in page shape list, but root shape isn't shape class
If ($Page.Shapes[$r].Name.ToString().Contains("Rectangle"))
{
If ($LeftEdge -gt (GetLeftEdge $Page.Shapes[$r]))
{
$LeftEdge = (GetLeftEdge $Page.Shapes[$r])
}
}
$r = $r + 1
}
$LeftEdge
}
Catch
{
"Error in GetLeftMostEdge function" | Write-Host
"Page is " + $Page.Name | Write-Host
"`r`n`r`nStack trace is`r`n`r`n$($Error)`r`n`r`n" | Write-Host
$Error.Clear()
$LeftEdge
}
}
#Gets right edge of shape with right edge furthest right
Function GetRightMostEdge
{
Try
{
$RightEdge = 0
$r = 0
While ($r -lt $Page.Shapes.Count)
{
If ($RightEdge -lt (GetRightEdge $Page.Shapes[($r+1)]))
{
$RightEdge = (GetRightEdge $Page.Shapes[($r+1)])
}
$r = $r + 1
}
$RightEdge
}
Catch
{
"Error in GetRightMostEdge function" | Write-Host
"Page is " + $Page.Name | Write-Host
"`r`n`r`nStack trace is`r`n`r`n$($Error)`r`n`r`n" | Write-Host
$Error.Clear()
$RightEdge
}
}
<#
.SYNOPSIS
Gets the Import Attribute Flow Rules from Sync Server Configuration
.DESCRIPTION
Reads the server configuration from the XML files, and outputs the Import Attribute Flow rules as PSObjects
.OUTPUTS
PSObjects containing the synchronization server import attribute flow rules
.EXAMPLE
Get-ImportAttributeFlow -ServerConfigurationFolder "E:\ServerConfiguration" | out-gridview
#>
Function Get-ImportAttributeFlow
{
Param
(
[parameter(Mandatory=$false)]
[String]
[ValidateScript({Test-Path $_})]
$ServerConfigurationFolder,
[String[]]
$ObjFilter
)
End
{
### This is where the rules will be aggregated before we output them
$rules = @()
###
### Loop through the management agent XMLs to get the Name:GUID mapping
###
$maList = @{}
$maFiles = (get-item (join-path $ServerConfigurationFolder "*.xml"))
foreach ($maFile in $maFiles)
{
### Skip the file if it does NOT contain an ma-data node
if (select-xml $maFile -XPath "//ma-data" -ErrorAction 0)
{
### Get the MA Name and MA ID
$maName = (select-xml $maFile -XPath "//ma-data/name").Node.InnerText
$maID = (select-xml $maFile -XPath "//ma-data/id").Node.InnerText
$maList.Add($maID,$maName)
}
}
###
### Get:
### mv-object-type
### mv-attribute
### src-ma
### cd-object-type
### src-attribute
###
[xml]$mv = get-content (join-path $ServerConfigurationFolder "MV.xml")
foreach($importFlowSet in $mv.selectNodes("//import-flow-set"))
{
$mvObjectType = $importFlowSet.'mv-object-type'
if ($ObjFilter -eq "*" -or $ObjFilter -contains $mvObjectType)
{
foreach($importFlows in $importFlowSet.'import-flows')
{
$mvAttribute = $importFlows.'mv-attribute'
$precedenceType = $importFlows.type
$precedenceRank = 0
foreach($importFlow in $importFlows.'import-flow')
{
$cdObjectType = $importFlow.'cd-object-type'
$srcMA = $maList[$importFlow.'src-ma']
$maID = $importFlow.'src-ma'
$maName = $maList[$maID]
if ($importFlow.'direct-mapping' -ne $null)
{
if ($precedenceType -eq 'ranked')
{
$precedenceRank += 1
}
else
{
$precedenceRank = $null
}
###
### Handle src-attribute that are intinsic (<src-attribute intrinsic="true">dn</src-attribute>)
###
if ($importFlow.'direct-mapping'.'src-attribute'.intrinsic)
{
$srcAttribute = "<{0}>" -F $importFlow.'direct-mapping'.'src-attribute'.'#text'
}
else
{
$srcAttribute = $importFlow.'direct-mapping'.'src-attribute'
}
$rule = New-Object PSObject
$rule | Add-Member -MemberType noteproperty -name 'RuleType' -value 'DIRECT'
$rule | Add-Member -MemberType noteproperty -name 'SourceMA' -value $srcMA
$rule | Add-Member -MemberType noteproperty -name 'CDObjectType' -value $cdObjectType
$rule | Add-Member -MemberType noteproperty -name 'CDAttribute' -value $srcAttribute
$rule | Add-Member -MemberType noteproperty -name 'MVObjectType' -value $mvObjectType
$rule | Add-Member -MemberType noteproperty -name 'MVAttribute' -value $mvAttribute
$rule | Add-Member -MemberType noteproperty -name 'ScriptContext' -value $null
$rule | Add-Member -MemberType noteproperty -name 'PrecedenceType' -value $precedenceType
$rule | Add-Member -MemberType noteproperty -name 'PrecedenceRank' -value $precedenceRank
$rules += $rule
}
elseif ($importFlow.'scripted-mapping' -ne $null)
{
$scriptContext = $importFlow.'scripted-mapping'.'script-context'
###
### Handle src-attribute that are intrinsic (<src-attribute intrinsic="true">dn</src-attribute>)
###
$srcAttributes = @()
$importFlow.'scripted-mapping'.'src-attribute' | ForEach-Object {
if ($_.intrinsic)
{
$srcAttributes += "<{0}>" -F $_.'#text'
}
else
{
$srcAttributes += $_
}
}
if ($srcAttributes.Count -eq 1)
{
$srcAttributes = $srcAttributes -as [String]
}
if ($precedenceType -eq 'ranked')
{
$precedenceRank += 1
}
else
{
$precedenceRank = $null
}
$rule = New-Object PSObject
$rule | Add-Member -MemberType noteproperty -name 'RuleType' -value 'SCRIPTED'
$rule | Add-Member -MemberType noteproperty -name 'SourceMA' -value $srcMA
$rule | Add-Member -MemberType noteproperty -name 'CDObjectType' -value $cdObjectType
$rule | Add-Member -MemberType noteproperty -name 'CDAttribute' -value $srcAttributes
$rule | Add-Member -MemberType noteproperty -name 'MVObjectType' -value $mvObjectType
$rule | Add-Member -MemberType noteproperty -name 'MVAttribute' -value $mvAttribute
$rule | Add-Member -MemberType noteproperty -name 'ScriptContext' -value $scriptContext.Replace("`"","'")
$rule | Add-Member -MemberType noteproperty -name 'PrecedenceType' -value $precedenceType
$rule | Add-Member -MemberType noteproperty -name 'PrecedenceRank' -value $precedenceRank
$rules += $rule
}
elseif ($importFlow.'sync-rule-mapping' -ne $null)
{
$scriptContext = $null
$ruleType = ("ISR-{0}" -f $importFlow.'sync-rule-mapping'.'mapping-type')
$srcAttributes = $importFlow.'sync-rule-mapping'.'src-attribute'
if ($precedenceType -eq 'ranked')
{
$precedenceRank += 1
}
else
{
$precedenceRank = $null
}
$rule = New-Object PSObject
if ($importFlow.'sync-rule-mapping'.'mapping-type' -ieq 'expression')
{
$scriptContext = $importFlow.'sync-rule-mapping'.'sync-rule-value'.'import-flow'.InnerXml
$rule | Add-Member -MemberType noteproperty -name 'ScriptContext' -value $scriptContext
}
elseif ($importFlow.'sync-rule-mapping'.'mapping-type' -ieq 'constant')
{
$constantValue = $importFlow.'sync-rule-mapping'.'sync-rule-value'
$rule | Add-Member -MemberType noteproperty -name 'ConstantValue' -value $constantValue
}
$rule | Add-Member -MemberType noteproperty -name 'RuleType' -value $ruleType
$rule | Add-Member -MemberType noteproperty -name 'SourceMA' -value $srcMA
$rule | Add-Member -MemberType noteproperty -name 'CDObjectType' -value $cdObjectType
$rule | Add-Member -MemberType noteproperty -name 'CDAttribute' -value $srcAttributes
$rule | Add-Member -MemberType noteproperty -name 'MVObjectType' -value $mvObjectType
$rule | Add-Member -MemberType noteproperty -name 'MVAttribute' -value $mvAttribute
$rule | Add-Member -MemberType noteproperty -name 'PrecedenceType' -value $precedenceType
$rule | Add-Member -MemberType noteproperty -name 'PrecedenceRank' -value $precedenceRank
$rules += $rule
}
elseif ($importFlow.'constant-mapping' -ne $null)
{
if ($precedenceType -eq 'ranked')
{
$precedenceRank += 1
}
else
{
$precedenceRank = $null
}
$constantValue = $importFlow.'constant-mapping'.'constant-value'
$rule = New-Object PSObject
$rule | Add-Member -MemberType noteproperty -name 'RuleType' -value "CONSTANT"
$rule | Add-Member -MemberType noteproperty -name 'SourceMA' -value $srcMA
$rule | Add-Member -MemberType noteproperty -name 'CDObjectType' -value $cdObjectType
$rule | Add-Member -MemberType noteproperty -name 'CDAttribute' -value $null
$rule | Add-Member -MemberType noteproperty -name 'MVObjectType' -value $mvObjectType
$rule | Add-Member -MemberType noteproperty -name 'MVAttribute' -value $mvAttribute
$rule | Add-Member -MemberType noteproperty -name 'ScriptContext' -value $null
$rule | Add-Member -MemberType noteproperty -name 'PrecedenceType' -value $precedenceType
$rule | Add-Member -MemberType noteproperty -name 'PrecedenceRank' -value $precedenceRank
$rule | Add-Member -MemberType noteproperty -name 'ConstantValue' -value $constantValue
$rules += $rule
}
}#foreach($importFlow in $importFlows.'import-flow')
}#foreach($importFlows in $importFlowSet.'import-flows')
}#foreach($importFlowSet in $mv.selectNodes("//import-flow-set"))
}
Write-Output $rules
}#End
}
<#
.SYNOPSIS
Gets the Export Attribute Flow Rules from Sync Server Configuration
.DESCRIPTION
Reads the server configuration from the XML files, and outputs the Export Attribute Flow rules as PSObjects
.OUTPUTS
PSObjects containing the synchronization server export attribute flow rules
.EXAMPLE
Get-ExportAttributeFlow -ServerConfigurationFolder "E:\sd\IAM\ITAuthorize\Source\Configuration\FimSync\ServerConfiguration"
#>
Function Get-ExportAttributeFlow
{
Param
(
[parameter(Mandatory=$false)]
[String]
[ValidateScript({Test-Path $_})]
$ServerConfigurationFolder,
[String[]]
$ObjFilter
)
End
{
### This is where the rules will be aggregated before we output them
$rules = @()
### Export attribute flow rules are contained in the ma-data nodes of the MA*.XML files
$maFiles = @(get-item (Join-Path $ServerConfigurationFolder "MA-*.xml"))
foreach ($maFile in $maFiles)
{
### Get the MA Name and MA ID
$maName = (select-xml $maFile -XPath "//ma-data/name").Node.InnerText
foreach($exportFlowSet in (Select-Xml -path $maFile -XPath "//export-flow-set" | select -ExpandProperty Node))
{
$mvObjectType = $exportFlowSet.'mv-object-type'
$cdObjectType = $exportFlowSet.'cd-object-type'
if ($ObjFilter -eq "*" -or $ObjFilter -contains $mvObjectType)
{
foreach($exportFlow in $exportFlowSet.'export-flow')
{
$cdAttribute = $exportFlow.'cd-attribute'
[bool]$allowNulls = $false
if ([bool]::TryParse($exportFlow.'suppress-deletions', [ref]$allowNulls))
{
$allowNulls = -not $allowNulls
}
[string]$initialFlowOnly = $null
[string]$isExistenceTest = $null
[string]$syncRuleID = $null
if ($exportFlow.'direct-mapping' -ne $null)
{
###
### Handle src-attribute that are intrinsic (<src-attribute intrinsic="true">object-id</src-attribute>)
###
if ($exportFlow.'direct-mapping'.'src-attribute'.intrinsic)
{
$srcAttribute = "<{0}>" -F $exportFlow.'direct-mapping'.'src-attribute'.'#text'
}
else
{
$srcAttribute = $exportFlow.'direct-mapping'.'src-attribute'
}
$rule = New-Object PSObject
$rule | Add-Member -MemberType NoteProperty -Name 'RuleType' -Value 'DIRECT'
$rule | Add-Member -MemberType NoteProperty -Name 'MAName' -Value $maName
$rule | Add-Member -MemberType NoteProperty -Name 'MVObjectType' -Value $mvObjectType
$rule | Add-Member -MemberType NoteProperty -Name 'MVAttribute' -Value $srcAttribute
$rule | Add-Member -MemberType NoteProperty -Name 'CDObjectType' -Value $cdObjectType
$rule | Add-Member -MemberType NoteProperty -Name 'CDAttribute' -Value $cdAttribute
$rule | Add-Member -MemberType NoteProperty -Name 'ScriptContext' -Value $null
$rule | Add-Member -MemberType NoteProperty -Name 'AllowNulls' -Value $allowNulls
$rule | Add-Member -MemberType NoteProperty -Name 'InitialFlowOnly' -Value $initialFlowOnly
$rule | Add-Member -MemberType NoteProperty -Name 'IsExistenceTest' -Value $isExistenceTest
$rules += $rule
}
if ($exportFlow.'constant-mapping' -ne $null)
{
###
### Handle src-attribute that are intrinsic (<src-attribute intrinsic="true">object-id</src-attribute>)
###
$constantValue = $exportFlow.'constant-mapping'.'constant-Value'
$rule = New-Object PSObject
$rule | Add-Member -MemberType NoteProperty -Name 'RuleType' -Value 'CONSTANT'
$rule | Add-Member -MemberType NoteProperty -Name 'MAName' -Value $maName
$rule | Add-Member -MemberType NoteProperty -Name 'MVObjectType' -Value $mvObjectType
$rule | Add-Member -MemberType NoteProperty -Name 'CDObjectType' -Value $cdObjectType
$rule | Add-Member -MemberType NoteProperty -Name 'CDAttribute' -Value $cdAttribute
$rule | Add-Member -MemberType NoteProperty -Name 'ConstantValue' -Value $constantValue
$rule | Add-Member -MemberType NoteProperty -Name 'AllowNulls' -Value $allowNulls
$rule | Add-Member -MemberType NoteProperty -Name 'InitialFlowOnly' -Value $initialFlowOnly
$rule | Add-Member -MemberType NoteProperty -Name 'IsExistenceTest' -Value $isExistenceTest
$rule | Add-Member -MemberType NoteProperty -Name 'SyncRuleID' -Value $syncRuleID
$rules += $rule
}
elseif ($exportFlow.'scripted-mapping' -ne $null)
{
$scriptContext = $exportFlow.'scripted-mapping'.'script-context'
$srcAttributes = @()
###
### Handle src-attribute that are intrinsic (<src-attribute intrinsic="true">object-id</src-attribute>)
###
$exportFlow.'scripted-mapping'.'src-attribute' | ForEach-Object {
if ($_.intrinsic)
{
$srcAttributes += "<{0}>" -F $_.'#text'
}
elseif ($_) # Do not add empty values.
{
$srcAttributes += $_
}
}
# (Commented) Leave as collection
if ($srcAttributes.Count-eq 1)
{
$srcAttributes = $srcAttributes -as[String]
}
$rule = New-Object PSObject
$rule | Add-Member -MemberType NoteProperty -Name 'RuleType' -Value 'SCRIPTED'
$rule | Add-Member -MemberType NoteProperty -Name 'MAName' -Value $maName
$rule | Add-Member -MemberType NoteProperty -Name 'MVObjectType' -Value $mvObjectType
$rule | Add-Member -MemberType NoteProperty -Name 'MVAttribute' -Value $srcAttributes
$rule | Add-Member -MemberType NoteProperty -Name 'CDObjectType' -Value $cdObjectType
$rule | Add-Member -MemberType NoteProperty -Name 'CDAttribute' -Value $cdAttribute
$rule | Add-Member -MemberType NoteProperty -Name 'ScriptContext' -Value $scriptContext.Replace("`"","'")
$rule | Add-Member -MemberType NoteProperty -Name 'AllowNulls' -Value $allowNulls
$rule | Add-Member -MemberType NoteProperty -Name 'InitialFlowOnly' -Value $initialFlowOnly
$rule | Add-Member -MemberType NoteProperty -Name 'IsExistenceTest' -Value $isExistenceTest
$rule | Add-Member -MemberType NoteProperty -Name 'SyncRuleID' -Value $syncRuleID
$rules += $rule
}
elseif ($exportFlow.'sync-rule-mapping' -ne $null)
{
$syncRuleID = $exportFlow.'sync-rule-mapping'.'sync-rule-id'
$srcAttribute = $exportFlow.'sync-rule-mapping'.'src-attribute'
$initialFlowOnly = $exportFlow.'sync-rule-mapping'.'initial-flow-only'
$isExistenceTest = $exportFlow.'sync-rule-mapping'.'is-existence-test'
if($exportFlow.'sync-rule-mapping'.'mapping-type' -eq 'direct')
{
$rule = New-Object PSObject
$rule | Add-Member -MemberType NoteProperty -Name 'RuleType' -Value 'OSR-Direct'
$rule | Add-Member -MemberType NoteProperty -Name 'MAName' -Value $maName
$rule | Add-Member -MemberType NoteProperty -Name 'MVObjectType' -Value $mvObjectType
$rule | Add-Member -MemberType NoteProperty -Name 'MVAttribute' -Value $srcAttribute
$rule | Add-Member -MemberType NoteProperty -Name 'CDObjectType' -Value $cdObjectType
$rule | Add-Member -MemberType NoteProperty -Name 'CDAttribute' -Value $cdAttribute
$rule | Add-Member -MemberType NoteProperty -Name 'ScriptContext' -Value $null
$rule | Add-Member -MemberType NoteProperty -Name 'AllowNulls' -Value $allowNulls
$rule | Add-Member -MemberType NoteProperty -Name 'InitialFlowOnly' -Value $initialFlowOnly
$rule | Add-Member -MemberType NoteProperty -Name 'IsExistenceTest' -Value $isExistenceTest
$rule | Add-Member -MemberType NoteProperty -Name 'SyncRuleID' -Value $syncRuleID
$rules += $rule
}
elseif ($exportFlow.'sync-rule-mapping'.'mapping-type' -eq 'expression')
{
$scriptContext = $exportFlow.'sync-rule-mapping'.'sync-rule-value'.'export-flow'.InnerXml
$cdAttribute = $exportFlow.'sync-rule-mapping'.'sync-rule-value'.'export-flow'.dest
$rule = New-Object PSObject
$rule | Add-Member -MemberType NoteProperty -Name 'RuleType' -Value 'OSR-Expression'
$rule | Add-Member -MemberType NoteProperty -Name 'MAName' -Value $maName
$rule | Add-Member -MemberType NoteProperty -Name 'MVObjectType' -Value $mvObjectType
$rule | Add-Member -MemberType NoteProperty -Name 'MVAttribute' -Value $srcAttribute
$rule | Add-Member -MemberType NoteProperty -Name 'CDObjectType' -Value $cdObjectType
$rule | Add-Member -MemberType NoteProperty -Name 'CDAttribute' -Value $cdAttribute
$rule | Add-Member -MemberType NoteProperty -Name 'ScriptContext' -Value $scriptContext
$rule | Add-Member -MemberType NoteProperty -Name 'AllowNulls' -Value $allowNulls
$rule | Add-Member -MemberType NoteProperty -Name 'InitialFlowOnly' -Value $initialFlowOnly
$rule | Add-Member -MemberType NoteProperty -Name 'IsExistenceTest' -Value $isExistenceTest
$rule | Add-Member -MemberType NoteProperty -Name 'SyncRuleID' -Value $syncRuleID
$rules += $rule
}
elseif($exportFlow.'sync-rule-mapping'.'mapping-type' -eq 'constant')
{
$constantValue = $exportFlow.'sync-rule-mapping'.'sync-rule-value'
$rule = New-Object PSObject
$rule | Add-Member -MemberType NoteProperty -Name 'RuleType' -Value 'OSR-Constant'
$rule | Add-Member -MemberType NoteProperty -Name 'MAName' -Value $maName
$rule | Add-Member -MemberType NoteProperty -Name 'MVObjectType' -Value $mvObjectType
$rule | Add-Member -MemberType NoteProperty -Name 'MVAttribute' -Value $srcAttribute
$rule | Add-Member -MemberType NoteProperty -Name 'CDObjectType' -Value $cdObjectType
$rule | Add-Member -MemberType NoteProperty -Name 'CDAttribute' -Value $cdAttribute
$rule | Add-Member -MemberType NoteProperty -Name 'AllowNulls' -Value $allowNulls
$rule | Add-Member -MemberType NoteProperty -Name 'InitialFlowOnly' -Value $initialFlowOnly
$rule | Add-Member -MemberType NoteProperty -Name 'IsExistenceTest' -Value $isExistenceTest
$rule | Add-Member -MemberType NoteProperty -Name 'ConstantValue' -Value $constantValue
$rule | Add-Member -MemberType NoteProperty -Name 'SyncRuleID' -Value $syncRuleID
$rules += $rule
}
else
{
$exportFlow.'sync-rule-mapping'.'mapping-type' | Write-Host
throw "Unsupported Export Flow type"
}
}
}
}
}
}
Write-Output $rules
}#End
}
Function Get-ImportToExportAttributeFlow
{
Param
(
[parameter(Mandatory=$true)]
[String]
[ValidateScript({Test-Path $_})]
$ServerConfigurationFolder,
[parameter(Mandatory=$true)]
[String[]]
$Filter
)
End
{
### Get the Import Attribute Flow Rules
$IAFs = Get-ImportAttributeFlow -ServerConfigurationFolder $ServerConfigurationFolder $Filter
### Add extra property for matching IAFs from different MAs
### Used to prevent duplicating IAFs that were previously matched
Foreach ($IAF in $IAFs)
{
$IAF | Add-Member -MemberType "NoteProperty" -Name "Matched" -Value $false
}
### Get the Export Attribute Flow Rules
$EAFs = Get-ExportAttributeFlow -ServerConfigurationFolder $ServerConfigurationFolder $Filter
### Add extra property for matching IAFs from different MAs
### Used to prevent duplicating IAFs that were previously matched
Foreach ($EAF in $EAFs)
{
$EAF | Add-Member -MemberType "NoteProperty" -Name "Matched" -Value $false
}
########################################################################
### This is where the rules will be aggregated before we output them ###
########################################################################
### Array holding PSObjects with arrays of IAFs and EAFs
$e2eFlowRules = @()
$i = 0
### Loops through IAFs looking for IAF and EAF matches until all IAFs are matched
foreach ($IAF in $IAFs)
{
### empty PS object to hold IAF and EAF arrays
$e2eAF = New-Object PSObject
$iafArray = @()
$eafArray = @()
### if not already matched look for matches
### if already matched move on to next IAF
if ($IAF.Matched -eq $false)
{
### IAF isn't matched add it to array and set Matched true
$IAF.Matched = $true
$e2eAF | Add-Member -MemberType "NoteProperty" -Name "MVObjectType" -Value $IAF.MVObjectType
$e2eAF | Add-Member -MemberType "NoteProperty" -Name "MVAttribute" -Value $IAF.MVAttribute
$iafArray += ($IAF | select * -ExcludeProperty MVObjectType,MVAttribute,Matched)
### get matching IAFs
$iafMatches = @($IAFs | where {$_.'MVAttribute' -contains $IAF.'MVAttribute' -and $_.'MVObjectType' -eq $IAF.'MVObjectType' -and $_.'Matched' -eq $false})
if ($iafMatches.Count -gt 0)
{
### Loops through matching IAFs adding them to array and setting matched true
Foreach ($match in $iafMatches)
{
### Set matched to true and add matches to array
$match.Matched = $true
$iafArray += ($match | select * -ExcludeProperty MVObjectType,MVAttribute,Matched)
}
}
### Look for a matchinging EAF rule
$eafMatches = @($EAFs | where {$_.'MVAttribute' -contains $IAF.'MVAttribute' -and $_.'MVObjectType' -eq $IAF.'MVObjectType'})
if ($eafMatches.count -gt 0)
{
### Loops through matching EAFs adding them to array and setting matched true
foreach($match in $eafMatches)
{
### Set matched to true and add matches to array
$match.Matched = $true
### use MVAttribute with EAF only if there's more than one attribute used.
if ($match.MVAttribute.Count -gt 1)
{
$eafArray += ($match | select * -ExcludeProperty MVObjectType,Matched)
}
else
{
$eafArray += ($match | select * -ExcludeProperty MVObjectType,MVAttribute,Matched)
}
}
}
### if arrays have objects add them to PSObject
if ($iafArray.Length -gt 0)
{
$e2eAF | Add-Member -MemberType "NoteProperty" -Name "IAFs" -Value $iafArray
if ($eafArray.Length -gt 0)
{
$e2eAF | Add-Member -MemberType "NoteProperty" -Name "EAFs" -Value $eafArray
}
### Add PSObject to array for output
$e2eFlowRules += $e2eAF
}
}
}
### Add unmatched EAFs to array
foreach ($EAF in @($EAFs | where {$_.'Matched' -eq $false}))
{
### Create empty array for EAF
$eafArray = @()
### Create new PSObject for eafArray
$e2eAF = New-Object PSObject
### Update Matched and add EAF to array
$EAF.Matched = $true
$e2eAF | Add-Member -MemberType "NoteProperty" -Name "MVObjectType" -Value $EAF.MVObjectType
$e2eAF | Add-Member -MemberType "NoteProperty" -Name "MVAttribute" -Value $EAF.MVAttribute
### use MVAttribute with EAF only if there's more than one attribute used
if ($EAF.MVAttribute.Count -gt 1)
{
$eafArray += ($EAF | select * -ExcludeProperty MVObjectType,Matched)
}
else
{
$eafArray += ($EAF | select * -ExcludeProperty MVObjectType,MVAttribute,Matched)
}
### Add array to PSObject
$e2eAF | Add-Member -MemberType "NoteProperty" -Name "EAFs" -Value $eafArray
### Add PSObject to array for output
$e2eFlowRules += $e2eAF
}
######################################################
################## Output formatting #################
######################################################
### Uncomment following line and comment out the following Foreach
### to output array of objects to work with
$e2eFlowRules | select MVObjectType,MVAttribute,IAFs,EAFs | sort MVObjectType,MVAttribute
### For readable output to screen
# Foreach ($Object in $e2eFlowRules)
# {
# "MVObjectType : " + $Object.MVObjectType
# "MVAttribute : " + $Object.MVAttribute
# "IAFs"
# "----"
# $Object.IAFs
# "EAFs"
# "----"
# $Object.EAFs
# "------------------------------------------------------------------------------"
# }
}
}
#Loops through IAFShapes and positions them on page
Function PositionIAFs
{
Try
{
$Y = 0
While ($Y -lt $IAFShapes.Count)
{
#position left of MV object
If ($Y -eq 0)
{
#height of new top edge
$NewTopEdge = ($Page.pagesheet.cells("pageheight").resultIU - .25)
#height of current top edge
$CurrentTopEdge = GetTopEdge $IAFShapes[$Y]
#Set PinY for first shape to top margin of page
$IAFShapes[$Y].Cells("PinY").ResultIU = $IAFShapes[$Y].Cells("PinY").ResultIU + ($NewTopEdge - $CurrentTopEdge)
$NewRightEdge = (GetLeftEdge $MVShape) - 2
$CurrentRightEdge = GetRightEdge $IAFShapes[$Y]
$IAFShapes[$Y].Cells("PinX").ResultIU = $IAFShapes[$Y].Cells("PinX").ResultIU + ($NewRightEdge - $CurrentRightEdge)
}
#Position under previous set object
else
{
#height of new top edge
$NewTopEdge = ((GetBottomEdge $IAFShapes[($Y-1)]) -.5)
#height of current top edge
$CurrentTopEdge = GetTopEdge $IAFShapes[$Y]
#PinY needs to move the difference between the new and current top edges
$IAFShapes[$Y].Cells("PinY").ResultIU = $IAFShapes[$Y].Cells("PinY").ResultIU + ($NewTopEdge - $CurrentTopEdge)
$NewRightEdge = GetRightEdge $IAFShapes[($Y-1)]
$CurrentRightEdge = GetRightEdge $IAFShapes[$Y]