0

我正在从列出合同到期日期的用户的 AD 中生成报告。到目前为止,我已经能够想出这个,它输出到一个带有自定义标题和缩短日期的 CSV 文件。

Get-QADUser -SizeLimit 0 -IncludedProperties AccountExpires,Domain,Name -DontUseDefaultIncludedProperties | Where { $_.Title -ne "Resource" } | Select @{Label="Domain";Expression={(($_.Domain).Name)}},@{Label="Employee Name";Expression={($_.Name)}},@{Label="Contract Expiry Date";Expression={(($_.AccountExpires).ToShortDateString())}},title,department,Office | Export-Csv C:\ExportForHR.csv -NoTypeInformation

我想要做的是在“合同到期日”列中放置一个自定义值,如果它们没有价值的话。

即,如果我没有合同,则默认值为空,因此电子表格中不会显示任何内容。但是,如果我想在该字段中输入“无合同到期”或“全职到期”怎么办?

找不到任何适合使用上述命令的内容。通过不使用 Select 和 export-csv 之类的东西,我可能会编写一个完整的 powershell 脚本来输出到 CSV 文件,但我宁愿不这样做,除非我真的必须这样做。

4

1 回答 1

0

您已经完成了大约 95% 的路程。Select-Object 的 Expression 部分中的脚本块是一个完整的脚本块,因此您可以在其中执行测试:

Get-QADUser -SizeLimit 0 -IncludedProperties AccountExpires,Domain,Name -DontUseDefaultIncludedProperties | 
Where { $_.Title -ne "Resource" } | 
Select-Object 
  @{Label="Domain";Expression={(($_.Domain).Name)}},
  @{Label="Employee Name";Expression={($_.Name)}},
  @{Label="Contract Expiry Date";Expression={
    if ($_.AccountExpires -ne $null) { 
      $_.AccountExpires).ToShortDateString()
    } else { 
      $CustomValue 
    }
  },
  title,
  department,
  Office 
| Export-Csv C:\ExportForHR.csv -NoTypeInformation
于 2014-03-25T22:10:47.330 回答