繁体   English   中英

使用PnP PowerShell for SharePoint Online在文档库上设置“说明”

[英]Setting the “Description” on a Document Library using PnP PowerShell for SharePoint Online

我正在尝试使用PnP-PowerShell命令在SharePoint Online中的文档库上设置描述,但是它似乎在工作中非常断断续续,因此我想检查正确的方法是什么?

我用以下方法创建一个新库:

New-PnPList -Template DocumentLibrary -Title "TempLibrary"

然后尝试通过以下方式设置说明:

$l = Get-PnPList -Identity TempLibrary
$l.Description = "My Description Here"

现在很明显这行不通,因为我需要使用假定的CSOM将更改发送回去?

因此,我尝试了以下操作:

$ctx = Get-PnPContext
$l = Get-PnPList -Identity TempLibrary
$l.Description = "My Description Here"
$ctx.ExecuteQuery()

但这似乎仍然行不通。

任何人对如何可靠地执行此操作的任何想法,将不胜感激。

非常感谢,D。

更新

Eurgh ...这似乎可行,但是对吗? 是预期的吗? 感觉不太像PowerShell ...

New-PnPList -Title "Test5" -Template DocumentLibrary
$t = Get-PnPList -Identity Test5
$ctx.Load($t)
$ctx.ExecuteQuery()
$t.Description = "Test5 Description"
$t.Update()
$ctx.ExecuteQuery()

如果不加载列表,您将无法设置描述或其他属性,因此代码正确。

$ctx.Load($t)

您为什么认为这不像PS? :)好奇...

使用以下脚本。 希望能帮助到你。

    Add - PSSnapin Microsoft.SharePoint.PowerShell  

    function CreateList($spWeb, $listName) 
    {   
        $spTemplate = $spWeb.ListTemplates["Document Library"]  
        $spListCollection = $spWeb.Lists  
        $spListCollection.Add($listName, $listName, $spTemplate)  
    }  

    Function SetDescription($spWeb, $listName)
    {            
        $path = $spWeb.url.trim()  
        $spList = $spWeb.GetList("$path/Lists/$listName")
        $spList.Description = "--Your Desired Description--"
        $spList.Update()
    }


    $siteCollectionUrl = "--Your Site Collection Url--"  
    $listName = "--Your Desired List Name--"  
    $spWeb = Get - SPWeb - Identity $siteCollectionUrl 

    CreateList $spWeb $listName 

    SetDescription $spWeb $listName

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM