Powershell Tuesday

Here’s a Powershell one-liner (or two) for your Tuesday.

1. Imagine you have a file of NetIDs, one per line, and you would like to generate a CSV file of first names, last names, etc. from the file of NetIDs. Here’s how you do it:

get-content C:\Users\bjchapm\Documents\badnetids.txt | get-aduser -Properties Name,Givenname,Surname | select-Object Name,GivenName,Surname

2. Really quick-and-dirty (and not very correct) dump of all of the groups that a particular set of your users belong to:

Import-Module ActiveDirectory
$Users = get-ADUser -Filter {(objectCategory -eq "User") -and (Description -eq "Student:School of Law")} -Properties MemberOf,Name,FullName |Select-Object MemberOf,Name, FullName
foreach ($user in $Users) {
 $user.name, $user.fullname, $user.MemberOf
 }

This will print out (to the console) each user name and the groups to which the user belongs. However, it’s clearly not the right way to do it… but, it worked for me.

Powershell is actually fun. 🙂

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s