Export-Csv into separate columns

时间:2017-06-15 09:44:50

标签: powershell csv

I want to find computers that have been inactive for 45 days and they are enabled. I have created below code and it works, but when I try to export into a CSV file it puts all the information into one column.

I've tried to use delimiter but still outputs all information into one column.

Here's the code:

Import-Module ActiveDirectory
$inactiveDays = 45
$date = (Get-Date).AddDays(-($inactiveDays))

Get-ADComputer -Filter {Enabled -eq 'true' -and LastLogonTimeStamp -lt $date -and (Name -like 'WS*' -or Name -like 'LT*')} -Properties Enabled, LastLogonTimeStamp, Name, CanonicalName |
    Select-Object Name, CanonicalName, @{Name='Stamp';Expression={[DateTime]::FromFileTime($_.LastLogonTimeStamp)}} |
    Export-Csv C:\Users\$env:username\Desktop\Old_Computers.csv -Delimiter ',' -NoTypeInformation

1 个答案:

答案 0 :(得分:0)

简单的解决方案是将 -delimiter 改为 ;这将在您的 Excel 中分隔值