SharePoint Online: Site Operation with PnP Powershell

First, you will have to connect to your SharePoint Online Site

Example: Connect to SPO

$siteurl = "https://yourspsite.sharepoint.com"  
Connect-SPOnline -Url $siteurl  
$ctx = Get-SPOContext  

Example: How to retrieve top level subsites

Get-SPOWeb -Identity "Subsite"

Example: Create a new subsite

$subsite = Get-SPOWeb -Identity "Subsite" -ErrorAction SilentlyContinue
if($subsite -eq $null) {
	Write-Host "Site does not exist, create..." -ForegroundColor Yellow
	#Create a Team Site STS#0
	#Create a Project Site PROJECTSITE#0
	#Create a Publishing Site CMSPUBLISHING#0
	#etc...
	New-SPOWeb -Title "Subsite" -Url "Subsite" -Template "STS#0" 
	Write-Host "Created site Subsite" -ForegroundColor Yellow		
}
else {
	Write-Host "Subsite already exist" -ForegroundColor Green
}

Getting subsites under the top level subsites

#assuming subsite exists
$subsite = Get-SPOWeb -Identity "Subsite"
$subsubsite =  Get-SPOSubWebs -Web $subsite | Where-Object -property Title -EQ -Value "subsubsite"
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s