Tuesday, 23 January 2018

SharePoint Online Automation: Increase SharePoint Storage Quota in SharePoint Online Using PowerShell

In this article, we will learn about How to Increase SharePoint Storage Quota in SharePoint Online Using PowerShell. In last few of articles I have been demonstrated about below topics:

Kindly check the above articles to understand the requirement of business and solve the issue programmatically.
This demonstration will be applied to SharePoint Online, Office 365 Admin, and Office 365 Small Business Admin
As we know When a site collection is created in SharePoint online, we must specify a storage quota. This site size value must be between 100 MB and 100 GB. We will discuss more about site collection quota and usage in next coming article.
SharePoint online Site Collection Quota is allocated a quantity of storage that's based on your number of users. The storage is available to all site collections in the tenant and serves as a central pool from which everyone can draw. Site quota can be updated and modify as per requirement. If you are a Global admin for Office 365 tenant or Site collection administrator you will have access to do it.
Example: If you are managing a site collection, it will be easy to check site quota and increase the same, if working in the organization as SharePoint online Administrator where more than 1000+ site collection exists and on daily basis, we keep getting the request to update site collection quota. This is something where we need more attention and human effort to work on the same request.
Below are the steps to perform the above activity step by step with the screenshot:
Open PowerShell ISE with Admin rights and copy below script
As mentioned in last articles, we always need to do changes to the defined variable as per your requirement. Here we need to update below details,

  • $UserName = User Name of your Office 365 account – Line 7
  • $Password = Your Account password – Line 8
  • $Site URL - Site URL of Office 365 SharePoint Online where you increase site quota – Line 17
  • Read-Host "Enter the SharePoint Online Tenant" – Line 3
  • Tenant URL
  • $Quota=Read-Host "Enter the Storage Quota (1 GB) to be increased [in GB]: - Line 18

See below screenshot for more details

Import-Module Microsoft.Online.SharePoint.Powershell
Write-Host "This script is to set Storage Quota" -f DarkGreen
Read-Host "Enter the SharePoint Online Tenant"
   
   Write-Host "Connecting to SharePoint Online Tenant"
   
   $UserName="Your Account Name"  
   $Password ='Password'
   #Setup Credentials to connect
   $Credentials = New-Object System.Management.Automation.PSCredential($UserName,(ConvertTo-SecureString $Password -AsPlainText -Force))  
 
   Connect-SPOService -Url "Office 365 Tenant" -Credential $Credentials
   Write-Host "Your Tenant is connected"
   $SiteUrl=Read-Host "Enter the site Collection URL to which you want to increase storage quota"
   [int]$Quota=Read-Host "Enter the Storage Quota (1 GB)to be increased [in GB]:"
   $siteUrlDetail= Get-SPOSite $SiteUrl -Detailed -Limit all
   [int]$CurrentStorage= $siteUrlDetail.StorageQuota
       if ($Quota -eq 5)
       {
       Write-Host "Current Storage Quota is: $([MATH]::Round($CurrentStorage/1024,2)) GB"
       [int]$NewStorage = $Quota * 1024
       $StorageToIncrease = $CurrentStorage + $NewStorage
       Set-SPOSite -Identity $SiteUrl -StorageQuota $StorageToIncrease
       $NewSite = Get-SPOSite $SiteUrl -Detailed
       $NewQuota = [MATH]::Round($NewSite.StorageQuota/1024,2)
       Write-Host "New Storage Quota is : $NewQuota GB"
       }
       else
       {
           Write-Host "You have entered the wrong value.As per Defined policy, Please enter 1 GB only for Sites" -f Red
       }
  
  • Once you have done with changes or modification of defined variables, click on F5 and wait for below screen to come up asking you to enter Office 365 URL, see below screenshot:


  • After the site is getting connected, it will prompt for Site collection where you want to increase site Quota.



  • Later this entry, PowerShell script will start action to check existing site quota and it will match with defined standard quota if Site quota is exceeded than standard limitation it will prompt to enter the site quota. 
  • Now you can see, you site quota has been changed and it will show the current quota size of site collection as well.

SharePoint Online Automation: O365 SharePoint Online- How to Upload your files remotely using PowerShell to SPO document Library.

SharePoint Online Automation: O365 SharePoint Online- How to Upload your files remotely using PowerShell to SPO document Library.
Continue, with SharePoint Online Automation Today going to demonstrate about “O365 SharePoint Online- How to Upload your files remotely using PowerShell to SPO document Library”.
In My last below articles, I have described you about below mentioned:


In this article, we will learn about O365 SharePoint Online- How to Upload your files remotely using PowerShell to SPO document Library. It’s very common query and requirement with Admins to Upload the files which are placed in the local system to SharePoint sites to avoid manual tasks, Risks, and hassle-free process.


Let us start live example step by step with screenshots:


  • Open PowerShell ISE with Admin rights and copy below script




As mentioned in last articles, we always need to do changes of the defined variable as per your requirement. Here we need to update the below details:
  • $User = User Name of your Office 365 account
  • $Password = Your Account password
  • $Site URL: Site URL of Office 365 SharePoint Online where you want to copy or move document
  • $Folder: Destination location from here it will copy your files and copy to destination URL
  • $DocLibName: Document Library name where you want to Copy the Files which will take from Local system


#Specify tenant admin and site URL
$User = "Your id"
$Password = 'Your Password'
$SiteURL = "Site URL/"
$Folder = "C:\Script\HpeQuota" #Path where you want to Copy
$DocLibName = "Documents" #Docs library
#Add references to SharePoint client assemblies and authenticate to Office 365 site - required for CSOM
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
#Bind to site collection
$Context = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Creds = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($User,(ConvertTo-SecureString $Password -AsPlainText -Force))
$Context.Credentials = $Creds
#Retrieve list
$List = $Context.Web.Lists.GetByTitle($DocLibName)
$Context.Load($List)
$Context.ExecuteQuery()
#Upload file
Foreach ($File in (dir $Folder -File))
{
$FileStream = New-Object IO.FileStream($File.FullName,[System.IO.FileMode]::Open)
$FileCreationInfo = New-Object Microsoft.SharePoint.Client.FileCreationInformation
$FileCreationInfo.Overwrite = $true
$FileCreationInfo.ContentStream = $FileStream
$FileCreationInfo.URL = $File
$Upload = $List.RootFolder.Files.Add($FileCreationInfo)
$Context.Load($Upload)
$Context.ExecuteQuery()
}
Save the above script once all changes has been done, In above script, you can see I have added Add-Type -path, which will refer reference file of SharePoint Online Management shell.


We need to follow below steps to execute above command without any error:


  • Ensure that SharePoint Client components SDK installed on a user machine if it’s not installed kindly download the same executable file and install to your local system:




  • Microsoft.SharePoint.Client.dll and Microsoft.SharePoint.Client.Runtime.dll paths mentioned in the script are same as user’s machine
  • Set the “execution policies” for PowerShell in user machine by executing Remote signed


Set-ExecutionPolicy Remotesigned


Once you have verified all pre-requisites, you are ready to run the script which will upload your files from local system to SharePoint site URL under a document library. Now click on F5 and wait for some time to get upload all files which is copied from local system to SharePoint Online Document Library.