SharePoint Online: Create Picture Library using PowerShell

Requirement: Create Picture Library in SharePoint Online using PowerShell

How to add picture library in SharePoint Online?
As the name implies, Picture Library in SharePoint Online is optimized for storing and sharing digital images. Picture library lets you upload and store photos and images that can be used in your site or shared with others. To create a picture library in SharePoint Online, follow these steps:
  • Navigate to the SharePoint site where you want to create the picture library.
  • Click on Settings gear icon >> Select Add an app. (You can also go to "Site contents", and then click add an app.)
  • On the Your Apps page, Scroll down and select "Picture Library" icon. You can use search box as well.
  • In the New dialog box,  type a name for the library and Click Create.
    sharepoint online create picture library

PowerShell to Create Picture Library in SharePoint Online:
#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"

#Variables for Processing
$SiteURL = "https://crescenttech.sharepoint.com/sites/marketing"
$LibraryName = "Logos"
$LibraryDescription ="Library to store all Logos of the Company"

#Get Credentials to connect
$Cred = Get-Credential

Try { 
    #Setup the context
    $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
    $Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)

    #Get the Web
    $Web = $Ctx.Web
    $Ctx.Load($Web)
    $Ctx.ExecuteQuery()

    #Define List Creation Parameters
    $ListCreationInformation = New-Object Microsoft.SharePoint.Client.ListCreationInformation 
    $ListCreationInformation.Title = $LibraryName 
    $ListCreationInformation.TemplateType = [int][Microsoft.SharePoint.Client.ListTemplatetype]::PictureLibrary
    #Create Picture Library
    $List = $Web.Lists.Add($ListCreationInformation)
    $List.Description = $LibraryDescription
    $Ctx.ExecuteQuery()
    Write-host -f Green "Picture Library '$LibraryName' Created Successfully!"
}
Catch {
    write-host -f Red "Error:" $_.Exception.Message
}

To get all list template types, refer:
https://docs.microsoft.com/en-us/previous-versions/office/sharepoint-server/ee541191(v%3Doffice.15)
SharePoint Online: Create Picture Library using PowerShell SharePoint Online: Create Picture Library using PowerShell Reviewed by Salaudeen Rajack on March 29, 2018 Rating: 5

No comments:

Please Login and comment to get your questions answered!

Powered by Blogger.