1
我的CSV中有一个小错误。我只是试图让我的CSV踢出来的用户和最后一栏载明具体DC从中拉出数据中列出的属性:Powershell将域控制器名称添加到CSV
$Path = Get-ScriptDirectory
$Date = (Get-Date).ToString('yyyy-MM-dd')
$Domain = Get-ADDomain | select -ExpandProperty ParentDomain
$DomainName = Get-ADDomain | select -ExpandProperty NetBIOSName
$Filename = "$Path\$DomainName" + "_Users_By_Last_DC_" + $Date + ".csv"
$DClist = Get-ADDomainController -Filter * | select name
$Statement = ForEach ($DomainController in $DClist){
Get-ADUser -Filter * -Properties SamAccountName, DisplayName, LastLogonDate, LogonCount, Enabled, PasswordExpired, PasswordLastSet, PasswordNeverExpires, PasswordNotRequired, CannotChangePassword, AccountExpirationDate, AccountExpires, WhenCreated, canonicalName -Server $DomainController.Name | select SamAccountName, DisplayName, LastLogonDate, LogonCount, Enabled, PasswordExpired, PasswordLastSet, PasswordNeverExpires, PasswordNotRequired, CannotChangePassword, AccountExpirationDate, AccountExpires, WhenCreated, canonicalName, @{Name="Domain Controller";Expression=$DomainController.name} | sort $DomainController.name, samAccountName, LastLogonDate}
$Statement | Export-Csv $FileName -NoTypeInformation
我得到了“域控制器”的如下: Microsoft.ActiveDirectory.Management.ADPropertyValueCollection
我觉得加一个-expandproperty name
会是适当的,但我似乎无法弄清楚它会去哪里。
任何帮助,将不胜感激。
是你大学的专业作为真棒,或你刚刚出生吗?谢谢! – Nate
@NateR np。不,我从高中辍学,研究解决现实世界问题的微妙艺术,结果非常好:D –