About modifiying site url in csv

jennyKim 240 Reputation points
2023-06-27T02:20:24.58+00:00

I want to create bulk document library and for this i use following script

According to script I can only use one site at a time so is there any way to add site url in csv just like following example

So i dont need to type site url many times

User's image

#Set Parameters
$SiteURL = "https://crescent.sharepoint.com/sites/Shared"
$CSVFilePath = "C:\Users\Downloads\Document.csv"
   
#Connect to the site
Connect-PnPOnline -Url $SiteURL -Interactive
 
#Get the data from CSV file
$CSVFile = Import-CSV $CSVFilePath
   
#Read CSV file and create List
ForEach($Row in $CSVFile)
{
    Try {
        #Create List
        Write-host -f Yellow "Creating List:"$Row.ListName
        If($Row.OnQuickLaunch -eq "True")
        {
            New-PnPList -Title $Row.ListName -Template $Row.Template -OnQuickLaunch -ErrorAction Stop | Out-Null
        }
        else
        {
            New-PnPList -Title $Row.ListName -Template $Row.Template -ErrorAction Stop | Out-Null
        }
        Write-host -f Green "`tCreated List '$($Row.ListName)'"
    }
    Catch {
        write-host -f Red "`tError:" $_.Exception.Message
    }
}



Microsoft 365 and Office | SharePoint | Development
Microsoft 365 and Office | SharePoint | For business | Windows
Windows for business | Windows Server | User experience | PowerShell
0 comments No comments
{count} votes

Accepted answer
  1. RaytheonXie_MSFT 40,471 Reputation points Microsoft External Staff
    2023-06-27T07:32:56.31+00:00

    Hi @jennyKim

    You can get siteurl from $Row. Please refer to the following script

    #Set Parameters
    $CSVFilePath = "C:\Users\Downloads\Document.csv"
     
    #Get the data from CSV file
    $CSVFile = Import-CSV $CSVFilePath
       
    #Read CSV file and create List
    ForEach($Row in $CSVFile)
    {
        $SiteURL=$Row.SiteURL
        #Connect to the site
        Connect-PnPOnline -Url $SiteURL -Interactive
    
        Try {
            #Create List
            Write-host -f Yellow "Creating List:"$Row.ListName
            If($Row.OnQuickLaunch -eq "True")
            {
                New-PnPList -Title $Row.ListName -Template $Row.Template -OnQuickLaunch -ErrorAction Stop | Out-Null
            }
            else
            {
                New-PnPList -Title $Row.ListName -Template $Row.Template -ErrorAction Stop | Out-Null
            }
            Write-host -f Green "`tCreated List '$($Row.ListName)'"
        }
        Catch {
            write-host -f Red "`tError:" $_.Exception.Message
        }
    }
    
    

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.