For SharePoint 2013 on premises we had around 700+ command lets but SharePoint 2013 Online has a limited command-lets of 30 because of this limitation we are going to use power shell with Client side object model.Below are prerequisites for running a power shell script.
1. You need to have Power shell ISE
2. You need to have assemblies and these can be downloaded here
Power Shell scripts for retrieving all the lists present in the site and exporting it to CSV File
#Enter the credentials in dialog box
$credential = Get-Credential
$username=$credential.UserName
$password=$credential.GetNetworkCredential().Password
$securePassword=ConvertTo-SecureString $password -AsPlainText -Force
##URL for site
$url="https://spk0365.sharepoint.com/sites/PradeepLearning"
#Add dll
Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
## Function to retrieve lists in the site
function GetAllLists()
{
$clientContext=New-Object Microsoft.SharePoint.Client.ClientContext($url)
$credentials=New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username,$securePassword)
$clientContext.Credentials=$credentials
$web=$clientContext.Web;
$listColl=$web.Lists;
$clientContext.Load($listColl);
#Execute query will execute the query with server and will load site's lists properties in ClientContext
$clientContext.ExecuteQuery();
foreach($list in $listColl)
{
Write-Host "List Name: " $list.Title " ID: " $list.Id
#Writing the Lists properties to CSV
$web.Lists | select Title,ID | Export-CSV c:\Lists.csv
}
}
#Calling the function
GetAllLists
No comments:
Post a Comment