static void Main(string[] args) { SecureString pwd = new SecureString(); string Username = args[0]; string password = args[1]; string url = args[2]; try { using (ClientContext ctx = new ClientContext(url)) { foreach (char c in password.ToArray()) { pwd.AppendChar(c); } ctx.Credentials = new SharePointOnlineCredentials(Username, pwd); RecycleBinItemCollection recycleBinItems = ctx.Site.GetRecycleBinItems("", 2000, false, RecycleBinOrderBy.DeletedDate, RecycleBinItemState.SecondStageRecycleBin); ctx.ExecuteQuery(); while (recycleBinItems != null) { ctx.Load(recycleBinItems); recycleBinItems.DeleteAll(); ctx.ExecuteQuery(); Console.WriteLine("items deleted"); } } } catch (Exception ex) { Console.WriteLine(ex); } Console.ReadLine(); }
protected override void ExecuteCmdlet() { switch (ParameterSetName) { case PARAMETERSET_IDENTITY: var recycleBinItem = Identity.GetRecycleBinItem(ClientContext.Site); if (Force || ShouldContinue(string.Format(Resources.ClearRecycleBinItem, recycleBinItem.LeafName), Resources.Confirm)) { recycleBinItem.DeleteObject(); ClientContext.ExecuteQueryRetry(); } break; case PARAMETERSET_ALL: if (ParameterSpecified(nameof(RowLimit))) { if (Force || ShouldContinue(SecondStageOnly ? Resources.ClearSecondStageRecycleBin : Resources.ClearBothRecycleBins, Resources.Confirm)) { RecycleBinItemState recycleBinStage = SecondStageOnly ? RecycleBinItemState.SecondStageRecycleBin : RecycleBinItemState.None; RecycleBinItemCollection items = ClientContext.Site.GetRecycleBinItems(null, RowLimit, false, RecycleBinOrderBy.DeletedDate, recycleBinStage); ClientContext.Load(items); ClientContext.ExecuteQueryRetry(); items.DeleteAll(); ClientContext.ExecuteQueryRetry(); } } else { if (SecondStageOnly) { if (Force || ShouldContinue(Resources.ClearSecondStageRecycleBin, Resources.Confirm)) { ClientContext.Site.RecycleBin.DeleteAllSecondStageItems(); ClientContext.ExecuteQueryRetry(); } } else { if (Force || ShouldContinue(Resources.ClearBothRecycleBins, Resources.Confirm)) { ClientContext.Site.RecycleBin.DeleteAll(); ClientContext.ExecuteQueryRetry(); } } } break; } }