Tuesday, February 18, 2020

How to search for Recycle Bin items in SharePoint online

Introduction: 

At times you may need to search for the recycle bin items in SharePoint online. Unfortunately there is no easy way to find the items in GUI, going to Site Contents --> Recycle Bin. However there is a way to export the recycle bin items to CSV using powershell. Good news is you do not need to have SPO admin or global admin rights to get this. Just a Site Collection Admin rights is required. A site collection admin can run this report. Let's get started.


Pre-requisites:  


  • At first you need to have PnP powershell command lets installed in your latest Powershell module. If you need the steps setting up Pnp, please refer to the link here from MSFT. 
  • You need to have Site Collection Admin to run this script. 

Steps: 

Please follow the below steps to get the report of recycle bin items based on parameters specified. 

Step1: Define the fields and initialize them.

Here i have created only site url and the user name where the users deleted items needs to be retrieved. 
$SiteURL = "URL OF YOUR SITE" #for instance https://www.contoso.com/sites/sales
Connecting to PnP online using the below script
$UserDisplayName = "DISPLAY NAME OF USER"

Step2: Connect to the site 

Run the below command to get connection to site
Connect-PnPOnline -Url $SiteURL -UseWebLogin 
#the reason to use weblogin parameter is that as in some scenarios, the MFA could be enabled for some users which is true in my case, it uses browser authentication and then establishes connection. 

Step3: Get all items from recycle bin

Run below command to get all items from recycle bin. Here i have selected only Title, DeletedByName, DeletedDate parameters only. You could also get more. Please refer to link for more details.  

$AllRecycleBinItems = Get-PnPRecycleBinItem | Select Title, DeletedByName, DeletedDate | Format-Table



Step4: Get only the items deleted by the user

You can filter from the all records using the below line of command. 

$DeletedByUser=$AllRecycyleBinItems | Where {$_.DeletedByName -eq $UserDisplayName}


Step5: Disconnect from the PnP connection

Run the below command to diconnect from the PnP established connection. 
Disconnect-PnPOnline

Complete Script: 

Below is the complete script copied from command shell. Please note that the fields $SiteURL and $DeletedByName is just for reference. The Display Name can be easily found either from SharePoint user properties or from Local AD properties, using ADUC controls. 

Note: This script is executed on PowerShell version 5.1.17763.771 in conjunction with PnP version 3.13.1909.0


$SiteURL = "https://contoso.com/sites/sales"
$DeletedByName = "UserFirstName UserLastName"
$FilePath = "PathToReportFile"

#connecting to site
Connect-PnPOnline -Url $SiteURL -UseWebLogin

#Getting all recycle bin items and storing in variable 
$AllRecycyleBinItems=Get-PnPRecycleBinItem | Select Title, DeletedByName, DeletedDate 

#Getting recycle bin items which are deleted by a specific user
$DeletedByUser=$AllRecycyleBinItems | Where {$_.DeletedByName -eq $DeletedByName} | Export-Csv -Path $FilePath

#To disconnect from PnP online
Disconnect-PnPOnline


Hope this is helpful. 

Thanks and Regards,

Vinay A. 

Thursday, June 20, 2019

Using MFA Accounts to connect to SPO online using PnP


Recently our organization have MFA (Multi-factor Authentication) enabled on all the Admin IDs. Which means once you are authenticated, you will be challenged again to prove your identity by giving a authentication code which will be sent to your mobile or MSFT calls your authorized identity phone to confirm its you who are logging in. Until now we used to store the password in an encrypted key and passed those credentials in the script. After MFA enabled, we need to use the paramter called 'use-weblogin'. Once this parameter is used who will be challenged second time while running the script, after successful verification rest of the script runs.

For instance Before MFA our code for connection
Connect-PnPOnline -Url https://yourAdminPortalURL -Credentials (Get-Credential)

After MFA our code for connection
Connect-PnPOnline -Url https://yourAdminPortalURL -UseWebLogin

Kindly let me know if there is any other ways to run the admin scripts automatically without weblogin paramter. May be there is way using Function and Azure Run books, i haven' explored that route much. Thanks for taking time to read this.

References: 

https://docs.microsoft.com/en-us/powershell/module/sharepoint-pnp/connect-pnponline?view=sharepoint-ps
HTH

Vinay. 

Tuesday, March 3, 2015

There was an error generating the XML document

There was an  issue i had encountered today while starting workflow using Nintex. The following thread helped me. 

http://oldconnect.nintex.com/forums/thread/30196.aspx 

While trying to start the workflow, it is failing while "Assigning Task to Apprver" basically in Nintex Language at "Request Approval" action item. 

The issue is the title contains some hidden characters. I copied the title and pasted in Notepad and found that there is one Escape character which is causing the workflow to fail. I cleaned up that character and after that workflow started working fine. 




Simple Fix! Isn't it? 

Thanks,

Vinay. 

Monday, February 16, 2015

The specified URL is not a top-level Web site

While doing site Backup and Restore in SharePoint 2013, i was getting the following error. Please note that the site collection is Host Name Site collection not Path based site collection.

The command i was giving is

PS C:\Windows\system32> Restore-SPSite http://sites.mytestsites.com/sites/mytestsite1 -Path "D:\Backup\MYTESTSITE1-PROD-20150210-2351.bak" -DatabaseName "SP13_Content_TESTSITEDB" -HostHeaderWebApplication "http://WFESERVERNAME" -Force 

The specified URL is not a top-level Web site. The backup and restore operations work only for top-level Web sites. Enter the URL for a site to try the

operation again.

At line:1 char:1
+ Restore-SPSite http://sites.mytestsites.com/sites/testSite1 -Path "D:\Backup\ ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (Microsoft.Share...dletRestoreSite:SPCmdletRestoreSite) [Restore-SPSite], SPException
    + FullyQualifiedErrorId : Microsoft.SharePoint.PowerShell.SPCmdletRestoreSite

The only thing that worked for me is 

- Deleting the existing site collection using the Remove-Spsite powershell cmdlet.
- Restoring the site from Backup using Restore-Spsite powershell cmdlet targeting to specific content DB

Remove-SPSite -Identity "http://sites.mytestsites.com/sites/TestSite1" -GradualDelete

Restore-SPSite http://sites.mytestsites.com/sites/MyTestSite1 -Path "D:\Backup\MyTestSite1.bak" -DatabaseName "SP13_Content_TestSitesContentDB" -HostHeaderWebApplication "http://WFESERVERNAME"

Hope this helps for some one who is having similar issue in backing up and restoring Host Name Site Collection (HNSC)

If someone finds a reason for this or is there any other way of doing this restore please let me know. 

Thanks,

Vinay. 

Friday, February 13, 2015

Export-SpWeb : The URL provided is invalid


While running the Export command for exporting the list from one site to another, i was giving the exact syntax but giving me the following error.

Export-SPWeb http://sites.sp13.com/sites/MyDevSite -Path "D:\SharePointBackUps\MyTestList.bak" -ItemUrl "http://sites.sp13.com/sites/MyDevSite/Lists/MyTestList" -IncludeUserSecurity -IncludeVersions All

Export-SPWeb : The URL provided is invalid. Only valid URLs that are site collections or sites are allowed to be exported using
stsadm.exe.
At line:1 char:1
+ Export-SPWeb -Identity http://sites.sp13.com/sites/myDevSite -Path "D: ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (Microsoft.Share...CmdletExportWeb:SPCmdletExportWeb) [Export-SPWeb], SPException
    + FullyQualifiedErrorId : Microsoft.SharePoint.PowerShell.SPCmdletExportWeb

Annoying, isn't it?

After reading the some of the blogs, the following link helped me
http://blogs.msdn.com/b/briangre/archive/2014/03/18/export-spweb-syntax-changes-between-root-site-and-sub-sites.aspx 

After giving the following syntax it worked. The issue occurring at -ItemUrl parameter. After giving in the format Lists/LISTNAME it worked.

Export-SPWeb http://sites.sp13.com/sites/MyDevSite -Path "D:\SharePointBackUps\MyTestList.bak" -ItemUrl "Lists/MyTestList" -IncludeUserSecurity -IncludeVersions All

Why??
The reason is at the background Get-SPWeb cmdlet is calling SPWeb.GetList(), before calling this function it prepends SPWeb.ServerRelativeUrl and an extra forward slash "/".

HTH

Vinay. 

Wednesday, December 3, 2014

Your changes were saved but could not be uploaded because of an error

This is the issue with the SharePoint 2010 office file not uploaded to SharePoint. What happens is when the user trying to download a copy from the SharePoint site and makes changes to it and uploads it back. Office 2010 suite and SharePoint, there is a medium called 'Microsoft Document upload Center' acts as medium between office files and SharePoint site.
http://office.microsoft.com/en-us/excel-help/microsoft-office-2010-upload-center-HA010388348.aspx

When opening the document from the server, the Microsoft Upload Center stores a local copy in its cache, and when the user makes the changes, the changes are first updated and local copy when saved, the changes from "Document Cache" which is in Microsoft Upload center gets updated back to the SharePoint site.

Sometimes due to network connectivity issues, the file may file to upload to SharePoint after user finished with changes. When we open the same file from the SharePoint you would get the following error

'Your Changes were save but could not be uploaded because of an error. You may be able to upload the file using the server Web page'




Most probable reason could be sitting in Microsoft Document Upload Center. To resolve this issue follow these steps

Step1: Access the Microsoft Document Upload Center from the 'Task Manager'

Step2: Look for any Cache errors.

Step3: Save the local copy if required.
Step4: Clear the Cache, this will remove the entire cache. or Discard the changes to file only that should remove the cache.

Step5: Try opening the file from SharePoint and save it back. That error pop up in the Document should go away.
 

Sunday, October 26, 2014

An error occurred while trying to load some required components

An error occurred while trying to load required components in Visual Studio 2012

This could be the case happening while installing Office Developer Tools in offline mode and then started creating SharePoint projects using Visual Studio 2012


An error occurred whilst trying to load some required components, Please ensure the following prerequisite components are installed.

Microsoft Web Developer Tools

Microsoft Exchange Web Services

The possible reason could be while installing the Office Developer tools and prerequisites, the office web installer sets some parameters mapped to GAC, which is not done while installed in offline mode according to following link
http://blogs.msdn.com/b/timquin/archive/2013/01/22/setting-up-visual-studio-2012-for-sharepoint-2013-development-offline.aspx

The fix this try the following steps:
- To un-install Microsoft Exchange Web Services from Control Panel
- Open the 'Command Prompt' with Administrator Previliges
- Navigate to location of file EWSManagedApi32.msi from the Command Prompts
- Run the following command. Make sure to be in single line. There is 'space' between .msi  and addlocal

  EwsManagedApi32.msi addlocal="ExchangeWebServicesApi_Feature,ExchangeWebServicesApi_Gac"

- The installation of the Exchange Web Services Api finishes. This commands does the installation and as well as maps the required dll files in GAC.
- Try closing any open instances of Visual Studio. Restart the Visual Studio
- Enjoy creating SharePoint Projects.

Hope this helps!

Thanks,

Vinay.