The Script Library: New and Improved

Well, not new really, but definitely improved 😉

When you visit the Script Library at http://www2.adminscripteditor.com/ScriptLibrary you’ll see that it matches the layout of the site as expected and the scripts that were on the old one are indeed carried forward to this new release of the service. What you’ll also find is that we are leveraging GoogleConnect for credentials in the ScriptLibrary.

To make things easier on everyone, we eliminated the need for a site/support account, but for the ScriptLibrary we really do need a personal account to pull it off. We started to dabble in GoogleConnect here and have leveraged that here for a couple of reasons. The biggest reason is you don’t have to create a new account! You can use your existing Google, Twitter or Facebook account instead of having to manage an additional account.

So it is up and running now and we’d love for you to check it out and let us know what you think. Thank you in advance!

Scripting 101

Oh my gosh!  Joe the scripting guy just left and guess what??!!??  I now get to do the login script for the entire enterprise and do not know what to do??!!??  Where do I go?  What do I do?  Sound typical?  If you speak with anybody out there who has done domain login scripting, it has pretty much played out in this scenario

Let’s stop for a second..  Take a breather..  I know.. I know, your boss is crawling down your neck asking you to add in a new drive mapping for Accounting

  1. Get a lay of the land
  2. What tools do you have available?
  3. What resources are out there?
  4. Check to see if you have appropriate domain rights
  5. Test test test..
  6. Implement

First of all, you are in IT so you know the one thing that is constant is change.  That is, things are always changing..

Get a lay of the land

  • Do you know where all of the DCs are?
  • Replication schedules?
  • Servers?
  • Workstations?
  • Printers?

I am not going to go in to all of the tools/applications that are available to determine this information

What format is the script in?  Is it KiXtart, VBS, GPO?

What tools do you have available?

  • Editor: For example: Admin Script Editor
  • The script files themselves, you may want to create a test script to verify if there any issues that come up before implementing into prod.  Be sure you have a BACKUP of any scripts you change – it will save you heartache later (trust me)!
  • The script parser itself (regular run and debug mode): kix32.exe, cscript.exe/wscript.exe, autoit3.exe, etc.  This will typically show you where there are problems.  Check for return codes, etc.
  • Deadline: While not a tool per se, it gives you a time container to work in

What resources are out there?

  • Documentation – When you download KiXtart or AutoIT for example, there are some examples included of what you can do with the product
  • Support Forums – A support forum is a treasure trove of information from people just like you that have had similar issues
  • Colleagues – Has anybody in the department done scripting before?  Maybe somebody a little obscure like your Report Writer..  What is good about this is that they have gone down the path you are starting to go down
  • Former colleagues – What have you done in the past that you can leverage a former colleague?  Please be careful and respect the person’s time as they are most likely on the clock and ask them if it is a good time to talk and if not, book another time to chat

Check to see if you have appropriate domain rights
If you cannot get to the script with write privileges, you will need to talk with your Domain Administrator.  If you are not sure, talk to your Manager for the appropriate policies and/or procedures. YMMV.  Note: This maybe a procedural issue where you have to put the scripts/updates in a specific location to be picked up and you will have to wait for domain replication to take place

Test test test..
Typically, as a scripter you do not have a software QC resource to test your scripts, for example.  Usually, you are on your own for testing, verifying, and updating.  Be sure to have a back-out plan in the event things don’t work.  Be careful oh Obi-Wan!

Implement
Once you have tested the script, implement into production.  You will hear if there is an issue – I know that is a bit hard to hear, but we all have stumbled.

Command-Line Add-ons

External Batch software

There are a lot of great command-line tools that come with Windows, but did you know there are number of great third-party DOS (or command-line) tools as well?  This is not intended to endorse or promote any application, but to show that there are tools available to help you do your job.  This is also by no means a complete list.

PowerShell Scripting – Getting Started

Getting started with PowerShell..

PowerShell is a “new kid on the block” in the scripting arena..

Be sure you have PowerShell installed.  If you run Windows Update, it should be installed automatically..

To start it, you can simply go to a Command Prompt (CMD.EXE) and type in powershell <ENTER>

To call up a script, you can just type in the name of the script and press the <ENTER> key.

For example type in:  rts-extract, or rts-extract.ps1, or can you use “command-line” completion, by pressing the <TAB> key.

Note: There is a caveat to running a PowerShell Script.  After you install it, you cannot run scripts as your computer system by default blocks them after installing PowerShell.

Enable Script Support in PowerShell..

  1. Open PowerShell (if you are running PowerShell on Windows Vista, right-click your PowerShell icon and select Run as administrator. If you don’t do this, you will not be able to enable script support).
  2. Check the current script execution policy by using the Get-ExecutionPolicy cmdlet. To do this, input Get-ExecutionPolicy and press Enter on your keyboard. PowerShell will return a value of Restricted.
  3. To change the script execution policy, use the Set-ExecutionPolicy cmdlet. Input Set-ExecutionPolicy unrestricted and press Enter on your keyboard.
  4. To ensure that the script execution policy has been changed, use the Get-ExecutionPolicy cmdlet again. PowerShell should return a value of Unrestricted.

So, now you will get the results you are looking for in the resulting CSV file.

Here is our code we are using..  Note: The is part of an application I use called RoyalTS and it uses an XML configuration file for the servers I connect to.  I had a need to extract out Server Names, IP, etc. and it was shared with me that this can be done pretty easily in PowerShell.

[xml]$Document=Get-Content ..\PIBConnections.rts;
$Categories=$Document.SelectNodes("/RTSDocument/Categories/RTSCategory");
$Connections = @(
 foreach($Category in $Categories){foreach($Connection in
 $Category.Connections.RTSConnection) {$Connection|Select-Object CategoryName, ConnectionName, Host, User, Domain}}
)
$Connections|Export-Csv -path .\test.csv;

To leave PowerShell, just type in exit and then exit again to leave the CMD prompt.

This is by no means a complete lesson in PowerShell, but a high-level of one of the things you can do with it..