![delete history one drive microsoft delete history one drive microsoft](https://gyorgybalassy.files.wordpress.com/2018/11/site-settings-menu_thumb.png)
We can then enter and pick an account with rights to grant permission: Figure 7: Entering the code and the account that grants access for the PnP module in a tenant. Running these cmdlets will display a one-time passcode to enter into. If we do not grant consent for the app, an error like this will be displayed:Ĭonnect - PnPOnline - Url $ Url - PnPManagementShell Then the script shows the files to review and/or remove using the Out-GridView cmdlet: Figure 5: Out-Grid view displaying the contents of the variable storing all files detected for a single OneDrive.Īfter selecting some files, we can decide to remove or not remove the files, below are some examples: Figure 6: Shows an operator choosing to confirm removal of a file and also decide to not delete another file.īefore you can run the script, you need to consent to using the PnP PowerShell Module because it uses OAuth authentication. We are also asked for the results CSV file that we downloaded from the search.
![delete history one drive microsoft delete history one drive microsoft](https://support.content.office.net/en-us/media/417698d9-5957-4ac3-8bff-d76d3da9905c.png)
When we run the script, the first thing is to connect to the target tenant. After downloading the CSV file and processing its contents, we can use it as a basis for removing files. Now that we have examined some important code sections, let’s review the overall process for the file removal. These two tasks can be completed with the below script: Once connected we grant site collection admin permission. To remove files from a user’s OneDrive account, we need to connect directly to their OneDrive URL (in the CSV file). Steps 1-6 continue until the last user is detected (last line of the CSV file).After a user’s files are processed, the Foreach loop moves on to the next user.Step 3 – Allow the operator to not delete the file (are you sure? option) Step 2 – Use the output from Out-GridView to start removing files.Ĭ. Step 1 – Display files with Out-GridViewī. When a change of user is detected, the current file list takes these steps.Ī.While connected, the ID of the file is queried and stored as it is needed to identify the file for removal.Once permission is granted, a connection is made to the user’s OneDrive account.Permissions are granted for the script operator (Site Collection Admin) for the script to perform its tasks.The Foreach loop groups each line for a single user into a variable.Overall, the steps in the script we will operate are: First, the loop is a foreach loop, where each line is read separately, and actions are taken within each loop. We use some rules to process data as we loop through the items in the file. Once connected, we can begin processing the CSV file. Finally, sort the $Table variable by User and store the results in a variable called $SortedResults:Ĭonnect - SPOService - Url $ SharePointURL - Credential $ Credentials In the code below we ask for the CSV file name, pull key elements (User and File) from the input file and store this data in a variable called $Table. The export file is not sorted or in a format that we can use, so first need to process the data to generate something more usable. Our downloaded CSV file is in a format like that shown below: Figure 4: Sample CSV File from our keyword search. Now, I’m going to highlight some important parts.
Delete history one drive microsoft full#
The full script is available to download here from GitHub. We use cmdlets from the SharePoint Online and PNP PowerShell modules to perform OneDrive file operations with the permissions needed to execute these tasks. To do this, we use PowerShell to group the files by user OneDrive address and allow the reviewer to select one, some, all, or none of the files for removal. The next task is to present the export data from the CSV file in a useable fashion. Reviewing Findings and Selective OneDrive Removal Now that the search is completed and report downloaded, we can utilize that CSV file to determine which OneDrive files to delete. Once the report is exported, we can download the CSV file generated: Figure 2: Click on Download report to retrieve the generated CSV file.ĭownloading the report requires a key (Figure 3), which can be copied from the search details and pasted into the Microsoft Export utility: Figure 3: Downloading the report requires a key. Once you are happy that the search finds the right items, generate a report of the results by selecting ‘Export Report’: Figure 1: Select the ‘Export Report’ option to generate and produce a report. Once the search completes, we can examine the preview results. Depending on the number of search locations, this could take some time to complete. The search starts and creates a preview set of results. Enter “Exchange” as a keyword for the search and choose the target OneDrive search locations. In the Microsoft 365 Compliance Center, go to the Content search section and create a new search. Reviewing Findings and Selective OneDrive Removalįirst, we need to run a Content Search.