Automated deployment for SharePoint Online can be one hell of a job. Apps and sandboxed solutions are the designated methods for provisioning, but are very limited. How about PowerShell? Yes! But not the default flimsy SPO cmdlets library. No, we are using SharePoint PowerShell, a third party PowerShell API for SharePoint (Online and On-premise).
SharePoint PowerShell
SharePoint PowerShell in fact a bunch of PowerShell Modules talking to CSOM, created by a guy called Jeffrey Paarhuis 🙂 Very usefull for Office 365 and private clouds where you don’t have access to the physical server.
What can you do with it?
- Site Collection
- Test connection
- Site
- Manage subsites
- Manage permissions
- Lists and Document Libraries
- Create list and document library
- Manage fields
- Manage list and list item permissions
- Upload files to document library (including folders)
- Add items to a list with CSV
- Add and remove list items
- File check-in and check-out
- Master pages
- Set system master page
- Set custom master page
- Features
- Activate features
- Web Parts
- Add Web Parts to page
- Users and Groups
- Set site permissions
- Set list permissions
- Set document permissions
- Create SharePoint groups
- Add users and groups to SharePoint groups
- Solutions
- Upload sandboxed solutions
- Activate sandboxed solutions
And yet more to come…
How does it work? Well, like this:
# Include SPPS Import-Module .\spps.psm1 # Setup SPPS Initialize-SPPS -siteURL "https://example.sharepoint.com/" -online $true -username "[email protected]" -password "password" # Activate Publishing Site Feature Activate-Feature -featureId "f6924d36-2fa8-4f0b-b16d-06b7250180fa" -force $false -featureDefinitionScope "Site" #Activate Publishing Web Feature Activate-Feature -featureId "94c94ca6-b32f-4da9-a9e3-1f3d343d7ecb" -force $false -featureDefinitionScope "Web" # Create a subsite Add-Subsite -title "Subsite" -webTemplate "STS#0" -description "Description..." -url "subsite" -language 1033 -useSamePermissionsAsParentSite $true # Create document library Add-DocumentLibrary -listTitle "Testdoclib" # Copy testfiles to this document library Copy-Folder "C:\example\Testdoclib" "Testdoclib" $false
Try it yourself: example application
And let me know what you think of it and how it can be improved!
Great initiative. I was just looking for CSOM or Rest Api option to automate our SharePoint Online environment. I also left a feature request at the codeplex page
Hi, would it be possible to create folders on request? so after it creates the library (which works fantastic thank you) then create folder with name I give it?
Thats not implemented yet, but you can try to do it first in CSOM and then translate the code to PowerShell.
Thank you Jeffrey, can you give an example of code?
var list = ctx.Web.Lists.GetByTitle(listName);
var folder = list.RootFolder;
ctx.Load(folder);
ctx.ExecuteQuery();
folder = folder.Folders.Add(folderName);
ctx.ExecuteQuery();
Hello Jeffrey, I am still very much a noob at this. need a little more detail please
I’m sorry but at this moment I’m not able to help you in translating it into a working piece of PowerShell. Maybe there is a programmer at your fingertips that’s able to do this? Otherwise I might do it later on.
var list = ctx.Web.Lists.GetByTitle(listName);
var folder = list.RootFolder;
ctx.Load(folder);
ctx.ExecuteQuery();
folder = folder.Folders.Add(folderName);
ctx.ExecuteQuery();
In PowerShell this becomes:
$list = $ctx.web.lists.getbytitle($listname)
$folder = $list.RootFolder
$ctx.Load($folder)
$ctx.ExecuteQuery();
$folder = $folder.Folders.Add($folderName);
$ctx.ExecuteQuery();
And yep I know this is late, however it may aid someone else 🙂
Is there any way to deploy workflows ?
Hi,
is it possible to support a proxy(with credentials) to get the context?
Thanks,
Lutz
Hi,
I am not able to deploy WSP file(sandboxed solutions) in solution gallery of SharePoint online (16 version)365 site of SharePoint 2013.
Please do some needful.
Any update on my issue.
What’s the error?