在网站集Sharepoint Online PowerShell上获取包含5000个项目的列表 [英] Get List with 5000 items on the Site Collections Sharepoint Online PowerShell
问题描述
大家好!我正在尝试获取网站集中的所有列表.
下面的脚本仅获取特定网站集中的列表,并且可以正常工作.
#环境变量
$ username =" user.name@xxx.com"
$ password =读取主机-提示符"输入密码:" -AsSecureString
$ url =" https://xxx.sharepoint.com/sites/xxxxxx"
$ securePassword = ConvertTo-SecureString $ password -AsPlainText -Force
#add SharePoint Online DLL-如果需要,请更新位置
$ programFiles = [environment] :: getfolderpath("programfiles")
添加类型-Path $ programFiles'\ SharePoint Online命令行管理程序\ Microsoft.Online.SharePoint.PowerShell \ Microsoft.SharePoint.Client.dll'
#连接/身份验证到SharePoint Online并获取ClientContext对象..
$ ctx =新对象Microsoft.SharePoint.Client.ClientContext($ url)
$ credentials =新对象Microsoft.SharePoint.Client.SharePointOnlineCredentials($ username,$ securePassword)
$ ctx.Credentials = $ credentials
#获取所有子网站
$ Web = $ ctx.Web
$ ctx.Load($ web)
$ ctx.Load($ web.Webs)
$ ctx.executeQuery()
Write-Host -ForegroundColor黄色有:" $ web.Webs.Count此网站集中的子网站"
#获取所有列表
foreach($ web.Webs中的$ subweb)
{
$ lists = $ subweb.Lists
$ ctx.Load($ lists)
$ ctx.ExecuteQuery()
#输出列表详细信息
Foreach($ list中的$ list)
{
如果($ list.ItemCount -gt 5000)
{
写入主机-ForegroundColor黄色网站URL为" $ subweb.Url
写主机"列表标题为:" $ list.Title".该列表具有:"$ list.ItemCount"项目"
}
}
}
当我尝试对其进行修改以获取所有网站集中的列表时.它错了.这是我修改的脚本.
#环境变量
$ username =" user.name@xxxx.com"
$ password =读取主机-提示符"输入密码:" -AsSecureString
$ url =获取内容"C:\ Users \ user.name \ Documents \ PowershellScripts \ sites.txt"
$ securePassword = ConvertTo-SecureString $ password -AsPlainText -Force
#add SharePoint Online DLL-如果需要,请更新位置
$ programFiles = [environment] :: getfolderpath("programfiles")
添加类型-Path $ programFiles'\ SharePoint Online命令行管理程序\ Microsoft.Online.SharePoint.PowerShell \ Microsoft.SharePoint.Client.dll'
#连接/认证到SharePoint Online并获取ClientContext对象.
$ ctx =新对象Microsoft.SharePoint.Client.ClientContext($ url)
$ credentials =新对象Microsoft.SharePoint.Client.SharePointOnlineCredentials($ username,$ securePassword)
$ ctx.Credentials = $ credentials
#获取所有子网站
$ Web = $ ctx.Web
$ ctx.Load($ web)
$ ctx.Load($ web.Webs)
$ ctx.executeQuery()
foreach($ url中的$ urls)
{
Write-Host -ForegroundColor黄色有:" $ web.Webs.Count此网站集中的子网站"
#获取所有列表
foreach($ web.Webs中的$ subweb)
{
$ lists = $ subweb.Lists
$ ctx.Load($ lists)
$ ctx.ExecuteQuery()
#输出列表详细信息
Foreach($ list中的$ list)
{
如果($ list.ItemCount -gt 5000)
{
写入主机-ForegroundColor黄色网站URL为" $ subweb.Url
写主机"列表标题为:" $ list.Title".该列表具有:"$ list.ItemCount"项目"
}
}
}
}
谢谢大家的帮助!
Hello Everyone ! Im trying to Get all the of the list in the Site Collections.
The script below just get the List in the specific site collection and this is working properly.
#environment variables
$username = "user.name@xxx.com"
$password = Read-Host -Prompt "Enter your password: " -AsSecureString
$url = "https://xxx.sharepoint.com/sites/xxxxxx"
$securePassword = ConvertTo-SecureString $password -AsPlainText -Force
#add SharePoint Online DLL - update the location if required
$programFiles = [environment]::getfolderpath("programfiles")
add-type -Path $programFiles'\SharePoint Online Management Shell\Microsoft.Online.SharePoint.PowerShell\Microsoft.SharePoint.Client.dll'
# connect/authenticate to SharePoint Online and get ClientContext object..
$ctx = New-Object Microsoft.SharePoint.Client.ClientContext($url)
$credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $securePassword)
$ctx.Credentials = $credentials
#get all the sub webs
$Web = $ctx.Web
$ctx.Load($web)
$ctx.Load($web.Webs)
$ctx.executeQuery()
Write-Host -ForegroundColor Yellow "There are:" $web.Webs.Count "sub webs in this site collection"
#get all the lists
foreach ($subweb in $web.Webs)
{
$lists = $subweb.Lists
$ctx.Load($lists)
$ctx.ExecuteQuery()
#output the list details
Foreach ($list in $lists)
{
if ($list.ItemCount -gt 5000)
{
Write-Host -ForegroundColor Yellow "The site URL is" $subweb.Url
Write-Host "List title is: " $list.Title". This list has: " $list.ItemCount " items"
}
}
}
When i try to modify it to get lists in all of the site collection. It errored out. Here is the script that i modify.
#environment variables
$username = "user.name@xxxx.com"
$password = Read-Host -Prompt "Enter your password: " -AsSecureString
$url = get-content "C:\Users\user.name\Documents\PowershellScripts\sites.txt"
$securePassword = ConvertTo-SecureString $password -AsPlainText -Force
#add SharePoint Online DLL - update the location if required
$programFiles = [environment]::getfolderpath("programfiles")
add-type -Path $programFiles'\SharePoint Online Management Shell\Microsoft.Online.SharePoint.PowerShell\Microsoft.SharePoint.Client.dll'
# connect/authenticate to SharePoint Online and get ClientContext object..
$ctx = New-Object Microsoft.SharePoint.Client.ClientContext($url)
$credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $securePassword)
$ctx.Credentials = $credentials
#get all the sub webs
$Web = $ctx.Web
$ctx.Load($web)
$ctx.Load($web.Webs)
$ctx.executeQuery()
foreach($urls in $url)
{
Write-Host -ForegroundColor Yellow "There are:" $web.Webs.Count "sub webs in this site collection"
#get all the lists
foreach ($subweb in $web.Webs)
{
$lists = $subweb.Lists
$ctx.Load($lists)
$ctx.ExecuteQuery()
#output the list details
Foreach ($list in $lists)
{
if ($list.ItemCount -gt 5000)
{
Write-Host -ForegroundColor Yellow "The site URL is" $subweb.Url
Write-Host "List title is: " $list.Title". This list has: " $list.ItemCount " items"
}
}
}
}
Thanks everyone for your help!
推荐答案
您遇到什么错误?
关于您的脚本,似乎是由获取所有网站和子网站"问题引起的.
About you script, it seems that caused by the get all sites and sub sites issue.
这是有关如何在线共享SharePoint中的所有网站和子网站的参考.
This is a reference about how to get all sites and subsites in SharePoint online.
function Get-SPOAllWeb
{
param (
[Parameter(Mandatory=
true,Position = 1)] [string]
true,Position=1)] [string]
用户名, [Parameter(Mandatory =
Username, [Parameter(Mandatory=
这篇关于在网站集Sharepoint Online PowerShell上获取包含5000个项目的列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!