[英]Get-ADComputer -Filter
I have a script that uploads data about a PC with the last activity more than 100 days, I can't upload it as a normal table and I don't understand how to add 2 distributionname + description fields我有一个脚本可以上传上次活动超过 100 天的 PC 数据,我无法将其作为普通表格上传,而且我不明白如何添加 2 个分布名称 + 描述字段
Get-ADComputer -Filter * -Properties OperatingSystem, LastLogonDate | Where { $_.LastLogonDate -LT (Get-Date).AddDays(-100) } | Select-Object Name, OperatingSystem, LastLogonDate | Out-File "\\Client\C$\Users\computer_ad.csv" -encoding Unicode -Delimiter ";"
You should not use Out-File
to save as CSV. There is a special cmdlet for that called Export-Csv您不应使用Out-File
保存为 CSV。有一个名为Export-Csv的特殊 cmdlet
Also, it is better to set the reference date to midnight using .Date
when comparing to the LastLogonDate.此外,与 LastLogonDate 进行比较时,最好使用.Date
将参考日期设置为午夜。
By default, Get-ADComputer returns these properties: DistinguishedName, DNSHostName, Enabled, Name, ObjectClass, ObjectGUID, SamAccountName, SID, UserPrincipalName
and for anything on top of that you need to specify it in the -Properties
parameter.默认情况下,Get-ADComputer 返回这些属性: DistinguishedName, DNSHostName, Enabled, Name, ObjectClass, ObjectGUID, SamAccountName, SID, UserPrincipalName
,对于除此之外的任何内容,您需要在-Properties
参数中指定它。
As for attribute Description
, that's easy enough, but what do you mean by distributionname
??至于属性Description
,这很简单,但是distributionname
是什么意思? I'm guessing you want the DistinguishedName
name there:我猜你想要DistinguishedName
名称:
$refDate = (Get-Date).AddDays(-100).Date # set this to midnight
Get-ADComputer -Filter * -Properties OperatingSystem, LastLogonDate, Description |
Where-Object { $_.LastLogonDate -lt $refDate } |
Select-Object Name, OperatingSystem, LastLogonDate, Description, DistinguishedName |
Export-Csv -Path "\\Client\C$\Users\computer_ad.csv" -Delimiter ';' -NoTypeInformation
If you really want the file to be encoded in UTF16-LE (Unicode), you can add that to the Export-Csv line: -Encoding Unicode
, although UTF8
is more commonly used.如果您确实希望文件以 UTF16-LE (Unicode) 编码,您可以将其添加到 Export-Csv 行: -Encoding Unicode
,尽管UTF8
更常用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.