2015-10-19 71 views
0

我有輸出網站(網頁)範圍爲CSV文件中的所有庫中的所有文檔的PowerShell腳本如下:檢索所有列出所有項目從一個站點 - Powershell的

function Get-DocInventory([string]$siteUrl) { 
$site = New-Object Microsoft.SharePoint.SPSite $siteUrl 
$web = Get-SPWeb "http://contoso.com/sites/Depts/HTG" 
foreach ($list in $web.Lists) { 
if ($list.BaseType -eq 「DocumentLibrary」) { 

foreach ($item in $list.Items) { 
foreach($version in $item.Versions){ 
$data = @{ 
"Version" = $version.VersionLabel 
         "List Name" = $list.Title 
         "Created By" = $item["Author"] 
         "Created Date" = $item["Created"] 
         "Modified By" = $item["Editor"] 
         "Modified Date" = $item["Modified"] 
         "Item Name" = $item.File.Name 
         "URL"=$web.Site.MakeFullUrl("$($web.ServerRelativeUrl.TrimEnd('/'))/$($item.Url)"); 
} 
New-Object PSObject -Property $data | Select "List Name", "Item Name", "Version", "Created By", "Created Date", "Modified By", "Modified Date", "URL" 
} 
} 
$web.Dispose(); 
} 
$site.Dispose() 
} 
} 



Get-DocInventory | Export-Csv -NoTypeInformation -Path C:\NewOutput.csv 

我有一個我需要做的最後一件事情就是除了輸出所有庫中的所有文檔之外,我還需要添加腳本以從上述腳本中列出的同一站點http://contoso.com/sites/Deptss/HTG的所有列表中提取所有項目。有人可以告訴我該怎麼做嗎?我真的需要別人的幫助。

注:我知道,通過所有列表循環,我可以通過文檔庫更改下面的線,這原本迭代:

if ($list.BaseType -eq 「DocumentLibrary」) 

要在這之下,通過列表迭代:

if ($list.BaseType -eq 「GenericList」) 

我想遍歷文檔庫和列表。我會怎麼做?

回答

2

正如你正確識別,在這行代碼的條件,通過文檔庫使你的腳本只循環:

if ($list.BaseType -eq 「DocumentLibrary」) 

要通過所有的列表迭代不論類型,只是刪除if條款(和其相應的開/關支撐)。

相關問題