We're using the basis of a powershell function originally provided on this forum to extract SharePoint list data to csv.
The function loops through a parameterized number of sub site levels under each site which we now set to a high value to extract all items under all subsites to the lowest level under each main Departmental site
Ultimatley we use the data to report on document counts by dept.
Our Sharepoint farm looks something like this
ServerName/sites/DeptPortal
ServerName/sites/DeptPortal/subsite
ServerName/sites/DeptPortal/subsite/subsite/to n levels
Is there a way we can modify the script to extract (as currently) the DeptPortal title, DeptPortal/subsiteand then all documents listed under this to the lowest level but against the DeptPortal/subsite title?
i.e. Currently we get the 'Web' column of the output file populated with the title of whatever the lowest level is.
This is the script:
param($Server, $Site, $Outfile)
function Audit-Webs($SiteUrl,$CheckSubWebs,$Depth,$SubsitesOnly)
{
$items = New-Object psobject
$items | Add-Member -MemberType NoteProperty -Name "Name" -value ""
$items | Add-Member -MemberType NoteProperty -Name "Title" -value ""
$items | Add-Member -MemberType NoteProperty -Name "Author" -value ""
$items | Add-Member -MemberType NoteProperty -Name "DataClassification" -value ""
$items | Add-Member -MemberType NoteProperty -Name "Classification" -value ""
$items | Add-Member -MemberType NoteProperty -Name "RetentionPeriod" -value ""
$items | Add-Member -MemberType NoteProperty -Name "ReviewPeriod" -value ""
$items | Add-Member -MemberType NoteProperty -Name "ListTitle" -value ""
$items | Add-Member -MemberType NoteProperty -Name "Site" -value ""
$items | Add-Member -MemberType NoteProperty -Name "Web" -value ""
$items | Add-Member -MemberType NoteProperty -Name "ItemUrl" -value ""
$a = $null
$a = @()
$w = get-spweb $SiteUrl
if($SubsitesOnly -eq $false)
{
$lc = $w.Lists;
foreach($l in $lc){
if($l.Title -eq "Style Library"){continue;}
if($l.Hidden -eq $true){continue;}
if($l.BaseTemplate -eq 101){
$listitems = $l.Items
foreach($i in $listitems){
$b = $items | Select-Object *;
$b.Name = $i["Name"];
$b.Title = $i["Title"];
$b.Author = $i["_Author"];
$b.DataClassification = $i["Data_x0020_Classification"];
$b.Classification = $i["Classification"];
$b.RetentionPeriod = $i["Retention_x0020_Period"];
$b.ReviewPeriod = $i["Review_x0020_Period"];
$b.ListTitle=$l.Title;
$b.Site=$Site;
$b.Web=$w.Title;
$b.ItemUrl = [String]::Concat($i.Web.Url,"/",$i.Url);
$a+=$b
}
}
}
}
if($CheckSubWebs)
{
if($w.Webs.Count -gt 0)
{
if($depth -gt 0)
{
foreach($sw in $w.Webs)
{
$a += Audit-Webs -SiteUrl $sw.Url -CheckSubWebs $true -Depth ($depth -1) -SubsitesOnly $false
}
}
}
}
$w.Dispose();
Write-Output $a
}
$a = $null
$a = @()
$a = Audit-Webs -SiteUrl "http://$Server/sites/$Site" -CheckSubWebs $true -Depth 4 -SubsitesOnly $false
$a | Where-Object {$_} | Export-Csv -Delimiter "," -Path "$Outfile\export_$Site.csv" -notype