The Multifunctioning DBA

Sep 24 2009   7:30AM GMT

AD Audit in Powershell Script Part 2

Colin Smith Colin Smith Profile: Colin Smith

Now that we have some idea about what this script is about and what we would like to accomplish with the script lets get into it.

I have the code in the box below and I will just go over what I am doing . This is where the script will start so I am setting up my variables and then I will start to call the other functions of the script.
First I place on doing my own error checking where I care if an error occurs and I do not want to be notified or have the script stop if an error does occur so I Silently Continue. I get the time that the script started so I can log that for a few reasons. One is so that I know when the script ran last and two so I can know how long the script runs. I set up the variables that I care about such as $holdingdays, $disabledays, and $deletedays. Now I take those values to determine the dates for holdin, disable, and delete. In my company we have other companies that are on our domain and we have them separated out with OU’s that have a company name designation. that is what my $companies variable holds. Now I can start to call my functions.



########################################################## ## Main ## Set up variables and call functions of script. ########################################################## $ErrorActionPreference = "SilentlyContinue" $starttime = [datetime]::Now echo "Start 90-180 Script run at $starttime" >> "c:\90-180\90-180.log" $holdingdays = -30 $disabledays = -90 $deletedays = -180 $disabledate = [datetime]::Now.AddDays($disabledays) $deletedate = [datetime]::Now.AddDays($deletedays) $holdingdate = [datetime]::Now.AddDays($holdingdays) $companies = "name1", "name2", "name3" clear-content "c:\90-180\homedirs.txt" #echo "calling Get_Users" Get_Users #echo "calling Disable_Acconts" Disable_Accounts #Echo "Calling Get Disabled Accounts" Get_Disabled_Accounts #Echo "Calling Delete_Accounts" Delete_Accounts #Echo "Calling Mail" Mail $endtime = [datetime]::Now echo "End 90-180 Script run at $endtime" >> "c:\90-180\90-180.log" echo "#################################`n" >> "c:\90-180\90-180.log"

My next post will be about the get_users function. This is a fun one since it has to query all the DC’s.

 Comment on this Post

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to: