@@ -27,55 +27,58 @@ public class SetHomeSite : PnPSharePointOnlineAdminCmdlet
27
27
protected override void ExecuteCmdlet ( )
28
28
{
29
29
Tenant . EnsureProperties ( t => t . IsMultipleVivaConnectionsFlightEnabled , t => t . IsVivaHomeFlightEnabled ) ;
30
+ HomeSiteConfigurationParam configurationParam ;
31
+
32
+ bool hasVivaConnectionsDefaultStart = ParameterSpecified ( nameof ( VivaConnectionsDefaultStart ) ) ;
33
+ bool hasDraftMode = ParameterSpecified ( nameof ( DraftMode ) ) ;
34
+
35
+ // Replace the current configurationParam assignment block with the following:
36
+
37
+ configurationParam = null ;
38
+ if ( hasVivaConnectionsDefaultStart || hasDraftMode )
39
+ {
40
+ configurationParam = new ( ) ;
41
+ if ( hasVivaConnectionsDefaultStart )
42
+ {
43
+ configurationParam . vivaConnectionsDefaultStart = VivaConnectionsDefaultStart ;
44
+ configurationParam . IsVivaConnectionsDefaultStartPresent = true ;
45
+ }
46
+ if ( hasDraftMode )
47
+ {
48
+ configurationParam . isInDraftMode = DraftMode ;
49
+ configurationParam . IsInDraftModePresent = true ;
50
+ }
51
+ }
30
52
31
53
if ( Tenant . IsMultipleVivaConnectionsFlightEnabled )
32
54
{
33
55
if ( Force || ShouldContinue ( "Before you update a home site or Viva Connections experiences, make sure you review the documentation at https://aka.ms/homesites." , Properties . Resources . Confirm ) )
34
56
{
35
57
IEnumerable < TargetedSiteDetails > enumerable = Tenant . GetTargetedSitesDetails ( ) ? . Where ( ( TargetedSiteDetails hs ) => ! hs . IsVivaBackendSite ) ;
36
58
AdminContext . ExecuteQueryRetry ( ) ;
37
- bool flag = false ;
38
59
if ( enumerable == null || enumerable . Count ( ) == 0 )
39
60
{
40
61
Tenant . AddHomeSite ( HomeSiteUrl , 1 , null ) ;
41
62
AdminContext . ExecuteQueryRetry ( ) ;
42
- flag = true ;
43
63
}
44
64
else if ( enumerable . Count ( ) == 1 && ! IsSameSiteUrl ( enumerable . First ( ) . Url , HomeSiteUrl ) )
45
65
{
46
66
Tenant . RemoveTargetedSite ( enumerable . First ( ) . SiteId ) ;
47
67
AdminContext . ExecuteQueryRetry ( ) ;
48
68
Tenant . AddHomeSite ( HomeSiteUrl , 1 , null ) ;
49
69
AdminContext . ExecuteQueryRetry ( ) ;
50
- flag = true ;
51
70
}
52
- HomeSiteConfigurationParam configurationParam = new ( )
53
- {
54
- vivaConnectionsDefaultStart = VivaConnectionsDefaultStart ,
55
- IsVivaConnectionsDefaultStartPresent = VivaConnectionsDefaultStart ,
56
- isInDraftMode = DraftMode ,
57
- IsInDraftModePresent = DraftMode || flag
58
- } ;
71
+
59
72
ClientResult < TargetedSiteDetails > clientResult = Tenant . UpdateTargetedSite ( HomeSiteUrl , configurationParam ) ;
73
+
60
74
AdminContext . ExecuteQueryRetry ( ) ;
61
75
WriteObject ( clientResult . Value ) ;
62
76
}
63
77
}
64
78
else if ( Force || ShouldContinue ( "Before you set a Home site, make sure you review the documentation at https://aka.ms/homesites." , Properties . Resources . Confirm ) )
65
79
{
66
80
Tenant . ValidateVivaHomeParameterExists ( VivaConnectionsDefaultStart ) ;
67
- HomeSiteConfigurationParam configuration = null ;
68
- if ( VivaConnectionsDefaultStart || DraftMode )
69
- {
70
- configuration = new HomeSiteConfigurationParam
71
- {
72
- vivaConnectionsDefaultStart = VivaConnectionsDefaultStart ,
73
- IsVivaConnectionsDefaultStartPresent = VivaConnectionsDefaultStart ,
74
- isInDraftMode = DraftMode ,
75
- IsInDraftModePresent = DraftMode
76
- } ;
77
- }
78
- ClientResult < string > clientResult = Tenant . SetSPHSiteWithConfiguration ( HomeSiteUrl , configuration ) ;
81
+ ClientResult < string > clientResult = Tenant . SetSPHSiteWithConfiguration ( HomeSiteUrl , configurationParam ) ;
79
82
AdminContext . ExecuteQueryRetry ( ) ;
80
83
WriteObject ( clientResult . Value ) ;
81
84
}
0 commit comments