I know this question has been asked before, but I'm having a really hard time applying the solutions of others to my situation. Please provide both the conceptual and technical (code) explanations to your answer as I need to understand how this works so I don't have to ask again for different scenarios. :)
Question: How do I get this to export all the rows in my PSObject
, and why is it currently only exporting the last row? (please remember I'm only on PS 2.0)
$d = Get-SPDatabase | Sort-Object DiskSizeRequired -desc
$d | %{
#Report
$t = New-Object PSObject
$t | Add-Member NoteProperty "Size (MB)"([string]("{0:N0}" -f ($_.DiskSizeRequired / 1MB)) + " MB")
$t | Add-Member NoteProperty "Database"($_.Name)
Write-Output $t
}
#Save Report to Tab Delimited File on the Desktop
$t | Export-Csv ("{0}\Desktop\SP DB Sizes ({1}).txt" -f $Env:UserProfile, (Get-Date -Format "yyyy-MM-dd")) -Delimiter `t -Encoding UTF8 -NoTypeInformation
The above is a SharePoint specific script, but I expect the same concepts should apply to any situation involving a PSObject
for outputting tabular data. Yes, I want to both write the output to the console as well as a file.