Forum Discussion

Americo Perez's avatar
Americo Perez
Iron Contributor
Apr 13, 2018

Creating libraries with powershell

Hi,

 

I got a script to create libraries in SPOnlnine and its work very well. But I would like to add a parameter that inform SPOnline that the library should be shown in the quicklaunch too, right now I have to gor through each library and addit to the quicklaunch manually. 

Here is the script I am using and for those that are looking something similar: 

 

function new-SPOnlineList ($listTitle) {
    #variables that needs to be set before starting the script
    $siteURL = ""
    $adminUrl = ""
    $listDescription = ""
    $listTemplate = 101

    # Creating client context object
    $context = New-Object Microsoft.SharePoint.Client.ClientContext($siteURL)
    $context.credentials = $SPOCredentials

    #create list using ListCreationInformation object (lci)
    $lci = New-Object Microsoft.SharePoint.Client.ListCreationInformation
    $lci.title = $listTitle
    $lci.description = $listDescription
    $lci.TemplateType = $listTemplate
    $list = $context.web.lists.add($lci)
    $context.load($list)
    #send the request containing all operations to the server
    try{
        $context.executeQuery()
        write-host "info: Created $($listTitle)" -foregroundcolor green
    }
    catch{
        write-host "info: $($_.Exception.Message)" -foregroundcolor red
    }  
}

$userName = "americo@americospdev.onmicrosoft.com"

# Let the user fill in their password in the PowerShell window
$password = Read-Host "Please enter the password for $($userName)" -AsSecureString

# set SharePoint Online credentials
$SPOCredentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($userName, $password)

$listTitle = @("Bibliotek 1", "Bibliotek 2")

for($i=0; $i -lt $listTitle.length; $i++) {
    new-SPOnlineList $listTitle[$i]
}

Best regards

Americo

Resources