Skip to content

Instantly share code, notes, and snippets.

@phillipharding
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phillipharding/36e1ea1b12d58f9a0401 to your computer and use it in GitHub Desktop.
Save phillipharding/36e1ea1b12d58f9a0401 to your computer and use it in GitHub Desktop.
Create Folder Tree's for SharePoint Lists and Libraries
function EnsureListFolderTree($web, $list, $folderName) {
$curl = $list.RootFolder.ServerRelativeUrl
$folders = $folderName.Replace("^/+","").Split("/")
ForEach($fn in $folders) {
$furl = $curl + "/" + $fn
$f = $web.GetFolder($furl)
if ($f.Exists -eq $false) {
$f = $list.AddItem($curl, [Microsoft.SharePoint.SPFileSystemObjectType]::Folder, $fn)
$f.Update()
$f = $web.GetFolder($f.Folder.ServerRelativeUrl)
}
$curl = $f.ServerRelativeUrl
}
$f
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment