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
当您说“重复”时,您的意思是什么?您是如何验证员工编号不正确的,因为您没有在输出中包含该信息?一般来说,请提供更多信息让我们了解问题。 –