if ((Get-PSSnapin
"Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue)
-eq $null)
{
Add-PSSnapin
"Microsoft.SharePoint.PowerShell"
}
#Get the Web
$web = Get-SPWeb -identity "http://win-2016"
#Get the Target List
$list = $web.Lists["Documents"]
#Array to Hold Result - PSObjects
$ListItemCollection = @()
#CAML Query
$spQuery = New-Object Microsoft.SharePoint.SPQuery
$spQuery.ViewAttributes
= "Scope='Recursive'";
$spQuery.RowLimit
= 2000
$caml="<OrderBy><FieldRef Name='ID' Ascending='True'
/></OrderBy>"
$spQuery.Query
= $caml
#Get All List items
$listItems=$list.GetItems($spQuery)
foreach($item
in $listItems)
{
$data =
@{
"URL"=$web.Site.MakeFullUrl("$($web.ServerRelativeUrl.TrimEnd('/'))/$($item.Url)");
}
$ExportItem
= New-Object
PSObject -Property
$data |
Select "URL"
$ExportItem
| Add-Member
-MemberType NoteProperty
-name "Name"
-value $item["Name"]
#Add the
object with property to an Array
$ListItemCollection
+= $ExportItem
}
#Export the result Array to CSV file
$ListItemCollection | Export-CSV "c:\ListData.csv" -NoTypeInformation
#Dispose the web Object
$web.Dispose()
No comments:
Post a Comment