0
我想我遇到了foreach循環處理的問題。但我不明白爲什麼不工作。所以我得到了未被發現的結果。我嘗試了幾個變化,但沒有運氣。導出問題與foreach和Get-ADUser -Filter
$reportdate = Get-Date -Format ssddmmyyyy
$csvreportfile = "c:\export\ALLADUsers_$reportdate.csv"
Import-Csv -Path "c:\export\list.csv" | ForEach-Object {
Get-ADUser -Properties * -Filter "EmployeeId -eq $($user.EmployeeID)" |
Select-Object @{Label = "First Name";Expression = {$_.GivenName}},
@{Label = "Last Name";Expression = {$_.Surname}},
@{Label = "Display Name";Expression = {$_.DisplayName}},
@{Label = "Logon Name";Expression = {$_.sAMAccountName}},
@{Label = "WhenCreated";Expression = {$_.whenCreated}},
@{Label = "Full address";Expression = {$_.StreetAddress}},
@{Label = "City";Expression = {$_.City}},
@{Label = "State";Expression = {$_.st}},
@{Label = "Post Code";Expression = {$_.PostalCode}},
@{Label = "Country/Region";Expression = {if (($_.Country -eq 'GB')) {'United Kingdom'} else {''}}},
@{Label = "Job Title";Expression = {$_.Title}},
@{Label = "Company";Expression = {$_.Company}},
@{Label = "Description";Expression = {$_.Description}},
@{Label = "Department";Expression = {$_.Department}},
@{Label = "Office";Expression = {$_.OfficeName}},
@{Label = "Phone";Expression = {$_.telephoneNumber}},
@{Label = "Email";Expression = {$_.Mail}},
@{Label = "Manager";Expression = {%{(Get-ADUser $_.Manager -Server $ADServer -Properties DisplayName).DisplayName}}},
@{Label = "Account Status";Expression = {if (($_.Enabled -eq 'TRUE')) {'Enabled'} else {'Disabled'}}, # the 'if statement# replaces $_.Enabled
@{Label = "Last LogOn Date";Expression = {$_.lastlogondate}}
} | Export-Csv -Path $csvreportfile -NoTypeInformation
假設輸入CSV是這樣的:
EmployeeID 16507 16534 16587 16622 16631 16632 16659 16661 16663 16666 16688 16713 16728 16753 16830
輸出CSV:
"First Name","Last Name","Display Name","Logon Name","WhenCreated","Full address","City","State","Post Code","Couny/Region","Job Title","Company","Description","Department","Office","Phone","Email","Manager","Account Status","Last LogOn Date"
"Jax","Teller","Jax Teller","JaxT","09.11.2012 12:34:35",,"Foobar","13685",,"","Consultant","Contoso","Contoso/
- ","Research","","1111111111 (1111)","[email protected]",,"Enabled","16.08.2016 15:50:27"
"Jax","Teller","Jax Teller","JaxT","09.11.2012 12:34:35",,"Foobar","13685",,"","Consultant","Contoso","Contoso/
- ","Research","","1111111111 (1111)","[email protected]",,"Enabled","16.08.2016 15:50:27"
"Jax","Teller","Jax Teller","JaxT","09.11.2012 12:34:35",,"Foobar","13685",,"","Consultant","Contoso","Contoso/
- ","Research","","1111111111 (1111)","[email protected]",,"Enabled","16.08.2016 15:50:27"
"Jax","Teller","Jax Teller","JaxT","09.11.2012 12:34:35",,"Foobar","13685",,"","Consultant","Contoso","Contoso/
- ","Research","","1111111111 (1111)","[email protected]",,"Enabled","16.08.2016 15:50:27"
"Jax","Teller","Jax Teller","JaxT","09.11.2012 12:34:35",,"Foobar","13685",,"","Consultant","Contoso","Contoso/
- ","Research","","1111111111 (1111)","[email protected]",,"Enabled","16.08.2016 15:50:27"
"Jax","Teller","Jax Teller","JaxT","09.11.2012 12:34:35",,"Foobar","13685",,"","Consultant","Contoso","Contoso/
- ","Research","","1111111111 (1111)","[email protected]",,"Enabled","16.08.2016 15:50:27"
"Jax","Teller","Jax Teller","JaxT","09.11.2012 12:34:35",,"Foobar","13685",,"","Consultant","Contoso","Contoso/
- ","Research","","1111111111 (1111)","[email protected]",,"Enabled","16.08.2016 15:50:27"
"Jax","Teller","Jax Teller","JaxT","09.11.2012 12:34:35",,"Foobar","13685",,"","Consultant","Contoso","Contoso/
- ","Research","","1111111111 (1111)","[email protected]",,"Enabled","16.08.2016 15:50:27"
"Jax","Teller","Jax Teller","JaxT","09.11.2012 12:34:35",,"Foobar","13685",,"","Consultant","Contoso","Contoso/
- ","Research","","1111111111 (1111)","[email protected]",,"Enabled","16.08.2016 15:50:27"
"Jax","Teller","Jax Teller","JaxT","09.11.2012 12:34:35",,"Foobar","13685",,"","Consultant","Contoso","Contoso/
- ","Research","","1111111111 (1111)","[email protected]",,"Enabled","16.08.2016 15:50:27"
"Jax","Teller","Jax Teller","JaxT","09.11.2012 12:34:35",,"Foobar","13685",,"","Consultant","Contoso.","Contoso/
- ","Research","","1111111111 (1111)","[email protected]",,"Enabled","16.08.2016 15:50:27"
"Jax","Teller","Jax Teller","JaxT","09.11.2012 12:34:35",,"Foobar","13685",,"","Consultant","Contoso","Contoso/
- ","Research","","1111111111 (1111)","[email protected]",,"Enabled","16.08.2016 15:50:27"
"Jax","Teller","Jax Teller","JaxT","09.11.2012 12:34:35",,"Foobar","13685",,"","Consultant","Contoso","Contoso/
- ","Research","","1111111111 (1111)","[email protected]",,"Enabled","16.08.2016 15:50:27"
"Jax","Teller","Jax Teller","JaxT","09.11.2012 12:34:35",,"Foobar","13685",,"","Consultant","Contoso","Contoso/
- ","Research","","1111111111 (1111)","[email protected]",,"Enabled","16.08.2016 15:50:27"
"Jax","Teller","Jax Teller","JaxT","09.11.2012 12:34:35",,"Foobar","13685",,"","Consultant","Contoso","Contoso/
- ","Research","","1111111111 (1111)","[email protected]",,"Enabled","16.08.2016 15:50:27"
嗯......那麼,什麼*是*「意外的結果」?代碼「不工作」怎麼樣?假設它是過濾器表達式:請看看[這個問題](http://stackoverflow.com/q/34028164/1630171)。 –
我的意思是「意外結果」,它返回一個CSV文件中未包含的重複employeeid用戶,例如13685 ID – Arbelac
當您說「重複」時,您的意思是什麼?您是如何驗證員工編號不正確的,因爲您沒有在輸出中包含該信息?一般來說,請提供更多信息讓我們瞭解問題。 –