Powershell script - report on AD accounts

rated by 0 users
This post has 9 Replies | 2 Followers

Top 50 Contributor
Posts 53
virtuallynothere Posted: 03-30-2012 9:45 PM

Howdy,

I am trying a new script that is hopefully easier than the last I tried.  I have a server that performs actions to create, modify, and disable user accounts.  I have a command that retrieves the list of users I need to report on and now I am not sure how to get to the next steps of creating this report.

The command I have is:Get-QARSOperation -CompletedOn 'Today' -TargetObjectType 'user' -OperationType deprovision

I get either no results depending on if any accounts were disabled today, or it could be 1 or 20 users.  The format I receive after running the command is below.  I now need to take the list of users that are returned, then gather specific attributes on the users, format the information and email it out to a DL.  Can someone help me figure out what I need to do next and keep going as I learn how to do this?

ID       InitiatedOn          InitiatedBy               Status     Type             Target

--       -----------          -----------               ------     ----             ------

1-1  3/30/2012 7:07:43 PM test.local\-admin-joe... Completed  Deprovision  CN=simpson\, marge,OU=Users,OU=Co...

Top 10 Contributor
Posts 296
Microsoft MVP
Top Contributor

First thing I would do is put the results into a CSV file - this saves rerunning the command and allows you save the results.

Get-QARSOperation -CompletedOn 'Today' -TargetObjectType 'user' -OperationType deprovision |

export-csv mycsv.csv  -NoTypeInformation

Now you can read the results

import-csv mycsv.csv | foreach {

 get-qaduser -Idendity $($_.Target) -includeallproperties | select a, b, c, d

}

select a, b, c, d     = the properties you want

If you don't need the csv file then simplify to

Get-QARSOperation -CompletedOn 'Today' -TargetObjectType 'user' -OperationType deprovision |

foreach {

get-qaduser -Idendity $($_.Target) -includeallproperties | select a, b, c, d

}

Top 50 Contributor
Posts 53

Thank you for the helpful response, I appreciate it!


I have been trying exactly that as well as a few other things and I can't get this to work, I keep getting an error with the get-qaduser command.

The error I am getting is:

Get-QADUser : Cannot validate argument on parameter 'Identity'. The argument is null or empty. Supply an argument that

is not null or empty and then try the command again.

At C:\Users\test\finaldeprovreportscript.ps1:7 char:29

+ get-qaduser -proxy -Identity <<<<  $($_.Target) -includeallproperties

    + CategoryInfo          : InvalidData: (:) [Get-QADUser], ParameterBindingValidationException

    + FullyQualifiedErrorId : ParameterArgumentValidationError,Quest.ActiveRoles.ArsPowerShellSnapIn.Powershell.Cmdlet

   s.GetUserCmdlet

 

I ultimately do not know if I need the csv file, my goal is to get the list of users changed, in this case disabled, then gather the attributes I need and combine the results that I get from the 1st command. I need the info from the get-qarsoperation as that shows who made the changes, the time, etc.  I am not sure how to take that info and pass it to get-qaduser and gather the attributes for each user listed from the 1st command and then have a final email or file that shows all the details with the changes but includes the attributes for the users I need such as office, phone, etc.

Top 10 Contributor
Posts 640

You spelled "-Identity" wrong.

Top 50 Contributor
Posts 53

correct, when I typed it in the forum I did spell it incorrectly, but even when it is spelled correctly the command fails. 

Is it possible to get an answer on how to get the command working?

 

 

 

Top 10 Contributor
Posts 640

Contact Quest Software - they created it. I'd start at www.PowerGUI.org for assistance. It's always best to contact the authors, if you can. They'll have the best idea how it works.

Top 50 Contributor
Posts 53

Thanks, I'll do that, 

Top 10 Contributor
Posts 640

So, a couple of clarifications for you.

First, I don't work for Idera, and nobody on these forums works for Idera. We volunteer our time. I'm sure Idera appreciates your purchase of PowerShell Plus, and I enjoy the product myself, but these forums are not a paid benefit of owning the product - they're a community resource. I try to do the best job I can in the time I'm able to spare.

Second, you're more than able to get general scripting help here. Many, many, many people have. But you're asking a specific question about a specific command created by Quest - and I'm not able to answer your question. Given my inability, I thought it best to direct you to the people who wrote the command you're using, since they will know exactly how it works. I'm sorry if that wasn't helpful to you, but since I can't personally be helpful, I thought I'd try and direct you to someone who could be.

 

Top 50 Contributor
Posts 53

Thank you, I do appreciate the help, it's just frustrating that it's difficult to get any information on the commands as I have searched for hours over several days and maybe what I am trying to do is not possible.

I like the Idera PowerShell Plus tools which is why I purchased them and I realize everyone that replies in a forum is volunteering, I do a ton of that myself, just not in scripting yet, but hopefully soon.


Thanks again for the great response time as that is not common in many forums, hence why I come here.

 

Top 500 Contributor
Posts 6

Hi, i dont have a Active Role Server in acces right now - but you do have. So try to assign the results to a Variable like $myResult=Get-QARSOp....

to check if there is a result do

if($myResult -ne $null) { echo "some user match"; $myResult[0].GetType().FullName; $myResult[0]|get-member; }

if you provide my with the output from GetType and get-member i might be able to help you putting it to a report. As for the Attribute Target you might want to check the GetType as well - in the Output i can see that there is an escaped comma in the distinguishedName so you might need to put $_.Target in Quotes before passing.

 

Page 1 of 1 (10 items) | RSS
Copyright 2012 PowerShell.com. All rights reserved.