• Home
  • Software
  • Services
  • About
  • Contact
  • Login

SharePoint Tips & Techniques

1/2/2024

Create A Modern Site Collection Using Powershell

This segment provides the Powershell commands to create a Modern Site collection.

This script was tested using Powershell v5.1.19041.3570 on the desktop.

Install The SharePoint Module (as required)
Install-Module Microsoft.Online.SharePoint.PowerShell -force

Variables for Processing
$Site_Title = "My New PS Site"
$ADMIN_URL = "https://{companyname}-admin.sharepoint.com"
$SPO_URL = "https://{companyname}.sharepoint.com/sites/{sitecollection}"
$STORAGE_QUOTA = 2048
$User_Name ="{user@domain}.OnMicrosoft.com"
$User_Password ="{password}"

Connect To SPO
$cred = New-Object -TypeName System.Management.Automation.PSCredential -argumentlist $user_Name, $(convertto-securestring $user_Password -asplaintext -force)
Connect-SPOService -Url $admin_url -Credential $cred

Get list of template IDs
Get-SPOWebTemplate|format-table name, title
#Name - Title
#STS#3 - Team site (no Microsoft 365 group)
#STS#0 - Team site (classic experience)
#BDR#0 - Document Center
#DEV#0 - Developer Site
#OFFILE#1 - Records Center
#EHS#1 - Team Site - SharePoint Online configuration
#BICenterSite#0 - Business Intelligence Center
#SRCHCEN#0 - Enterprise Search Center
#BLANKINTERNETCONTAINER#0 - Publishing Portal
#ENTERWIKI#0 - Enterprise Wiki
#PROJECTSITE#0 - Project Site
#PRODUCTCATALOG#0 - Product Catalog
#COMMUNITY#0 - Community Site
#COMMUNITYPORTAL#0 - Community Portal
#SITEPAGEPUBLISHING#0 - Communication site
#SRCHCENTERLITE#0 - Basic Search Center
#visprus#0 - Visio Process Repository

Set Site Template ID
$SITE_TEMPLATE = "STS#3"

Create the site collection
New-SPOSite -Url $SPO_URL -title $SITE_TITLE -Owner $USER_NAME -StorageQuota $STORAGE_QUOTA -NoWait -Template $SITE_TEMPLATE


12/12/2023

Get List of Content Types Using Powershell

This segment provides the Powershell commands to get the list of Content Types for a list in SharePoint Online using CSOM.

This script was tested using Powershell v5.1.19041.3570 on the desktop.

Load SharePoint CSOM Assemblies
Import-Module "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Import-Module "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"

Variables for Processing
$SPO_URL = "https://{companyname}.sharepoint.com/sites/{sitecollection}"
$User_Name ="{user@domain}.OnMicrosoft.com"
$User_Password ="{password}"
$List_Name = "My List"

Get the Client Credentials
$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($User_Name, (ConvertTo-SecureString $User_Password -AsPlainText -Force))

Establish the context
$Context = New-Object Microsoft.SharePoint.Client.ClientContext($SPO_URL)
$Context.Credentials = $Credentials

Get the list information
$List = $Context.Web.lists.GetByTitle($List_Name)

Get all of the Content Types
$ContentTypes = $List.ContentTypes
$Context.Load($ContentTypes)
$Context.ExecuteQuery()

Display The Content Types
$ContentTypes | Select Name,Description


12/5/2023

Get List Of Files Using Powershell

This segment provides the Powershell commands to get a list of files in SharePoint Online using CSOM.

This script was tested using Powershell v5.1.19041.3570 on the desktop.

Load SharePoint CSOM Assemblies
Import-Module "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Import-Module "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"

Variables for Processing
$SPO_URL = "https://{companyname}.sharepoint.com/sites/{sitecollection}"
$User_Name ="{user@domain}.OnMicrosoft.com"
$User_Password ="{password}"
$Library = "Documents"

Create the user credentials
$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($User_Name, (ConvertTo-SecureString $User_Password -AsPlainText -Force))

Establish the context
$Context = New-Object Microsoft.SharePoint.Client.ClientContext($SPO_URL)
$Context.Credentials = $Credentials

Get the library information
$Library=$context.web.Lists.GetByTitle($Library) $Context.Load($Library) $Context.Load($Library.RootFolder) $Context.ExecuteQuery()

Get the folder information
$Folder = $Library.rootfolder
$Ctx = $Folder.Context
$Ctx.load($Folder.files)
$Ctx.ExecuteQuery()

Get the folder information
ForEach ($File in $Folder.files)
{
    #Get the File Name
    Write-host -f Green $File.Name
}


11/14/2023

Create Document Library Using Powershell

This segment provides the Powershell commands to create a new document library in SharePoint Online using CSOM.

This script was tested using Powershell v5.1.19041.3570 on the desktop.

Load SharePoint CSOM Assemblies
Import-Module "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Import-Module "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"

Variables for Processing
$SPO_URL = "https://{companyname}.sharepoint.com/sites/{sitecollection}"
$User_Name ="{user@domain}.OnMicrosoft.com"
$User_Password ="{password}"

Create the user credentials
$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($User_Name, (ConvertTo-SecureString $User_Password -AsPlainText -Force))

Establish the context
$Context = New-Object Microsoft.SharePoint.Client.ClientContext($SPO_URL)
$Context.Credentials = $Credentials

Create the library
$ListInfo = New-Object Microsoft.SharePoint.Client.ListCreationInformation
$ListInfo.Title = "{new library name}"
$List.Description = "{library description}"
$ListInfo.TemplateType = 101 #Document Library
$List = $Context.Web.Lists.Add($ListInfo)
$List.Update()
$Context.ExecuteQuery()


11/10/2023

Upload A File To SPO Using Powershell

This segment provides the Powershell commands to upload a single document into SharePoint Online using CSOM.

This script was tested using Powershell v5.1.19041.3570 on the desktop.

#Load The CSOM Modules
Import-Module "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Import-Module "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"

#Set The Variables
$SPO_URL = "https://companyname.sharepoint.com/sites/sitecollection/"
$Document_Library = "MyDocLibrary"
$Source_File = "d:\MyPhoto.jpg"
$User_Name ="user@companyname.onmicrosoft.com"
$User_Password = "mypassword"

#Create The User Credentials
$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($User_Name, (ConvertTo-SecureString $User_Password -AsPlainText -Force))

#Establish The Context
$Context = New-Object Microsoft.SharePoint.Client.ClientContext($SPO_URL)
$Context.Credentials = $Credentials

#Get the Library Information
$Library = $Context.Web.Lists.GetByTitle($Document_Library)

#Load The File Stream With The File
$FileStream = ([System.IO.FileInfo] (Get-Item $Source_File)).OpenRead()
#Get File Name from source file path
$Source_File_Name = Split-path $Source_File -leaf

#Prepare The File
$File_Creation_Info = New-Object Microsoft.SharePoint.Client.FileCreationInformation
$File_Creation_Info.Overwrite = $true
$File_Creation_Info.ContentStream = $FileStream
$File_Creation_Info.URL = $Source_File_Name
$FileUploaded = $Library.RootFolder.Files.Add($File_Creation_Info)

#Upload The File
$Context.Load($FileUploaded)
$Context.ExecuteQuery()

#Close File Stream
$FileStream.Close()


11/9/2023

Create A New List From CSV File Using Powershell

There are several ways import data. This segment will explain the steps to create a new SPO list using a CSV file.

1.

Create the CSV file with the data to be loaded into SharePoint.


2.

On the site where you want to create the new list, select the "+ New" option.


3.

Select "List".


4.

Select "From CSV".


5.

Select the file to upload.


6.

Once the data is loaded, you will be able to confirm the column type(s). Select "Next" button to continue.


7.

Provide a name for the new list and click the "Create" button.


8.

The result is a new list created from the CSV file:




Off-Site Labs, Inc.
©Copyright 1998-2025
All Rights Reserved