1

I have a script that outputs to CSV all items and files from Libraries and Lists in a Site shown below:

Add-PSSnapin microsoft.sharepoint.powershell
$excludeLists = @("Master Page Gallery",
                "Workflows",
                "Workflow History"
                                          )

function Get-DocInventory([string]$siteUrl) {
$web = Get-SPWeb "http://contoso.com/sites/depts/HBG"
foreach ($list in $web.Lists) {
if($excludeLists -notcontains $list.Title){

foreach ($item in $list.Items) {
foreach($version in $item.Versions){

$personField = $item.Fields.GetField("Author");
$authorObject = $personField.GetFieldValue($item["Author"]);
$authorName = $authorObject.LookupValue;

$userField = $version.Fields.GetField("Editor");
$editorObject = $userField.GetFieldValue($version["Editor"]);
$editorName = $editorObject.LookupValue;

$localOffset = +5;
$modified = $version["Modified"] -as [datetime];

if($modified.IsDaylightSavingTime()){$localOffset += 1;}
$modifiedLocal = $modified.addHours(-$localOffset);

$data = @{
"Version" = $version.VersionLabel
                        "List Name" = $list.Title
                        "Created By" = $authorName 
                        "Created Date" = ($item["Created"] -as [datetime]).DateTime
                        "Modified By" = $editorName
                        "Modified Date" = ($modifiedLocal -as[datetime]).DateTime
                        "Item Name" = $item.Name

}
New-Object PSObject -Property $data | Select "List Name", "Item Name", "Version", "Created By", "Created Date", "Modified By", "Modified Date"
}
}
$web.Dispose();
}
}
}




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

Below is a sample of what the script outputs:

enter image description here

The output above shows a file called Lions.pdf with 3 versions. In addition, this displays which user made the change at a specific version of the file. My question is, is there a way to return the user's name in the Created By column and the Created Date only once instead of it repeating for each version of the file? If so, can someone show me how as I have been having a hard time.

Below is the desired output that displays the user's name once in the Created By column and the Created Date shows only once as well:

enter image description here

Your Answer

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

Browse other questions tagged or ask your own question.