Enhance `spo site list` to return archived sites
Idea
Let's enhance the command spo site list to return sites that are archived using spo site archive.
The idea is to expand option --type [type] with extra options: fullyArchived, recentlyArchived, and archived.
Let's make sure that we use the same API that is currently being used. The output of the command cannot alter.
Remarks
(Include these remarks in the docs to make it clearer)
When providing a value for option type, consider the following:
-
fullyArchived: return sites that are fully archived (longer than 7 days) -
recentlyArchived: return sites that are recently archived (within 7 days) -
archived: return both recently archived and fully archived sites
@pnp/cli-for-microsoft-365-maintainers, I'm not really sure about the name of the command. Currently, we already have:
-
spo tenant site archive -
spo tenant site unarchive
@pnp/cli-for-microsoft-365-maintainers, I'm not really sure about the name of the command. Currently, we already have:
TBH I don't have any different suggestions. For me the name is fine and explains exactly what is going to be done.
I want to list archive sites on my tenant -> tenant archivesite list
Hi guys,
Wouldn't it be nicer if we put this functionality with spo site list, for example like:
Get active sites
m365 spo site list
# or
m365 spo site list --state active
Get archived sites
m365 spo site list --archived
# or
m365 spo site list --state archived
Get deleted sites
m365 spo site list --deleted
# or
m365 spo site list --state deleted
The admin portal uses /_api/SPO.Tenant/RenderAdminListData for all variants
@milanholemans? @Adam-it? @pnp/cli-for-microsoft-365-maintainers, just pinging you guys here :-)
How does the response of the underlying API for this command compare to the current output of spo site list? If it's different, then I suggest that we put it in a different command to avoid confusion of returning different shapes for different arguments. If the output is the same, then we could consider consolidating.
Great suggestions @martinlingstuyl with --disabled and --archived
The output looks different using this API. However, we might be able to add some filters to the spo site list API to retrieve archived sites.
About deleted sites, usually we create a recyclebinitem command to list these.
@milanholemans, I tried out the request you mention in the issue:
POST https://contoso-admin.sharepoint.com/_api/SPO.Tenant/GetSitesByState
{
"states": [6, 15]
}
However, that does not return sites for me. Also no archived sites. If I use state value 1 I get all sites returned, including the archived sites.
It seems that the archived status of a site can not be deduced from the state property. At least on my tenant. So how did you get to this conclusion? The API response does contain a "ArchiveStatus": "Archived" property though.
So this endpoint seems to return the same shape of data for archived sites as well as for active sites, which is a nice pointer to the possibility that we could include this behavior in the spo site list command itself, using a --archived or --state archived option for example.
In the spo site list command we use a CSOM call instead of a REST API call. But if I look at the response from that API, it actually also returns my Archived sites, with the same shape as active sites as far as I can see, and it has nice additional properties like ArchiveStatus, ArchivedTime and ArchivedBy.
Long story short: I suggest it is a better route to add an option to the existing spo site list command and get a list of active sites / archived sites in that way.
What do you think?
Hi @martinlingstuyl,
If I'm not mistaken, it was from a browser request. Looking at it again, it seems like this request only returns recently archived sites and not the actual archived ones. Back then when I wrote this spec, I didn't have a site that was fully archived. Thanks for rechecking.
It seems like there is a list /Lists/DO_NOT_DELETE_SPLIST_TENANTADMIN_ARCHIVE_SITES_AGG that we might be able to use.
But as mentioned in my previous comment, I think we're possible to use the spo site list API as well, so I'm ok with enhancing that command instead.
Would something like the example below work for you?
m365 spo site list --type archived
I was thinking maybe about providing 3 values:
-
fullyArchived: return sites that are fully archived (longer than 7 days) -
recentlyArchived: return sites that are recently archived (within 7 days) -
archived: return both recently archived and fully archived sites
Hi @milanholemans, that last idea seems nice to me! This way we would have a very nice feature to load archived sites in an easily discoverable way.
I'll try to respec the issue soon.
Could you do another review @pnp/cli-for-microsoft-365-maintainers?
I love it @milanholemans, let's ship it!
Hi @milanholemans, @MathijsVerbeeck,
I'm rechecking the specs here.
for the value of type, allowed values are now TeamSite,CommunicationSite,fullyArchived,recentlyArchived,archived.
but what if we want all archived Teamsites? or all archived communicationsites?
Wouldn't it be better to put the options fullyArchived,recentlyArchived,archived in a new option, something like state? And should it not also contain an allowed value to be able to list ACTIVE sites, as opposed to archived sites..
Just reopening the discussion here, as I think it's better to catch this before it's in the codebase and it becomes a breaking change to update it.
Well, fullyArchived etc is not really a site type. So I agree with the part of creating a new option. Would it mean that you can specify both type and state to filter even on fully archived team sites for example?
Well,
fullyArchivedetc is not really a site type. So I agree with the part of creating a new option. Would it mean that you can specify bothtypeandstateto filter even on fully archived team sites for example?
Yes, that would be great, wouldn't it?! :-)
@MathijsVerbeeck, would you be able to update the PR, using a state property?
So new specs:
| Option | Description |
|---|---|
-t, --type [type] |
convenience option for type of sites to list. Allowed values are TeamSite,CommunicationSite. |
--state [state] |
option to allow to list sites that are in several stages of being archived. Allowed values are active,fullyArchived,recentlyArchived,archived. |
@milanholemans, agreed on these specs? I did add an allowed value for listing active sites as well, that might be interesting in scripting scenario's where you push a value into the option, instead of having to remove/add the option alltogether.