0

I have a SharePoint library with document sets on level 1.

Then inside document sets I have Folders and some documents(word,excel,text) on level 2.

Then again inside folders in level 2 I have some documents and folders and so on. I have to write a PowerShell script to go through all the folders,sub folders and find documents and update some columns.

I have tried and I am able to iterate through all sub folders but I don't know how to get the items(documents) in every level.

Level 1- Document sets

Level 2- Folders and documents

Level 3- Folders and documents

My requirement is to iterate through all levels update a column of document and then go into folders in that level.

0

I also have or had the same requirement. Just asked here:

Get all documents from subsite with Powershell

I ended up with the following Powershellscript:

[System.Reflection.Assembly]::Load("Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c")
[System.Reflection.Assembly]::Load("Microsoft.SharePoint.Portal, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c")
[System.Reflection.Assembly]::Load("Microsoft.SharePoint.Publishing, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c")
[System.Reflection.Assembly]::Load("System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")

function Get-DocInventory([string]$siteUrl) {
$site = New-Object Microsoft.SharePoint.SPSite $siteUrl

$web = Get-SPWeb -Identity "http://sp13/teams/it"

foreach ($list in $web.Lists) {
if ($list.BaseType -ne “DocumentLibrary”) {
continue
}

foreach ($item in $list.Items) {
$data = @{
 "list" = $list.Title
 "Item URL" = $item.Url
 "Item Title" = $item.Title
 "Item Created" = $item["Created"]
 "Item Modified" = $item["Modified"]
 "Created By" = $item["Author"]
 "Modified By" = $item["Editor"]
 "File Size" = $item.File.Length/1KB
 "File Size (MB)" = $item.File.Length/1MB
}
New-Object PSObject -Property $data
}
}
$web.Dispose();

$site.Dispose()
}

Get-DocInventory "http://sp13/teams/it" | Out-GridView
Get-DocInventory "http://sp13/teams/it" | Export-Csv -NoTypeInformation -Path "c:\temp\Document_Detail_Report_IT.csv"

Maybe it is still relevant for you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.