0
我想要獲取一個域的SAMAccountNames並將它們與來自另一個域的等於它們進行比較。Powershell導入CSV和Foreach對象,不包含與CSV標頭
要得到DC1的所有用戶使用:
Get-ADUser -Filter * -SearchBase $SearchBase | Select-Object SamAccountName |
Export-Csv -path $exports -encoding "unicode" -notype
,然後我再導入CSV並嘗試比較他們對任何差異
$readthat = Import-CSV $exports -Header SamAccountName | ForEach-Object {
$user1 = Get-ADUser -Identity $_.SamAccountName -Properties $attributes
$user2 = Get-ADUser -Identity $_.SamAccountName -Properties $attributes -Server $dc2
$modified = @{}
$attributes | Where-Object { $user1.$_ -ne $user2.$_ } | ForEach-Object {
$modified[$_] = $user2.$_
}
}
所有的不同之處在於它是偉大工程,也試圖找到SamAccountName,這當然會產生錯誤,因爲SamAccountName = SamAccountName不會退出。
有關如何避免這種情況的任何提示,或者你們有更優雅的解決方案嗎?
該.csv看起來是這樣的:
"SamAccountName"
"foo"
"bar"
在讀入導入/導出功能時必須錯過該部分。 謝謝 – StUffz 2014-12-04 12:55:59