• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Powershell script not outputting correctly to CSV/Excel

Obsoleet

Platinum Member
I'm trying to output certain data to a CSV file, but it's slapping all the information from all fields into a single spreadsheet cell.

You can see I'm pulling certain variables, then putting them into a temporary file. Then putting that into another file using Out-File, this is the only way I could get it to append after my script ran through each server (rather than overwriting the last server's information).

Code:
$dbs = $s.Databases
$dbs | select Parent, Version, Name, LastBackupDate, LastLogBackupDate, Size, SpaceAvailable | Export-Csv "C:\Documents and Settings\Desktop\sqlservers\SERVER\TempDatabase.csv" -notype
[System.IO.File]::ReadAllText("C:\Documents and Settings\Desktop\sqlservers\SERVER\TempDatabase.csv") | Out-File "C:\Documents and Settings\Desktop\sqlservers\SERVER\BACKUP_GEN_Information.csv" -Append


But after you open up Excel it looks like this example from cell A1, when I want Excel to respect the imported data as comma separated-
Parent,"Version","Name","LastBackupDate","LastLogBackupDate","Size","SpaceAvailable"

I haven't found anyway to make Out-File import the information into the final file in a way that is correct.. any ideas? Thank you
 
I don't know powershell but whouldn't you need the tablename in the database statement?

I.e.

Code:
select Parent, Version, Name, LastBackupDate, LastLogBackupDate, Size, SpaceAvailable [COLOR="Red"]from tablename[/COLOR]
 
Back
Top