0

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

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) {


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();
}
}



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

Below is a sample output of the script:

enter image description here

The problem is for columns Created Date and Modified Date it outputs the time as military time. I need it to ouput to normal time and displays whether it is a.m. or p.m. Can someone assist in what to add to the script to make it work?

1

By changing the line:

"Modified Date" = $item["Modified"]

to:

"Modified Date" = ($item["Modified"] -as [datetime]).DateTime

This will output the time as standard and not military time.

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.