当前位置:网站首页 > 更多 > 玩电脑 > 正文

[玩转系统] SharePoint Online:使用 PowerShell 创建图片库

作者:精品下载站 日期:2024-12-14 14:58:02 浏览:14 分类:玩电脑

SharePoint Online:使用 PowerShell 创建图片库


要求:使用 PowerShell 在 SharePoint Online 中创建图片库。

如何在SharePoint Online中添加图片库?

顾名思义,SharePoint Online 中的图片库针对存储和共享数字图像进行了优化。图片库允许您上传和存储可在您的网站上使用或与其他人共享的照片和图像。本文将向您展示如何在 SharePoint Online 中创建图片库。我们还将向您展示如何使用 PowerShell 在 SharePoint Online 中创建图片库。

要在 SharePoint Online 中创建图片库,请按照下列步骤操作:

  1. 导航到要在其中创建图片库的 SharePoint 网站。
  2. 单击“设置”齿轮图标 >> 选择“添加应用程序”。 (您也可以转到“网站内容”,然后单击“添加应用程序”。)
  3. 在“应用程序”页面上,向下滚动并选择“图片库”图标。您也可以使用搜索框。
  4. 在“新建”对话框中,键入库的名称,然后单击“创建”。

    [玩转系统] SharePoint Online:使用 PowerShell 创建图片库

创建图片库后,您可以通过单击图库工具栏中的“上传”并选择要添加的图片来上传图片。

PowerShell 在 SharePoint Online 中创建图片库

以下是如何使用 PowerShell 在 SharePoint Online 中创建图片库:


#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"

#Variables for Processing
$SiteURL = "https://crescent.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
}

要获取所有列表模板类型,请参阅:https://docs.microsoft.com/en-us/previous-versions/office/sharepoint-server/ee541191(v%3Doffice.15)

使用 PnP PowerShell 在 SharePoint Online 中添加图片库

要在 SharePoint Online 中创建图片库,请使用以下 PnP PowerShell 脚本:


#Parameters
$SiteURL = "https://crescent.sharepoint.com/teams/Ops"
$LibraryName = "Team Outing"
 
#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Interactive
 
#powershell to create picture library
New-PnPList -Title $LibraryName -Template PictureLibrary

总之,在 SharePoint Online 中创建图片库是一个简单的过程,可以帮助您以有组织且高效的方式存储和管理图片。按照上述步骤,您可以创建新的图片库、上传图片并自定义库设置以满足您的需求。您还可以使用 PowerShell 自动执行此过程并在 Sharepoint Online 中创建图片库。

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯