Solved

Powershell: Add EmployeeID to existing Get-ADUser and Get-ADGroup script with multiple lines for each user

Posted on 2016-11-23
2
20 Views
Last Modified: 2016-11-23
This is the working script that I have. I would like to add the EmployeeID attribute for each user but am having trouble with the syntax. The output shows the user and the group name, but does not show the EmployeeID.

Import-Module Activedirectory
Get-ADUser -Filter * -Properties DisplayName,memberof,EmployeeID | % {
 $Name = $_.DisplayName
 $EmployeeID = $_.EmployeeID
  $_.memberof | Get-ADGroup | Select @{N="User";E={$Name}},Name
 } | Export-Csv C:\Reports\Testing\GroupsMultipleLines2.csv -nti

Open in new window

0
Comment
Question by:Intelli-Seeker
2 Comments
 
LVL 83

Accepted Solution

by:
oBdA earned 500 total points
ID: 41899346
That's because you don't create a calculated property for EmployeeID:
Import-Module Activedirectory
Get-ADUser -Filter * -Properties DisplayName, MemberOf, EmployeeID | % {
	$ADUser = $_
	$_.MemberOf | Get-ADGroup | Select-Object @{N="User"; E={$ADUser.DisplayName}}, @{N="EmployeeID"; E={$ADUser.EmployeeID}}, Name
 } | Export-Csv C:\Reports\Testing\GroupsMultipleLines2.csv -nti

Open in new window

1
 

Author Closing Comment

by:Intelli-Seeker
ID: 41899357
This is perfect and exactly what our Supervisors need for auditing their users. Thanks a million!
0

Join & Write a Comment

Microsoft Windows Server Update Service (WSUS) is free for everyone, but it lacks of some desirable features like send an e-mail to the administrator with the status of all computers on the WSUS server. This article is based on my PowerShell script …
I thought I'd write this up for anyone who has a request to create an anonymous whistle-blower-type submission form created using SharePoint 2010 (this would probably work the same for 2013). It's not 100% fool-proof but it's as close as you can get…
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now