Maximize your protection, eliminate business risks.
Optimize and modernize with cloud transformation.
Empower your people to work securely from anywhere.
Let us handle IT so you can focus on growing your business.
Get multichannel 24/7/365 expert end-user support.
Protect, detect, and respond—Dataprise keeps your business secure.
Maximize uptime with with industry-leading DRaaS.
Swiftly mitigate cyber threats and restore security.
Improve efficiency, productivity and outcomes with cloud.
Ensure all mobile devices, everywhere, are secure.
Gain a competitive edge with strategic IT solutions.
This battle-tested checklist enables your team to swiftly initiate a ransomware response.
IT for businesses of all sizes, in any industry.
Empower institution growth with custom IT solutions.
Ensure your firm is always in compliance.
Improve patient care and staff morale.
Deal with pressing legal matters, not IT.
Keep up with the evolving digital landscape.
Focus on your mission by outsourcing IT.
Accelerate PE client deals and secure data.
Empower Your Municipality with Secure, Reliable IT Services
Execute initiatives and develop IT strategies.
Get the latest industry insights and trends.
Join us at events in person and online.
Hear from clients and learn more about strategic IT.
See how Dataprise can make IT your greatest asset.
Get informative technical resources from IT experts.
Stay on stop of emerging cybersecurity threats.
Discover the key areas of DR your organization needs to address to ensure downtime is minimized.
Gain a strategic asset by bringing harmony to IT.
Ensure 24/7 support and security with dedicated teams.
Drive business forward by partnering with Dataprise.
Meet our one-of-a-kind leadership team.
Discover the recognition Dataprise has earned.
Help us help businesses with strategic IT.
Grow through acquisition and partnership with Dataprise.
Embracing different perspectives and backgrounds.
Find a Dataprise location near you.
Dataprise is committed to empowering more women to consider a career in technology.
Explore our trusted partnerships with leading tech innovators.
Posts
By: Stephanie Hamrick
Table of content
As with most businesses, with the new year comes documentation and internal paperwork that refers to 2017, instead of 2016. Part of this process requires us to create new 2017 SharePoint folders to keep track of client proposals, quotes, and contracts signed in the new year.
This is the first time we have had to deal with this situation since we moved to SharePoint Online last year. While the transition to SharePoint Online was painful, to say the least, I was assured by our Microsoft representatives that SharePoint Online would be a vast improvement, not the least of which is due to the extensive API provided by the Client-Side Object Model (CSOM).
While the CSOM is not as intuitive to navigate as I’d hoped, after a few weeks of dithering with various methods available in the API, I was able to successfully add 2017 folders in all the necessary document libraries for all our clients. Since we have hundreds of clients, doing this procedure by hand would have been impossible.
Adding a folder to a SharePoint document library is broken down into a few simple steps:
[NOTE: Before proceeding make sure you are a global administrator for your SharePoint online site collection]
Import-Module Microsoft.Online.SharePoint.PowerShell -DisableNameChecking
$Username = Read-Host -Prompt “Please enter your username”
$Password = Read-Host -Prompt “Please enter your password” -AsSecureString
$Site = “https://sharepoint_site.com/subsite”
$Context = New-Object Microsoft.SharePoint.Client.ClientContext($Site)
$Creds = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username,$Password)
$Context.Credentials = $Creds
——-> at this point you have connected to the sharepoint site located at https://sharepoint_site.com/subsite (subsites are optional if you’re trying to work on the root of the site collection)
$Web = $Context.Web
$Context.Load($Web)
$Context.ExecuteQuery()
——-> the “web” object is the top of the data hierarchy of this subsite, all my clients are stored as subsites underneath this one, so I have to fetch the “webs” object which allows me to get to each client individually
$Webs = $Web.Webs
$Context.Load($Webs)
——-> now I have the “webs” object which contains all the subsites of my client site (which is itself a subsite of the main site collection)
foreach ($ClientSite in $Webs) {
$Context.Load($ClientSite)
——-> this loads the client site
$ClientRootFolder = $ClientSite.RootFolder
$Context.Load($ClientRootFolder)
——-> this loads the root of the folder tree for the client site, and will allow me to get access to folders in the Sales document library
$ClientFolders = $ClientRootFolder.Folders
$Context.Load($ClientFolders)
——-> this loads all the document libraries under the client, so I can find the one called “Sales”
foreach ($Folder in $ClientFolders) {
$Context.Load($Folder)
if ($Folder.Name -like “Sales”) {
$SalesFolders = $Folder.Folders
$Context.Load($SalesFolders)
——-> once I find the folder called “Sales” I can load all the Sales folders which will allow me to create a new one
$NewSalesFolder = $SalesFolders.Add(“2017”)
$Context.Load($NewSalesFolder)
——-> this final command executes the action to create the new folder, and now we’re in business!
}
This is a simple PowerShell script to do a very simple task. SharePoint Online CSOM can be tricky at times, but if you stick with it this can be a powerful tool to programmatically manipulate the large data sets that many companies store in their SharePoint Online site collections.
I hope this trick helps you solve some internal scripting challenges of your own!
Allison Sousa, Director of Managed Services, PEI
INSIGHTS
Subscribe to our blog to learn about the latest IT trends and technology best practices.