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 –