Search This Blog

Wednesday, July 9, 2014

Powershell scripts to delete sharepoint List Items

if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null) { Add-PSSnapin "Microsoft.SharePoint.PowerShell" } # "Enter the site URL instead http://serverurl" $SITEURL = "http://arwqa.grouphc.net/" $site = new-object Microsoft.SharePoint.SPSite ( $SITEURL ) $web = $site.OpenWeb() "Web is : " + $web.Title # Enter name of the List below insted of LIST NAME $oList = $web.Lists["ARWAdjInvoice"]; $query=new-object Microsoft.SharePoint.SPQuery $query.ViewAttributes = "Scope='Recursive'" $items=$oList.GetItems($query) "List is :" + $oList.Title + " with item count " + $oList.ItemCount $collListItems = $oList.Items; $count = $collListItems.Count - 1 for($intIndex = $count; $intIndex -gt -1; $intIndex--) { "Deleting record: " + $intIndex $collListItems.Delete($intIndex); } # Enter name of the List below insted of LIST NAME $oList = $web.Lists["ARWAdjProductCode"]; "List is :" + $oList.Title + " with item count " + $oList.ItemCount $collListItems = $oList.Items; $count = $collListItems.Count - 1 for($intIndex = $count; $intIndex -gt -1; $intIndex--) { "Deleting record: " + $intIndex $collListItems.Delete($intIndex); } #DEleting folders $query = New-Object Microsoft.SharePoint.SPQuery $camlQuery = 'Folder' $query.Query = $camlQuery $items = $oList.GetItems($query) Write-Host("DELETED FILE: " + $count) for ($intIndex = $items.Count - 1; $intIndex -gt -1; $intIndex--) { $items.Delete($intIndex); Write-Host("DELETED Folder: " + $intIndex) } # Enter name of the List below insted of LIST NAME $oList = $web.Lists["ARWCreditDebitOrder"]; "List is :" + $oList.Title + " with item count " + $oList.ItemCount $collListItems = $oList.Items; $count = $collListItems.Count - 1 for($intIndex = $count; $intIndex -gt -1; $intIndex--) { "Deleting record: " + $intIndex $collListItems.Delete($intIndex); } #DEleting folders $query = New-Object Microsoft.SharePoint.SPQuery $camlQuery = 'Folder' $query.Query = $camlQuery $items = $oList.GetItems($query) Write-Host("DELETED FILE: " + $count) for ($intIndex = $items.Count - 1; $intIndex -gt -1; $intIndex--) { $items.Delete($intIndex); Write-Host("DELETED Folder: " + $intIndex) } # Enter name of the List below insted of LIST NAME $oList = $web.Lists["ARWDisputeInvoice"]; "List is :" + $oList.Title + " with item count " + $oList.ItemCount $collListItems = $oList.Items; $count = $collListItems.Count - 1 for($intIndex = $count; $intIndex -gt -1; $intIndex--) { "Deleting record: " + $intIndex $collListItems.Delete($intIndex); } # Enter name of the List below insted of LIST NAME $oList = $web.Lists["ARWDrafts"]; "List is :" + $oList.Title + " with item count " + $oList.ItemCount $collListItems = $oList.Items; $count = $collListItems.Count - 1 for($intIndex = $count; $intIndex -gt -1; $intIndex--) { "Deleting record: " + $intIndex $collListItems.Delete($intIndex); } #DEleting folders $query = New-Object Microsoft.SharePoint.SPQuery $camlQuery = 'Folder' $query.Query = $camlQuery $items = $oList.GetItems($query) Write-Host("DELETED FILE: " + $count) for ($intIndex = $items.Count - 1; $intIndex -gt -1; $intIndex--) { $items.Delete($intIndex); Write-Host("DELETED Folder: " + $intIndex) } # Enter name of the List below insted of LIST NAME $oList = $web.Lists["ARWErrorReason"]; "List is :" + $oList.Title + " with item count " + $oList.ItemCount $collListItems = $oList.Items; $count = $collListItems.Count - 1 for($intIndex = $count; $intIndex -gt -1; $intIndex--) { "Deleting record: " + $intIndex $collListItems.Delete($intIndex); } # Enter name of the List below insted of LIST NAME $oList = $web.Lists["ARWInvoiceNewCustomer"]; "List is :" + $oList.Title + " with item count " + $oList.ItemCount $collListItems = $oList.Items; $count = $collListItems.Count - 1 for($intIndex = $count; $intIndex -gt -1; $intIndex--) { "Deleting record: " + $intIndex $collListItems.Delete($intIndex); } #DEleting folders $query = New-Object Microsoft.SharePoint.SPQuery $camlQuery = 'Folder' $query.Query = $camlQuery $items = $oList.GetItems($query) Write-Host("DELETED FILE: " + $count) for ($intIndex = $items.Count - 1; $intIndex -gt -1; $intIndex--) { $items.Delete($intIndex); Write-Host("DELETED Folder: " + $intIndex) } # Enter name of the List below insted of LIST NAME $oList = $web.Lists["ARWInvoiceNewCustomerProductCode"]; "List is :" + $oList.Title + " with item count " + $oList.ItemCount $collListItems = $oList.Items; $count = $collListItems.Count - 1 for($intIndex = $count; $intIndex -gt -1; $intIndex--) { "Deleting record: " + $intIndex $collListItems.Delete($intIndex); } #DEleting folders $query = New-Object Microsoft.SharePoint.SPQuery $camlQuery = 'Folder' $query.Query = $camlQuery $items = $oList.GetItems($query) Write-Host("DELETED FILE: " + $count) for ($intIndex = $items.Count - 1; $intIndex -gt -1; $intIndex--) { $items.Delete($intIndex); Write-Host("DELETED Folder: " + $intIndex) } # Enter name of the List below insted of LIST NAME $oList = $web.Lists["ARWJDEFailureTickets"]; "List is :" + $oList.Title + " with item count " + $oList.ItemCount $collListItems = $oList.Items; $count = $collListItems.Count - 1 for($intIndex = $count; $intIndex -gt -1; $intIndex--) { "Deleting record: " + $intIndex $collListItems.Delete($intIndex); } #DEleting folders $query = New-Object Microsoft.SharePoint.SPQuery $camlQuery = 'Folder' $query.Query = $camlQuery $items = $oList.GetItems($query) Write-Host("DELETED FILE: " + $count) for ($intIndex = $items.Count - 1; $intIndex -gt -1; $intIndex--) { $items.Delete($intIndex); Write-Host("DELETED Folder: " + $intIndex) } # Enter name of the List below insted of LIST NAME $oList = $web.Lists["ARWK2Rules"]; "List is :" + $oList.Title + " with item count " + $oList.ItemCount $collListItems = $oList.Items; $count = $collListItems.Count - 1 for($intIndex = $count; $intIndex -gt -1; $intIndex--) { "Deleting record: " + $intIndex $collListItems.Delete($intIndex); } # Enter name of the List below insted of LIST NAME $oList = $web.Lists["ARWNote"]; "List is :" + $oList.Title + " with item count " + $oList.ItemCount $collListItems = $oList.Items; $count = $collListItems.Count - 1 for($intIndex = $count; $intIndex -gt -1; $intIndex--) { "Deleting record: " + $intIndex $collListItems.Delete($intIndex); } #DEleting folders $query = New-Object Microsoft.SharePoint.SPQuery $camlQuery = 'Folder' $query.Query = $camlQuery $items = $oList.GetItems($query) Write-Host("DELETED FILE: " + $count) for ($intIndex = $items.Count - 1; $intIndex -gt -1; $intIndex--) { $items.Delete($intIndex); Write-Host("DELETED Folder: " + $intIndex) } # Enter name of the List below insted of LIST NAME $oList = $web.Lists["ARWReasonCode"]; "List is :" + $oList.Title + " with item count " + $oList.ItemCount $collListItems = $oList.Items; $count = $collListItems.Count - 1 for($intIndex = $count; $intIndex -gt -1; $intIndex--) { "Deleting record: " + $intIndex $collListItems.Delete($intIndex); } #DEleting folders $query = New-Object Microsoft.SharePoint.SPQuery $camlQuery = 'Folder' $query.Query = $camlQuery $items = $oList.GetItems($query) Write-Host("DELETED FILE: " + $count) for ($intIndex = $items.Count - 1; $intIndex -gt -1; $intIndex--) { $items.Delete($intIndex); Write-Host("DELETED Folder: " + $intIndex) } # Enter name of the List below insted of LIST NAME $oList = $web.Lists["ARWRecordCorrections"]; "List is :" + $oList.Title + " with item count " + $oList.ItemCount $collListItems = $oList.Items; $count = $collListItems.Count - 1 for($intIndex = $count; $intIndex -gt -1; $intIndex--) { "Deleting record: " + $intIndex $collListItems.Delete($intIndex); } # Enter name of the List below insted of LIST NAME $oList = $web.Lists["ARWReinvoiceProductCode"]; "List is :" + $oList.Title + " with item count " + $oList.ItemCount $collListItems = $oList.Items; $count = $collListItems.Count - 1 for($intIndex = $count; $intIndex -gt -1; $intIndex--) { "Deleting record: " + $intIndex $collListItems.Delete($intIndex); } #DEleting folders $query = New-Object Microsoft.SharePoint.SPQuery $camlQuery = 'Folder' $query.Query = $camlQuery $items = $oList.GetItems($query) Write-Host("DELETED FILE: " + $count) for ($intIndex = $items.Count - 1; $intIndex -gt -1; $intIndex--) { $items.Delete($intIndex); Write-Host("DELETED Folder: " + $intIndex) } # Enter name of the List below insted of LIST NAME $oList = $web.Lists["ARWReinvoiceSameCustomer"]; "List is :" + $oList.Title + " with item count " + $oList.ItemCount $collListItems = $oList.Items; $count = $collListItems.Count - 1 for($intIndex = $count; $intIndex -gt -1; $intIndex--) { "Deleting record: " + $intIndex $collListItems.Delete($intIndex); } # Enter name of the List below insted of LIST NAME $oList = $web.Lists["ARWSalesinformation"]; "List is :" + $oList.Title + " with item count " + $oList.ItemCount $collListItems = $oList.Items; $count = $collListItems.Count - 1 for($intIndex = $count; $intIndex -gt -1; $intIndex--) { "Deleting record: " + $intIndex $collListItems.Delete($intIndex); } #DEleting folders $query = New-Object Microsoft.SharePoint.SPQuery $camlQuery = 'Folder' $query.Query = $camlQuery $items = $oList.GetItems($query) Write-Host("DELETED FILE: " + $count) for ($intIndex = $items.Count - 1; $intIndex -gt -1; $intIndex--) { $items.Delete($intIndex); Write-Host("DELETED Folder: " + $intIndex) } # Enter name of the List below insted of LIST NAME $oList = $web.Lists["ARWStatusCode"]; "List is :" + $oList.Title + " with item count " + $oList.ItemCount $collListItems = $oList.Items; $count = $collListItems.Count - 1 for($intIndex = $count; $intIndex -gt -1; $intIndex--) { "Deleting record: " + $intIndex $collListItems.Delete($intIndex); } #DEleting folders $query = New-Object Microsoft.SharePoint.SPQuery $camlQuery = 'Folder' $query.Query = $camlQuery $items = $oList.GetItems($query) Write-Host("DELETED FILE: " + $count) for ($intIndex = $items.Count - 1; $intIndex -gt -1; $intIndex--) { $items.Delete($intIndex); Write-Host("DELETED Folder: " + $intIndex) } # Enter name of the List below insted of LIST NAME $oList = $web.Lists["ARWTicketHistory"]; "List is :" + $oList.Title + " with item count " + $oList.ItemCount $collListItems = $oList.Items; $count = $collListItems.Count - 1 for($intIndex = $count; $intIndex -gt -1; $intIndex--) { "Deleting record: " + $intIndex $collListItems.Delete($intIndex); } #DEleting folders $query = New-Object Microsoft.SharePoint.SPQuery $camlQuery = 'Folder' $query.Query = $camlQuery $items = $oList.GetItems($query) Write-Host("DELETED FILE: " + $count) for ($intIndex = $items.Count - 1; $intIndex -gt -1; $intIndex--) { $items.Delete($intIndex); Write-Host("DELETED Folder: " + $intIndex) }

No comments:

Post a Comment