Esempio n. 1
0
        protected override void ExecuteCmdlet()
        {
            if (!string.IsNullOrEmpty(Url))
            {
                var list = Tenant.GetSitePropertiesByUrl(Url, Detailed);
                list.Context.Load(list);
                list.Context.ExecuteQueryRetry();
                WriteObject(list, true);
            }
            else
            {
#if !ONPREMISES
                SPOSitePropertiesEnumerableFilter filter = new SPOSitePropertiesEnumerableFilter()
                {
                    IncludePersonalSite = IncludeOneDriveSites.IsPresent ? PersonalSiteFilter.Include : PersonalSiteFilter.UseServerDefault,
                    IncludeDetail       = Detailed,
#pragma warning disable CS0618 // Type or member is obsolete
                    Template = Template ?? WebTemplate,
#pragma warning restore CS0618 // Type or member is obsolete
                    Filter = Filter,
                };
#endif
                SPOSitePropertiesEnumerable sitesList = null;
                var sites = new List <SiteProperties>();
#if !ONPREMISES
                do
                {
                    sitesList = Tenant.GetSitePropertiesFromSharePointByFilters(filter);
                    Tenant.Context.Load(sitesList);
                    Tenant.Context.ExecuteQueryRetry();
                    sites.AddRange(sitesList.ToList());
                    filter.StartIndex = sitesList.NextStartIndexFromSharePoint;
                } while (!string.IsNullOrWhiteSpace(sitesList.NextStartIndexFromSharePoint));
#else
                sitesList = Tenant.GetSiteProperties(0, Detailed);
                Tenant.Context.Load(sitesList);
                Tenant.Context.ExecuteQueryRetry();
                sites.AddRange(sitesList.ToList());
#endif

#if !ONPREMISES
                if (Template != null)
                {
                    WriteObject(sites.Where(t => t.Template == Template).OrderBy(x => x.Url), true);
                }
                else
                {
                    WriteObject(sites.OrderBy(x => x.Url), true);
                }
#else
                WriteObject(sites.OrderBy(x => x.Url), true);
#endif
            }
        }
Esempio n. 2
0
        protected override void ExecuteCmdlet()
        {
            if (SPOnlineConnection.CurrentConnection.ConnectionType == ConnectionType.OnPrem)
            {
                WriteObject(ClientContext.Site);
            }
            else
            {
                if (!string.IsNullOrEmpty(Url))
                {
                    var list = Tenant.GetSitePropertiesByUrl(Url, Detailed);
                    list.Context.Load(list);
                    list.Context.ExecuteQueryRetry();
                    WriteObject(list, true);
                }
                else
                {
                    SPOSitePropertiesEnumerableFilter filter = null;
                    if (IncludeOneDriveSites || WebTemplate != null || Filter != null)
                    {
                        filter = new SPOSitePropertiesEnumerableFilter()
                        {
                            IncludePersonalSite = IncludeOneDriveSites.IsPresent ? PersonalSiteFilter.Include : PersonalSiteFilter.UseServerDefault,
                            StartIndex          = "0",
                            IncludeDetail       = Detailed,
                            Template            = WebTemplate,
                            Filter = Filter,
                        };
                    }

                    SPOSitePropertiesEnumerable list = null;
                    var sites = new List <SiteProperties>();
                    do
                    {
                        list = filter == null?Tenant.GetSiteProperties(list?.NextStartIndex ?? 0, Detailed) : Tenant.GetSitePropertiesFromSharePointByFilters(filter);

                        Tenant.Context.Load(list);
                        Tenant.Context.ExecuteQueryRetry();
                        sites.AddRange(list.ToList());
                        if (filter != null)
                        {
                            filter.StartIndex = list.NextStartIndex.ToString();
                        }
                    } while (list.NextStartIndex > 0);

                    if (Template != null)
                    {
                        WriteObject(sites.Where(t => t.Template == Template).OrderBy(x => x.Url), true);
                    }
                    else
                    {
                        WriteObject(sites.OrderBy(x => x.Url), true);
                    }
                }
            }
        }
Esempio n. 3
0
        protected override void ExecuteCmdlet()
        {
            if (!string.IsNullOrEmpty(Url))
            {
                var siteProperties = Tenant.GetSitePropertiesByUrl(Url, Detailed);
                ClientContext.Load(siteProperties);
                ClientContext.ExecuteQueryRetry();
                Model.SPOSite site = null;
                if (ParameterSpecified(nameof(DisableSharingForNonOwnersStatus)))
                {
                    var office365Tenant = new Office365Tenant(ClientContext);
                    var clientResult    = office365Tenant.IsSharingDisabledForNonOwnersOfSite(Url);
                    ClientContext.ExecuteQuery();
                    site = new Model.SPOSite(siteProperties, clientResult.Value);
                }
                else
                {
                    site = new Model.SPOSite(siteProperties, null);
                }
                WriteObject(site, true);
            }
            else
            {
                SPOSitePropertiesEnumerableFilter filter = new SPOSitePropertiesEnumerableFilter()
                {
                    IncludePersonalSite = IncludeOneDriveSites.IsPresent ? PersonalSiteFilter.Include : PersonalSiteFilter.UseServerDefault,
                    IncludeDetail       = Detailed,
#pragma warning disable CS0618 // Type or member is obsolete
                    Template = Template,
#pragma warning restore CS0618 // Type or member is obsolete
                    Filter = Filter,
                };
                SPOSitePropertiesEnumerable sitesList = null;
                var sites = new List <SiteProperties>();
                do
                {
                    sitesList = Tenant.GetSitePropertiesFromSharePointByFilters(filter);
                    Tenant.Context.Load(sitesList);
                    Tenant.Context.ExecuteQueryRetry();
                    sites.AddRange(sitesList.ToList());
                    filter.StartIndex = sitesList.NextStartIndexFromSharePoint;
                } while (!string.IsNullOrWhiteSpace(sitesList.NextStartIndexFromSharePoint));

                if (Template != null)
                {
                    WriteObject(sites.Where(t => t.Template == Template).OrderBy(x => x.Url), true);
                }
                else
                {
                    WriteObject(sites.OrderBy(x => x.Url), true);
                }
            }
        }
Esempio n. 4
0
        protected override void ExecuteCmdlet()
        {
            ClientContext.ExecuteQueryRetry();
            if (ParameterSpecified(nameof(Identity)))
            {
                var siteProperties = Tenant.GetSitePropertiesByUrl(Identity.Url, Detailed);
                ClientContext.Load(siteProperties);
                ClientContext.ExecuteQueryRetry();
                Model.SPOSite site = null;
                if (ParameterSpecified(nameof(DisableSharingForNonOwnersStatus)))
                {
                    var office365Tenant = new Office365Tenant(ClientContext);
                    var clientResult    = office365Tenant.IsSharingDisabledForNonOwnersOfSite(Identity.Url);
                    ClientContext.ExecuteQuery();
                    site = new Model.SPOSite(siteProperties, clientResult.Value);
                }
                else
                {
                    site = new Model.SPOSite(siteProperties, null);
                }
                WriteObject(site, true);
            }
            else
            {
                SPOSitePropertiesEnumerableFilter filter = new SPOSitePropertiesEnumerableFilter()
                {
                    IncludePersonalSite = IncludeOneDriveSites.IsPresent ? PersonalSiteFilter.Include : PersonalSiteFilter.UseServerDefault,
                    IncludeDetail       = Detailed,
#pragma warning disable CS0618 // Type or member is obsolete
                    Template = Template,
#pragma warning restore CS0618 // Type or member is obsolete
                    Filter = Filter,
                };

                if (ClientContext.ServerVersion >= new Version(16, 0, 7708, 1200))
                {
                    if (ParameterSpecified(nameof(GroupIdDefined)))
                    {
                        filter.GroupIdDefined = GroupIdDefined.Value == true ? 1 : 2;
                    }
                }
                else if (ParameterSpecified(nameof(GroupIdDefined)))
                {
                    throw new PSArgumentException("Filtering by Group Id is not yet available for this tenant.");
                }

                SPOSitePropertiesEnumerable sitesList = null;
                var sites = new List <SiteProperties>();
                do
                {
                    sitesList = Tenant.GetSitePropertiesFromSharePointByFilters(filter);
                    Tenant.Context.Load(sitesList);
                    Tenant.Context.ExecuteQueryRetry();
                    sites.AddRange(sitesList.ToList());
                    filter.StartIndex = sitesList.NextStartIndexFromSharePoint;
                } while (!string.IsNullOrWhiteSpace(sitesList.NextStartIndexFromSharePoint));

                if (Template != null)
                {
                    WriteObject(sites.Where(t => t.Template == Template).OrderBy(x => x.Url).Select(s => new Model.SPOSite(s, null)), true);
                }
                else
                {
                    WriteObject(sites.OrderBy(x => x.Url).Select(s => new Model.SPOSite(s, null)), true);
                }
            }
        }