The Multifunctioning DBA:

Administration

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


Jun 30 2009   8:13PM GMT

Select Folder Dialog Box



Posted by: Colin Smith
Powershell, Administration, Scripting

If you would like your scripts to interact with the user and have a nice popup box for a user to select a folder here is a link to an article that will help you out. I think this is pretty great.

 http://powershell.com/cs/blogs/tips/arch…


Jun 30 2009   3:38PM GMT

Reboot a Remote Windows Host Remotely



Posted by: Colin Smith
Powershell, Remote boot, Administration, Windows Administration

Say you need to reboot a server and this is something that you would like to automate based on certain criteria. For instance, I might want to reboot a server if I can talk to the server but for somereason my SQL Server is not up and running. If everything is configured correctly the SQL Server should start up again on boot. So you can do something like the following.

$varname = Get-WmiObject Win32_OperatingSystem -computername “remotemachine”

$varname.reboot()

Now you can check your SQL Server once the machine is back up.


Jun 26 2009   3:54PM GMT

Another Example of why you should learn Powershell



Posted by: Colin Smith
Powershell, Administration, Scripting, Server Administration

I was roaming around the web and reading some articles and I ran across the following blog post:

 http://bassplayerdoc.blogspot.com/2008/1…

I think this is a great reason why all administrators that deal with Microsoft products should learn powershell. I know some Administrators are happy with VBScript and I know that many people use Pearl or other languages. I am all for knowing them and using them when they make the most sense. Some languages are better at some things then others. I think that Powershell is the Future of Microsoft Administration and this is a great example. Check out the other articles on this Blog as well. Some really good stuff.