2016-10-01 3 views
0

foreach 루프 처리에 문제가 있다고 생각합니다. 그러나 나는 왜 그것이 작동하지 않는지 이해하지 못합니다. 그래서 나는 미숙 한 결과를 얻고있다. 여러 변형을 시도했지만 운이 없습니다.내보내기 문제 foreach 및 Get-ADUser -Filter

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" 
+0

음 ... 그렇다면 "예기치 않은 결과"는 무엇인가요? * 정확히 * 어떻게 코드가 "작동하지 않습니까?" 그것이 필터 식이라고 가정합니다 : [이 질문을보십시오] (http://stackoverflow.com/q/34028164/1630171). –

+0

13685와 같이 CSV 파일에 포함되지 않은 중복 된 employeeid 사용자를 반환하는 "예기치 않은 결과"를 의미합니다. – Arbelac

+0

"복제본"이라고 정확히 할 때 어떤 의미입니까? 출력에 해당 정보를 포함하지 않으므로 직원 ID가 잘못되었음을 어떻게 확인 했습니까? 일반적으로 문제를 이해할 수 있도록 자세한 정보를 제공해주십시오. –

답변

0

지금 내가 볼

$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 같은 인 입력을 가정합니다. 필터에 $user 변수를 사용하고 있습니다.이 변수는 이전에 채워져있는 것으로 보입니다. 이는 각 입력 ID에 대해 주어진 ID를 가진 객체 대신 실제로 동일한 사용자 객체를 가져 오는 것을 의미합니다. 13685은 해당 사용자 계정의 st 속성 값으로 나타납니다.

$user을 현재 개체 변수 $_으로 바꾸면 문제가 사라집니다. 당신이 실제로 속성으로 뭔가를 할 경우 보조 노트로


Import-Csv 'C:\export\list.csv' | ForEach-Object { 
    Get-ADUser -Properties * -Filter "EmployeeId -eq $($_.EmployeeID)" | 
     Select-Object ... 
} | Export-Csv $csvreportfile -NoType 

는 사용 계산 된 속성은 (같은 재산, 변경/재 형식 값 등의 이름을 변경). 그렇지 않으면 단순히 목록에 속성 이름을 넣으십시오.