Automation archives - The Multifunctioning DBA

The Multifunctioning DBA:

Automation

Sep 18 2009   4:37PM GMT

AD Audit in Powershell



Posted by: Colin Smith
AD, Powershell, Audit, Automation, Administration

I have mentioned this before but I have finally done what I set out to do and re-wrote my old vbscript that audits AD Accounts based on Create Date and Last LogonDate in Powershell. This is another great example of how much better powershell is and why everyone should now it. My VB Script was just under 800 lines of code and that was without many comments that documented the process. Now I feel that documenting scripts is very important. This is because I have had to try to fix other peoples scripts when they did not document it well and it is not fun. My powershell version of the same script with added functionality as well as over 100 lines of comments is only just over 400 lines. That means that I was able to remove about 500 lines of actual code from the script as well as add functionality to the script.
I will break the script down and post each one of the functions with a good explanation of each in my next few posts. It is a very cool script and it could be added to and customized to fit any situation that you may need. My version is based on my companies policy of disabling an account after 90 days of inactivity and deleting the account after 180 days of inactivity. My company runs the script weekly and the script sends out emails about the accounts that have been disabled and deleted to the needed personal so that the appropriate paperwork can be completed for those accounts. The script is soon to be posted. I am still testing but I will have it very soon.

Aug 18 2009   6:00PM GMT

Powershell Profile



Posted by: Colin Smith
Powershell, Powershell Tips, Scripting, Automation, Administration

The Powershell Profile is a script that druns anytime you launch Powershell. This is handy so you can ste up variables, add snapins, or just do what ever you like or think is cool when launching Powershell. I was just editing mine, which you can do by:

notepad $profile

This will pull up your profile so you can edit the script. If you would like to know where the script is located then just do a $profile to get the full path. Anyway after I edited my profile I wanted to reload the profile so that all the new things I just added would be available in my current powershell session. Like most things in Powershell this is simple.

. $profile

This will re-run the profile script and now all your new goodies are available