使用Powershell删除Sharepoint联机列表项

时间:2018-10-16 05:44:08

标签: powershell sharepoint sharepoint-online

我目前有一个Powershell脚本可以循环访问Sharepoint在线站点上的列表。

$creds = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials("[USERNAME]", (ConvertTo-SecureString "[PASSWORD]" -AsPlainText -Force))  
$ctx = New-Object Microsoft.SharePoint.Client.ClientContext("https://[SITENAME].sharepoint.com/sites/Projekter")  
$ctx.credentials = $creds  

try{  
    $lists = $ctx.web.Lists


    $list = $lists.GetByTitle("Ekstern synkronisering")
    $listItems = $list.GetItems([Microsoft.SharePoint.Client.CamlQuery]::CreateAllItemsQuery())  
    $ctx.load($listItems)  

    $ctx.executeQuery()  

    foreach($listItem in $listItems)  
    {          
        $internal = $listItem["ConnectionString1"]
        $external = $listItem["ConnectionString2"]
        $folder = $listItem["Mappe"]
        $project = $listItem["Project"]
        $caseNo = $listItem["Title"]

        $doc = New-Object System.Xml.XmlDocument
        $doc.Load("C:\Script\PS-Layer2\xmlTemplate.xml")
        $ns = New-Object System.Xml.XmlNamespaceManager($doc.NameTable)
        $ns.AddNamespace("ns", $doc.DocumentElement.NamespaceURI)

        $doc.SelectSingleNode("//ns:dataEntity[@name='Intern site']", $ns).connectionString = $internal+";Authentication=Office365;User Id=$userId;Password=$pwd;"

        $doc.SelectSingleNode("//ns:dataEntity[@name='Externt site']", $ns).connectionString = $external+";Authentication=Office365;User Id=$userId;Password=$pwd;"

        $doc.Save("C:\Temp\$caseNo - $project - $folder.xml")

    }  
}  
catch{  
    write-host "$($_.Exception.Message)" -foregroundcolor red  
} 

这样可以很好地获取项目并修改XML文件。

我想做的是,当XML文件创建完毕后,它将从共享点站点中删除列表项,这样就不会在下次运行时再次创建它。

有人对此有解决方案吗?

最诚挚的问候...

0 个答案:

没有答案