Hi @sravya shivapuram ,
According to my research and testing, you can try to use the following CSOM script to get all deleted sites in SharePoint Online:
private class Configuration
{
public static string ServiceSiteUrl = "https://xxxxx.sharepoint.com";
public static string ServiceUserName = "xxxx@xxxxxx.onmicrosoft.com";
public static string ServicePassword = "xxxxxxx";
}
static ClientContext GetonlineContext()
{
var securePassword = new SecureString();
foreach (char c in Configuration.ServicePassword)
{
securePassword.AppendChar(c);
}
var onlineCredentials = new SharePointOnlineCredentials(Configuration.ServiceUserName, securePassword);
var context = new ClientContext(Configuration.ServiceSiteUrl);
context.Credentials = onlineCredentials;
return context;
}
static void Main(string[] args)
{
var clientContext = GetonlineContext();
Web web = clientContext.Web;
var tenant = new Tenant(clientContext);
var deletedSites = tenant.GetDeletedSitePropertiesFromSharePoint("0");
clientContext.Load(deletedSites, c => c.IncludeWithDefaultProperties(s => s.Url, s => s.SiteId, s => s.DaysRemaining, s => s.Status));
clientContext.ExecuteQueryRetry();
// loop through sites
foreach(var site in deletedSites)
{
Debug.WriteLine(site.Url);
}
}
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.