@@ -22,20 +22,30 @@ internal static class ActiveDirectoryClientExtensions
2222 {
2323 public static PSADObject ToPSADObject ( this User user )
2424 {
25- return new PSADObject ( )
26- {
27- DisplayName = user . DisplayName ,
28- Id = new Guid ( user . ObjectId )
29- } ;
25+ var adObj = new PSADObject ( ) { DisplayName = user . DisplayName } ;
26+ return AssignObjectId ( adObj , user . ObjectId ) ;
3027 }
3128
3229 public static PSADObject ToPSADObject ( this ADGroup group )
3330 {
34- return new PSADObject ( )
31+ var adObj = new PSADObject ( ) { DisplayName = group . DisplayName } ;
32+ return AssignObjectId ( adObj , group . ObjectId ) ;
33+ }
34+
35+ public static PSADObject AssignObjectId ( PSADObject adObj , string objectId )
36+ {
37+ Guid objectIdGuid ;
38+
39+ if ( Guid . TryParse ( objectId , out objectIdGuid ) )
3540 {
36- DisplayName = group . DisplayName ,
37- Id = new Guid ( group . ObjectId )
38- } ;
41+ adObj . Id = objectIdGuid ;
42+ }
43+ else
44+ {
45+ adObj . AdfsId = objectId ;
46+ }
47+
48+ return adObj ;
3949 }
4050
4151 public static PSADObject ToPSADObject ( this AADObject obj )
@@ -44,89 +54,95 @@ public static PSADObject ToPSADObject(this AADObject obj)
4454
4555 if ( obj . ObjectType == typeof ( User ) . Name )
4656 {
47- return new PSADUser ( )
57+ var adUser = new PSADUser ( )
4858 {
4959 DisplayName = obj . DisplayName ,
50- Id = new Guid ( obj . ObjectId ) ,
5160 Type = obj . ObjectType ,
5261 UserPrincipalName = obj . UserPrincipalName
5362 } ;
63+
64+ return AssignObjectId ( adUser , obj . ObjectId ) ;
5465 }
5566 else if ( obj . ObjectType == "Group" )
5667 {
57- return new PSADGroup ( )
68+ var adGroup = new PSADGroup ( )
5869 {
5970 DisplayName = obj . DisplayName ,
6071 Type = obj . ObjectType ,
61- Id = new Guid ( obj . ObjectId ) ,
6272 SecurityEnabled = obj . SecurityEnabled ,
6373 MailNickname = obj . Mail
6474 } ;
65-
75+ return AssignObjectId ( adGroup , obj . ObjectId ) ;
6676 }
6777 else if ( obj . ObjectType == typeof ( ServicePrincipal ) . Name )
6878 {
69- return new PSADServicePrincipal ( )
79+ var adSp = new PSADServicePrincipal ( )
7080 {
7181 DisplayName = obj . DisplayName ,
72- Id = new Guid ( obj . ObjectId ) ,
7382 Type = obj . ObjectType ,
7483 ServicePrincipalNames = obj . ServicePrincipalNames . ToArray ( )
7584 } ;
85+
86+ return AssignObjectId ( adSp , obj . ObjectId ) ;
7687 }
7788 else
7889 {
79- return new PSADObject ( )
90+ var adObj = new PSADObject ( )
8091 {
8192 DisplayName = obj . DisplayName ,
82- Id = new Guid ( obj . ObjectId ) ,
8393 Type = obj . ObjectType
8494 } ;
95+
96+ return AssignObjectId ( adObj , obj . ObjectId ) ;
8597 }
8698 }
8799
88100 public static PSADObject ToPSADGroup ( this AADObject obj )
89101 {
90- return new PSADObject ( )
102+ var adObj = new PSADObject ( )
91103 {
92104 DisplayName = obj . DisplayName ,
93- Id = new Guid ( obj . ObjectId )
94105 } ;
106+
107+ return AssignObjectId ( adObj , obj . ObjectId ) ;
95108 }
96109
97110 public static PSADUser ToPSADUser ( this User user )
98111 {
99- return new PSADUser ( )
112+ var adUser = new PSADUser ( )
100113 {
101114 DisplayName = user . DisplayName ,
102- Id = new Guid ( user . ObjectId ) ,
103115 UserPrincipalName = user . UserPrincipalName ,
104116 Type = user . ObjectType
105117 } ;
118+
119+ return ( PSADUser ) AssignObjectId ( adUser , user . ObjectId ) ;
106120 }
107121
108122 public static PSADGroup ToPSADGroup ( this ADGroup group )
109123 {
110- return new PSADGroup ( )
124+ var adGroup = new PSADGroup ( )
111125 {
112126 DisplayName = group . DisplayName ,
113- Id = new Guid ( group . ObjectId ) ,
114127 SecurityEnabled = group . SecurityEnabled ,
115128 Type = group . ObjectType ,
116129 MailNickname = group . Mail
117130 } ;
131+
132+ return ( PSADGroup ) AssignObjectId ( adGroup , group . ObjectId ) ;
118133 }
119134
120135 public static PSADServicePrincipal ToPSADServicePrincipal ( this ServicePrincipal servicePrincipal )
121136 {
122- return new PSADServicePrincipal ( )
137+ var adSp = new PSADServicePrincipal ( )
123138 {
124139 DisplayName = servicePrincipal . DisplayName ,
125- Id = new Guid ( servicePrincipal . ObjectId ) ,
126140 ApplicationId = Guid . Parse ( servicePrincipal . AppId ) ,
127141 ServicePrincipalNames = servicePrincipal . ServicePrincipalNames . ToArray ( ) ,
128142 Type = servicePrincipal . ObjectType
129143 } ;
144+
145+ return ( PSADServicePrincipal ) AssignObjectId ( adSp , servicePrincipal . ObjectId ) ;
130146 }
131147
132148 public static PSADApplication ToPSADApplication ( this Application application )
0 commit comments