从AD导出结果,每个属性都有自己的列

时间:2017-02-17 16:13:48

标签: powershell active-directory export-to-csv

我需要在AD中找到具有以下属性的所有已禁用用户:

  • 启用
  • CN
  • 的samAccountName
  • 描述
  • 的distinguishedName
  • LastLogonDate
  • 修饰

我可以让它在PowerShell中显示,但我不能让它在Excel中工作,如果它确实导出它的随机数。如何将其导出到Excel中,每个属性都应该有自己的列。

Click here for the screenshot

以下是代码:

Get-ADUser -Filter {Enabled -eq $false} -Properties * |
    FT Enabled, CN, samAccountName, Description, DistinguishedName, LastLogonDate, Modified |
    Export-csv c:\Users\shiv\Desktop\newlist.csv

1 个答案:

答案 0 :(得分:0)

以下是您需要做的事情。

Get-ADUser -Filter { Enabled -eq $false } -Properties cn,description,LastLogonDate,Modified |
  Select-Object cn,sAMAccountName,description,distinguishedName,LastLogonDate,Modified |
  Export-Csv C:\temp\newlist.csv -NoTypeInformation

我们不建议使用-Properties *,因为这会不必要地检索所有属性并增加运行查询的时间。仅指定默认情况下未返回的属性,然后使用Select-Object仅选择输出中所需的属性。最后,-NoTypeInformation Export-Csv参数会阻止您在Excel中看到的第一行输出,这会阻止Excel理解该文件确实是CSV。

Format-Table(你在这里使用ft别名)应该只在管道的末尾使用,因为它产生格式化的输出(因此名称)。

相关问题