Hi @ネパリ サンデャ ,
You can use the follow script to bulk create document library:
#Function to Create a SharePoint Online document library
Function CreateSPO-DocumentLibrary()
{
[cmdletbinding()]
param
(
[Parameter(Mandatory=$True,ValueFromPipeline)] [String[]] $LibraryNames,
[Parameter(Mandatory=$False)] [String] $Description
)
Try {
#Create Each Document Library
ForEach($LibraryName in $LibraryNames)
{
Write-host -f Yellow "`nEnsuring Document Library '$LibraryName'"
#Get All Existing Lists from the web
$Lists = $Web.Lists
$Ctx.Load($Lists)
$Ctx.ExecuteQuery()
#Check if Library name doesn't exist already
If(!($Lists.Title -contains $LibraryName))
{
#Create a new Document Library
$ListInfo = New-Object Microsoft.SharePoint.Client.ListCreationInformation
$ListInfo.Title = $LibraryName
$ListInfo.Description = $Description
$ListInfo.TemplateType = [Microsoft.SharePoint.Client.ListTemplateType]::DocumentLibrary
$Web.Lists.Add($ListInfo) | Out-Null
$Ctx.ExecuteQuery()
write-host -f Green "`tNew Document Library '$LibraryName' has been created!"
}
Else
{
Write-Host -f Magenta "`tA Document Library '$LibraryName' Already exists!"
}
}
}
Catch {
write-host -f Red "`tError:" $_.Exception.Message
}
}
#Set Parameters
$SiteURL= "https://domain.sharepoint.com/sites/sitename/"
#Get Credentials to connect
$Cred = Get-Credential
#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 from URL
$Web = $Ctx.web
$Ctx.Load($Web)
$Ctx.executeQuery()
#Call the function to create document libraries
CreateSPO-DocumentLibrary -LibraryNames @("Document Library 1", "Document Library 2", "Document Library 3", "Document Library 4")
Please fill in $SiteURL and LibraryNames according to your actual situation.
You can use the follow script to grant access to a SharePoint Online site level:
#Variables for Processing
$SiteURL = "https://domain.sharepoint.com/Sites/sitename/"
$UserAccount = "******@domain.com"
$PermissionLevel = "Contribute"
#Setup 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()
#Ensure the user
$User=$web.EnsureUser($UserAccount)
$Ctx.Load($User)
$Ctx.ExecuteQuery()
#Get the Permission Level
$RoleDefinition = $web.RoleDefinitions.GetByName($PermissionLevel)
$RoleAssignment = New-Object Microsoft.SharePoint.Client.RoleDefinitionBindingCollection($Ctx)
$RoleAssignment.Add($RoleDefinition)
#Assign Role Assignment to User
$Permissions = $Web.RoleAssignments.Add($User,$RoleAssignment)
$Web.Update()
$Ctx.ExecuteQuery()
Write-host -f Green "User '$UserAccount' has been Granted with Access '$PermissionLevel'!"
}
Catch {
write-host -f Red "Error:" $_.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.