Tuesday, 21 May 2013

Scripting Games - Beginner Event 4


The Scripting Games has been discussed in the previous post. The games are now four events old.  Event 4 of the Beginners track posed the challenge below:

Dr. Scripto isn’t saying that he dislikes auditors, but they do seem to show up at the most inconvenient times—and with the oddest requests. So he’s tossing this particular auditor request over to you.

This auditor would like a report that shows 20 randomly selected (well, as random as you can get) users from Active Directory. For each user, the auditor wants to see their user name, their department and title, and the last time they logged on. You also need to show the date their password was last changed, and whether the account is disabled or locked out. So that’s seven pieces of information. You’re to put that information into an HTML-based report file, and the file must show the date and time that the report was generated. Please make sure that all of the dates are normal looking, human-readable dates and times.

Keep your command as concise as possible, although that doesn’t mean you’re not allowed to use full command and parameter names—that’s always okay to do! A domain admin will always run the command, and the resulting HTML file will be manually emailed to the requesting auditor.

My solution for the event was:

Import-module ActiveDirectory

Get-ADUser -Filter * -Properties Name,Department,Title,LastLogonDate,PasswordLastSet,LockedOut,Enabled | get-random -count 20 | select Name,Department,Title,PasswordLastSet,LastLogonDate,LockedOut,Enabled | ConvertTo-Html -PostContent "<hr>","Report Generated at : ", (get-date) | Set-Content "C:\Users Report.htm"

The first line imports the ActiveDirectory module with the assumption that the module is not pre-loaded. The ‘Properties’ switch in Get-ADUser switch specifies the user attributes to be retrieved that are not displayed by default; ex: Dpartment, Title, LastLogonDate.  ‘Get-Random’ command in the pipeline outputs random 20 users.  The required properties are then selected and the output is converted to HTML and saved on the local drive.

Helpful links:




No comments:

Post a Comment