" /> The Japan Page: August 2006 Archives

« July 2006 | Main | September 2006 »

August 30, 2006

Sample Script - Check web server from a batch script

OK, just to prove you can do anything with a command line batch script... how about verifying your web server is up...? Why use an application when you can script it? :-)

Thanks to the IIS 6.0 Resource Kit tool TinyGet.exe, you can do amazing things from the command line.

I'll leave "whether you should" up to you...

Requirements:

  • You need tinyget.exe.
  • A command line SMTP mail utilty like bmail, or postie would be helpful. I used to use postie a lot, but bmail does 80% of the features for free. This script is written for bmail.
  • A web server to monitor... doh!


How it works:
Pretty simple really, you need a page on your web server with static text content that tinyget can grab. The script then runs as often as you schedule it (mine runs every 3 hours during the day), verifies it can get the page and trigger string, and alerts you if it can't. I use this to verify that my home server on my DSL line is up, and that my Dynamic DNS registration is current.

If it goes down, I fix it when I get home. TinyGet is capable of quite a lot, including grabbing pages over SSL, but I just need a simple "It's down alert". Whatsup or any number of monitoring tools are capable of this, but batch scripts are free.


Download the script here or cut and paste from the following.

::REM ------------------- Begin sample batch script ------------------------
::REM Sample batch programming script Serverup.cmd
::REM (C)2006 John D. Seaman, Copylefted under terms of the GNU/GPL
::REM by John D. Seaman, www.japan-page.net/batch

@echo off
cls
echo.
echo.
echo _____ __ __
echo ^/ ___^/___ ______ _____ _____^/ ^/ ^/ ^/___
echo ^\__ \^/ _ \^/ ___^/ ^| ^/ ^/ _ \^/ ___^/ ^/ ^/ ^/ __ \
echo ___^/ ^/ __^/ ^/ ^| ^|^/ ^/ __^/ ^/ ^/ ^/_^/ ^/ ^/_^/ ^/
echo ^/____^/\___^/_^/ ^|___^/\___^/_^/ \____^/ .___^/
echo ^/_^/
echo S e r v e r U p V e r i f i c a t i o n S c r i p t 0.02a
echo.

::REM ASCII art generator on the web @ http://www.network-science.de/ascii/


::REM ------------------ Begin user configuration --------------------------------------

::REM Set variables

set _log=log.txt
set _frm=serverMon@yourdomain.com
set _too=cellphone#@yourwirelesscarrier.com
set _hst=smtp.server.com

::REM Initialize the alert variable.
set _alert=0


::REM I look for a specific page (ismyserverup.asp) because I use a blog and didn't choose to embed my test string "smeg".

set _page=ismyserverup.asp
set _trigger=smeg


::REM Generate the servers.ini file. Add or remove FQDN lines for each web server you want to check.
::REM You need at least one entry, but this utility will loop through as many lines as you wish to add.

echo www.mydomain.com>servers.ini
echo home.mydomain.com>>servers.ini
echo alternate.mydomain.com>>servers.ini


::REM ------------------ End user configuration --------------------------------------


::REM Create the log file

echo.>%_log%
echo Server test script executed on %computername% on %date% at %time%. >>%_log%
echo.>>%_log%
echo.>>%_log%


::REM Do it already...

for /f %%i in (servers.ini) do call :doCheck %%i
echo.
echo Finished.
sleep 5


::REM Check the alert status

if "%_alert%" == "1" (goto :blastSMTP)
echo Completed without errors.
echo Completed without errors.>>%_log%
goto :EOF

:blastSMTP
::REM Send out the SMTP alert

set _sbj="Alert: One or more errors found, web services are down."
echo.
echo.>>%_log%

echo Errors detected, e.mail sent.
echo Errors detected, e.mail sent.>>%_log%


bmail -f %_frm% -s %_hst% -t %_too% -a %_sbj% -m %_log% -d

goto :EOF

::REM ------------ F U N C T I O N S -----------------------------

:doCheck
::REM Do it already!

::REM Get content from the web server

tinyget -d %1 /%_page% >_out.txt


::REM Check the content

type _out.txt | find "%_trigger%"
goto :result%ERRORLEVEL%


:result0
::REM Server is

echo Server %1 is up, no problems detected.
echo Server %1 is up, no problems detected.>>%_log%
echo.>>%_log%

goto :EOF


:result1
::REM Server is down

echo The server %1 was not available.
echo ALERT: The server %1 was not available !! >>%_log%
echo.>>%_log%

set _alert=1
goto :EOF


:EOF
::REM ------------------- End sample batch script ------------------------

August 29, 2006

Sample Script - Network Appliance snapshot monitor

As part of a HA Exchange 2003 rollout using iSCSI on Network Appliance filers, I needed a utility to monitor that our snapshots were running every few hours without issues. I couldn't find anything, so I wrote a script to do it.

Here's a little background:
We're running Exchange 2003 on 2 node MSCS clusters, with the back end storage on Netwok Appliance FAS-960c (cluster) over iSCSI. We have an R200 NearStore hooked up to Veritas NetBackup over NDMP. Exchange backups are run through SnapManager for Exchange Snapshot and SnapMirrored from the filers to the R200, then to tape. We snapmirror every 3 hours during the business day.

The Goal:
If the snapshots on the NearStore are ever older than 4 hours, we need to be alerted. SnapManager for Exchange will alert us if the backup process fails between Exchange and the front end filer, but it doesn't (currently) monitor that the snapshot was successfully snapmirrored all the way to the NearStore.

Requirements:
1. This script connects to the NearStore over RSH, calls snapmirror status, then decides if any of the lag times is older than (four) hours. In order to run this, you'll have to configure your filer to accept RSH connections from the box and account running this script.

2. Change the SMTP alerting variables for your environment. This script is written to use bmail, a freeware SMTP command line utility, but can easily be modified to use postie or blat.

3. You can change the alarm on x hours of lag time by modifying the script where lag time comments show 4 hours. (Total of 2 lines).


Deployment:

Copy the script, save as a .cmd file. Change the config and schedule it to run as a scheduled task. Make sure you've added the host and account to the RSH access table on all filers and your NearStore.


The Script:

Download here, or cut and paste the following code...


::REM -------------------------------- Begin Sample Batch Script ----------------------------------------
::REM Network Appliance Snapmirror Monitor script "SnapMonitor"
::REM by John D. Seaman, www.japan-page.net/batch
::REM (C) 2006 John D. Seaman, copylefted under terms of the GNU/GPL


@echo off
cls


::REM About this script...

echo.
echo Network Appliance SnapMirror Monitor v.2005.6.15 by JDS
echo.

echo.
echo This batch script will confirm that the lag time on SnapMirrors
echo on the R200 are not older than 4 hours. Anything older indicated
echo a problem with the SnapMirror process.
echo.
echo Due to a limitation with looping logic in batch files, this script
echo will alert and report only 1 instance of a lagging snapmirror. If
echo multiple lagging snapmirrors exist you'll notice this in the log file
echo anyway.
echo.
echo This script must run against both filers and the near store to
echo produce a complete report.
echo.
echo.
echo.


::REM ---------- Begin User Configuration ---------------------

::REM You need each front end filer and the nearstore to appear on a line in filers.ini. I prefer to
::REM compile this on the fly because people have a bad habit of deleting static .ini files...

::REM Generate filer list...

echo filer1>_filers.ini
echo filer2>>_filers.ini
echo nearstore1>>_filers.ini


::REM Set SMTP alert variables

set _sbj="Error: SnapMirror replication problem detected"
set _msg="A SnapMirror error was detected. Examine the log file for more info."
set _hst=smtp.yourdomain.com
set _frm=%computername%@yourdomain.com
set _too=admin@yourdomain.com


::REM ---------- End User Configuration ---------------------

::REM Debug mode (0 deletes files, 1 keeps output files)

set _debug=0

::REM Create a log file, initialize error variable

set _log=snapmon.log
set _alert=0


echo.>%_log%
echo.>>%_log%
echo.>>%_log%
echo NetApp SnapMirror Monitor v.2005.6.15 by JDS >>%_log%
echo Generated by %computername% at %time% on %date%... >>%_log%
echo ------------------------------------------------------------------------------ >>%_log%
echo.>>%_log%
echo.>>%_log%

::REM Do it finally...

::REM Get the SnapMirror status output in a loop for all 3 NetApp devices...


::REM Process in a loop

for /f %%i in (_filers.ini) do call :checkfiler %%i

echo.
echo.>>%_log%

::REM Send out SMTP alert, if needed.

if /i %_alert% EQU 1 (
echo Alert condition detected, sending alert e.mail...
echo Alert condition detected, sending alert e.mail...>>%_log%
echo ^
echo ^ >>%_log%

bmail -f %_frm% -s %_hst% -t %_too% -a %_sbj% -b %_msg% -m %_log% -d -h >smtp.log

echo Alert mail send call completed...
echo Alert mail send call completed... >>%_log%
)


echo Finished processing...
echo Finished processing...>>%_log%

::REM Cleanup

if /i not %_debug% EQU 1 del /q _*.txt

goto :EOF


::REM ---------------- F U N C T I O N S ----------------

:checkfiler

echo.
echo.>>%_log%

echo Now checking filer %1
echo ---------------------------------------------
echo Now checking filer %1 >>%_log%
echo --------------------------------------------->>%_log%

::REM Get the filer snapmirror status

rsh %1 snapmirror status >_%1out.txt

::REM Strip header line (lag time)

type _%1out.txt | find ":" >>_%1out2.txt


::REM Get the lag time field...

if exist _error.txt del /q error.txt
if exist _snaplag.txt del /q _snaplag.txt
for /f "tokens=1,2,3,4,5*" %%i in (_%1out2.txt) do echo %%l >>_snaplag.txt

::REM Get the first two digits of the lag time, find anything >= 4

for /f "delims=:, tokens=1,2,3*" %%i in (_snaplag.txt) do (
echo SnapMirror lag time value is %%i...
if /i %%i GEQ 04 (set _alert=1)
)

echo Alert status for host %1 is %_alert%...
echo Alert status for host %1 is %_alert%...>>%_log%

::REM This line strips out any lag times LEQ 03. Change this is you change the lag time from "4" hours.

type _%1out2.txt | find /V " 00:" | find /V " 01:" | find /V " 02:" | find /V " 03:">>%_log%
del /q _%1out2.txt

echo.>>%_log%
echo.>>%_log%


goto :EOF


::REM ---------------- E N D ----- F U N C T I O N S ----------------


:EOF
::REM -------------------------------- End Sample Batch Script ----------------------------------------

August 28, 2006

Exchange 5.5 Site Consolidatin Notes - object rehoming

When consolidating an Exchange 5.5 site: before turning off 5.5 you have to rehome the Distribution Lists and custom recipients. Here are some notes...

Run the exdeploy tool in scan mode first.

I ran it twice, once to get Distribution Lists and again for custom recipients (contacts). The output is XML, rename the first file before running the command again.

To Scan for all Distribution Lists to be migrated:
exdeploy.exe /gc:AD_GC_server /m:D /MA:S /ss:Exchange55site /p:pathToOutputLogFile

(Don't be surprised when it says "starting the cross-site move", as long as MA:S is set to Scan)

To get a count of how many DL's you have, try the following from the command line
type ToBeMoved.xml | find "Object DN" /c

To Scan for all Contacts to be migrated:
exdeploy.exe /gc:AD_GC_server /m:C /MA:S /ss:Exchange55site /p:pathToOutputLogFile

How to migrate objects
In order to migrate the objects, you re-run exdeploy with the MA:U (migrate action:update) switch. I found you need to specify the full path for ithe input file (XML) and the log file, and the resulting command was getting too long to type. So, here's a simple script to do the work...


::REM -------------------- Begin Sample Batch Script -----------------------------
::REM by John Seaman, www.japan-page.net/batch
@echo off
set _pth=c:\utils\exchange.2003.deploy.tools\Exdeploy\

exdeploy /s:exch55server /gc:AD-DC=GCserver /M:D /MA:U /SS:55-site-name /TS:ex2kx-site-name /ES:ex2kx-expansion-server /f:%_pth%\DistroLists_ToBeMoved.xml /p:%_pth%\testlog.log

pause
::REM -------------------- End Sample Batch Script -----------------------------

August 25, 2006

Why you shouldn't take your Birthday off...

Recently my co-worker, we'll call him Langey, took his Birthday off. His staff were a little sad to not see him on his special day, and felt obligated to get him something to unwrap. Four industrial size rolls of plastic wrap and 2 hours later, his entire cube, and everything inside it were individually wrapped.


Click here to see the entire Gallery...

Perhaps this is a sign of stress in IT, but at least there won't be any dust in his cube this week. He'll be back tomorrow, can't wait to see his face when he walks in...

August 24, 2006

Useful Zantaz EAS SQL Queries

About a year ago I rolled out Zantaz EAS (Exchange Archive Solution) to 3000 users. We were the first large production rollout onto NetApp filers for Zantaz, and after a bunch of tweaking we got it up running. (Zantaz says you can run the Indexer and Archiver over CIFS, but don't do it! :-)

Anyway, here are a few useful SQL queries you can use when troubleshooting or performing maintenance on your EAS system.

Note: These queries assume you use MS SQL as the backend for your EAS deployment. Feel free to tweak as required for your version. We are still running 4.1 SP1 here, but my understanding is 4.3 hasn't made great changes to the DB structure at this point.

Some simple queries to get started with...

Find a user with the LegacyExchangeDN similar to SmithJ1
select * from users where objDistName like '%SmithJ1%'

Find all users who are enabled in EAS (enabled is zero, disabled is 1)
select * from users where easStatus = 0

Get a count of active EAS users (change easStatus = 1 for disabled users)
select count(*) from users where easStatus = 0

Find how many messages user 1670 has indexed.
select count(*) from INDEXED_BY where USERID = 1670

Find how many messages user 1670 has archived.
select count(*) from refer where USERID = 1670

Find out which search Indexes user 1670 is assigned to.
select * from user_search_idex where userid = 1670


Some simple update statements:

Change the ObjDistName (AKA LegacyExchangeDN) for user 1670
update users set objDistName = "/O=ORG-NAME/OU=SITE/CN=RECIPIENTS/CN=USER-NAME" where userid = 1670

Disable user 1670 in EAS
update users set easStatus = 1 where userid = 1670


Some more fun queries...

Find all users who have more than one DB entry by username, outputs the Username and count... *1
select username,count(username) as number from USERS group by USERNAME having count(username)>1

Find all users who have more than one DB entry by username, outputs the Username and ObjDistName...
select username,objDistName from users where username in (select username from users groub by username having count(username)>1)

The userstatus field has some great potential for scripting. This field is incremented by the last job number after a successfull archive pass, so you can find users failing to archive, or estimate the last successfull archive date from this field.

Find all users who have not been archived since job pass # 5000
select * from USERS where USERSTATUS = 5000

Related to the above, find all users who are not disabled and have not archived passed a userStatus value (<5000)
select * from users where userStatus <5000 and easStatus <> 1

Got an EAS client error message that references a specific message ID? Get the message details (msgid=99999.)
select * from EASSRV.PROFILE P where msgid=99999

Note: This field may be known as PROFILE P, or have a custom header appended to it depending on your installation.


Notes:
1. I usually replace select * with select username,userId, objDistName and limit the return fields to just what I need.

2. The objDistName is a key field so you cannot have 2 identical values.

3. The objDistName field MUST BE in UPPERCASE. If you modify it, don't add lower case chars.

I will post some batch scripts I have for manipulating the EAS DB from the command line using SQLCMD.exe in the near future. Have fun !!

August 23, 2006

Artsy Ken, AKA Ken Lee's Photography

Ken Lee is another long term resident of Tokyo and a great photographer. We started going "shooting" together right around the time Ken got back into photography. He always called me Sensei (Teacher), but I didn't figure I was really teaching him anything, he's a natural (and far surpassed his not really "Sensei" anyway).

Ken is especailly good with Black and White, and is a regular poster of his photographs, unlike other persons we won't name like yours truly...


http://artsyken.com
Better than the real thing...

Ken's got some other photo sites floating around, I know he's a regular poster on TrekEarth also, so I'll try to dig out the URL's. I've never really been a good B&W Photographer myself, despite the fact that the urban jungle of Tokyo is absolutely the best place on the planet for B&W photography.

I've heard through the grapevine that Ken is moving to Singapore soon, so we'll look forward to some pictures from Sing too. He's also travelled extensively around Asia, hey Ken, where are those pictures...? Amyway, check it out !!

August 21, 2006

Sample Script - Convert a text file to a system variable

When running a batch script there are times when you want to take the output of a utility and/or file and convert it to a system variable. Batch was not designed for this, but there's an easy way to do it....

In this example, we'll take a line of output from Systernals PSInfo.exe and convert it to a variable.


::REM ------------------ start batch sample script -------------------------------
::REM by John D. Seaman, www.japan-page.net/batch

::REM Call www.systernals.com psinfo.exe, put results in a text file

::REM Get output from psinfo to text file "_out.txt"
psinfo.exe >_out.txt

::REM Use find, isolate the Product Version line
type _out.txt | find "Product version:" _out2.txt

::REM Create a loop, grab the 2nd field (AKA the version)
::REM Tokens states we're looking at 2 values (and grabbing the second)
::REM Delims states break the string at the colon
::REM If you call this directly from the command line, change %%i below to %i.

for /f "tokens=1,2* delims=:" %%i in (_out.txt) do set var=%j

echo Your new variable VAR is %var%

::REM ------------------ end batch sample script -------------------------------

So, a simple for loop takes a value from a text file and converts this into a variable. What can you do with this? I have run some rather complex scripts such as dumping every workstation name in a 3000 user environment from AD, then calling a script against all the workstations to do some maintenance - check AV signatures in an outbreak, scan for disk space, verify a service is running, etc. With the for loop, you can process each machine, find the value your looking for, then dump the results into a log file or continue processing based on the result.

You can also use a 3rd party text manipulator such as SED (a GNU *Nix tool), or my old fav TextTools32 (t.exe), but the above trick will let you do it from the native windows command line.

August 20, 2006

Strange File - FlushServ.exe

I recently ran into a strange file (and service) running on my Windows 2003 server called FlushServ.exe. An Internet search didn't show any useful hits or details on the file, but I quickl figured it out.

In my case c:\windows\system32\flushserv.exe was installed by the LSI Logic Power Console Plus v.5.00 utility. This is the RAID console software for my LSI Logic MegaRaid SATA 150-4, and the process (service) is designed to flush the RAID cache on shutdown (or presumably when called through an API). Mystery solved, it's not a hostile file.

August 19, 2006

www.JohnSeaman.com - Fine Art Photography of Japan and Asia


I started my own stock photography site back in late 2000, perfect timing just at the end of the .com dot bust. I ended up ripping out the shopping cart and leaving the shell up to display the photos. Along comes a big project at work, then my daughter arrived...

Fast forward 5 years, my daughter is almost 4 now. I moved back home to California, just wrapped up a big Exchange migration, and discovered SmugMug, based in Mountain View CA.


www.JohnSeaman.com

SmugMug is a great, professional level digital image hosting site for photographers. Be advised, it's not free and has enough features to drive an end-user batty, but if you're a semi-pro photographer (like me, I just don't have the time to be a pro) or a real pro but don't want to host your own site, this is the place to be.

I had previously scanned around 1500 of my best slides (positives) out of around 10,000 in my library. I'm adding the descriptions and keywords and posting the galleries up on photography.JohnSeaman.com .

It will take a while to get everything posted, classifying and adding keywords makes me really sleepy at night. But it's a lot better than the previous web site that sat stagnant for 5 years. Not only that, the photos can be purchased as prints and delivered right to your house.

August 18, 2006

SEO Tools (Search Engine Optimization)

Found a great site full of free SEO tools...

Quote:

The SEO Tools found in this section were designed to assist you in configuring your website(s) for search engine optimization within the different search engines. Please select one of the SEO Tools from below to begin optimizing your website(s) for top placement within the search engines. Our SEO tools do not support any secured server sites due to authentication issues.

http://www.seochat.com/seo-tools/

August 17, 2006

Customized Search Template in MovableType 3.x

MovableType has added numerous improvements since I started using it with v.2.2x. One of the sucky features are the search pages and templates that generate results, they're CGI and not as easy to customize as the rest of the shell.

But, turns out you can still do it...


1. Go to the search_templates directory and make a copy of default.tmpl, then rename it. I have two separate domains on my server, so I call them search_domain1.tmpl and search_domain2.tmpl. Don't worry, no one will ever see the names, so get creative...!

2. Open up mt-config.cgi and add the following line:

AltTemplate japan-page search-domain1.tmpl

Where japan-page is the template name and search-domain1.tmpl is the actual template file name we created in step 1.

Before:

-snip-
##################### REQUIRED SETTINGS ########################

CGIPath http://www.japan-page.net/blog/
StaticWebPath http://www.japan-page.net/blog/mt-static/

#================ DATABASE SETTINGS ==================
-snip-

After::

-snip-
##################### REQUIRED SETTINGS ########################

CGIPath http://www.japan-page.net/blog/
StaticWebPath http://www.japan-page.net/blog/mt-static/
AltTemplate japan-page search-domain1.tmpl

#================ DATABASE SETTINGS ==================
-snip-


3. Edit the new tmpl file to your hearts content.




4. Test the template file before you put it in production. You can call the template file on the following URL before you make the cutover.

http://www.yourdomain.com/path/to/mt-search.cgi?Template=Name , where Name is the name you assigned in step 2.


5. When you're ready to put the new template in production, edit your index files and add the following:

<input type="hidden" name="Template" value="NAME" /> where, once again, NAME is the name you assigned in step 2.

In my blog the search box is part of a sidebar module, but regardless the code is the same:

<form method="get" action="<$MTCGIPath$><$MTSearchScript$>">
<input type="hidden" name="IncludeBlogs" value="<$MTBlogID$>" />
<label for="search" accesskey="4">Search this blog:</label><br />
<input id="search" name="search" size="20" />
<input type="hidden" name="Template" value="japan-page" />
<input type="submit" value="Search" />
</form>


See the MovableType 3.2 User Manual here. (Less details, this article is better for kinda sorta still MT noobs like me).

New Photo Gallery - Fall Leaves at Night

A new photo gallery is up. This is a small collection of photogrpahs of the beautiful Autumn leaves at night. Most of the pictures were taken at Kiyomizu Temple (Kiyomizu Dera) in Kyoto Japan. For a short month during the fall, Kiyomizu Temple is open at night with absolutely brilliant lighting at night. As the most famous temple in Kyoto, it attracts large crowds, which do make photography a little more challenging.

Click here to view the entire Photo Gallery.

There is a small entrance fee charged at night to help offset the costs of running the lighting. Outside of this special fall lighting, the temple is closed at sundown the remainder of the year.

August 16, 2006

Sample Script - Custom Attribute yields easier LDAP searching in ADUC

During a recent Exchange 5.5 to 2003 cross site mailbox migration, I needed a simple way to select a large number of users out of AD, right click and say move mailbox. Sounds pretty simple, right? But what if you use multiple levels of OU's in your AD structure, and the users in question span across multiple OU's / Departments / Etc? I was moving 200 users per night, but they didn't all fit in a single department, or physical location. So, I cheated....

I created a script that modified the CustomAttribute3 field with a known value that an ADUC Saved Query could then find. I run the batch script against a list of user names, add the tag "20060816migrate", then go into a ADUC and get busy.

If it sounds like a lot of work, it isn't. You wouldn't bother with this for a 12 user move, but the 5 minutes it takes from start to finish save hours in a 2500 user move.

Notes:
*I chose customAttribute3 at random, choose whichever you aren't using. Don't blindly overwrite the employee number the HR database syncs in...
*Use a unique string for your search term, something tied to the date is very effective. I don't bother to go back and delete or reset the field afterwards because (1) I'm lazy, and (2) if I was ever curious when a user was migrated I can always go back and look at that field.

The Script, available for download from here.:

::REM ----------------- Begin sample batch script -----------------------------
@echo off
cls
::REM Get Legacy Exchange DN from AD sample script
::REM By John Seaman, www.japan-page.net/batch
::REM (C)Copylefted under terms of the GNU / GPL


::REM This script will take a user name (samAccountName) and add the custom value specified below into the
::REM AD Custom Attribute field #3. A custom LDAP script can then search this field and select all users
::REM for the exchange attributes removal/migration/etc.

::REM Note: to see the field from ADUC, go to Exchange Advanced tab, choose Custom Fields.

::REM This script requires adfind.exe and admod.exe from from Joeware.net (http://www.joeware.net/win/free/tools/adfind.htm).
::REM Big thanks to Joe Richards !!!

::REM Usage call this script and append the user ID after it, updateLdap.cmd
::REM Or run a loop like the following....
::REM for /f %%i in (userlist.txt) do call :processUser %%i
::REM pause
::REM goto :EOF

::REM Be sure to update the _baseDN field for your domain!

::REM Set variables

set _dc=MyDomainController
set _baseDN="OU=MyOuInActiveDirectory,DC=root,DC=MyDomain,DC=com"

::REM Create log file

set _log=updateLdap.log

::REM Set the text to add to the custom field

set _text=20080816migrate


:processUser
::REM Start

echo Now applying update to user $1...


::REM ---------------------
::REM Get username base DN:


::REM Time to get jiggy...

adfind -b %_baseDN% -f "(&(objectcategory=user)(samAccountName=%1))" -dn >_out.txt


type _out.txt | find "dn:" >_userDN.txt

::REM Fix the UserDN by nuking the first 3 characters...
::REM I use textTools32, replace with SED or your favorite text editor

type _userDN.txt | t repl 'dn:' '' >_userDN1.txt

for /f "delims=@" %%i in (_userDN1.txt) do echo User $1 DN is %%i >>%_log%


::REM ----------------------

::REM Call ADmod and fix the field

for /f "delims=@" %%i in (_userDN1.txt) do call admod.exe -h %_dc% -b "%%i" "extensionAttribute3::%_text%" -exterr >>%_log%
echo %errorlevel%


:EOF
::REM ----------------- End sample batch script -----------------------------

Create a Saved Query in ADUC:
Saved queries in ADUC are the slickest thing since instant coffee. Create a new query, choose custom search, then advanced, then paste the following into the Query String window...
(objectCategory=user)(extensionAttribute3=20060816migrate)

After you save the query, execute it and you'll get your entire user list in one window. Have fun !

August 15, 2006

Sample Script - Get the Legacy Exchange DN from AD

During a recent Exchange 5.5 to 2003 maibox migration, I needed to have quick and easy access to the Legacy Exchange DN (AKA the Obj-Dist-Name in Exchange 5.5). We use the Zantaz EAS (Exchange Archive System) here, and it binds to MB's in the GAL through this field.

The ADUC (Active Directory Users and Computers) MMC doesn't display this field, and opening up ldp.exe takes waaay too much time.

So, in typical impatient geek fashion, I wrote a quick command line script to grab the field out of AD.

This script requires adfind.exe from Joeware.net. Joe Richards has some great freeware applications so check his site out.

In this script I grab three useful fields

1. User DN (Distinguished Name). I grab this just so I can find out if the user account is sitting in the _Disabled account OU. This outputs in the format:
dn:CN=Seaman\, John,OU=ServerAdmins,OU=PA,DC=root,DC=mydomain,DC=com

2. HomeMDB. This way I know at a glance which MB server they're on.

3. LegacyExchangeDN. This outputs in the format:
/O=MyExchOrgName/OU=PA/CN=RECIPIENTS/CN=SEAMANJ

ADfind is an extremely powerful tool, and I'm actually grabbing all the fields through the LDAP call and just filtering out those I'm interested in, so you can tweak the find statement and grab whatever info you're looking for.

Notes:
* As coded, this script searches on the samAccountName, AKA NT user ID. More complex scripting could be added for a "like" search.
* The batch script has the DC and base hard coded. Be sure to modify those before running the first time..
* This was a quick and dirty script, so we don't vet the input text.

Download the sample script here, or copy from below.

::REM ----------------- Begin sample batch script -----------------------------
@echo off
cls
::REM Get Legacy Exchange DN from AD sample script
::REM By John Seaman, www.japan-page.net/batch
::REM (C)Copylefted under terms of the GNU / GPL

echo.
echo Getting legacy exchange DN for user %1...
echo.

::REM Fix the base and DC fields for your domain.
set _base=dc=root,dc=mydomain,dc=com

adfind -h domain_controller -b %_base% -f "samAccountName=%1" >_getOdn.out.txt

echo.
echo DN............................:
echo.
type _getOdn.out.txt | find "dn:CN="
echo.
echo.


echo.
echo HomeMDB.......................:
echo.
type _getOdn.out.txt | find "homeMDB:"
echo.
echo.


echo.
echo legacyExchangeDN..............:
echo.
type _getOdn.out.txt | find "legacyExchangeDN:" >_getOdn.odn.txt
type _getOdn.odn.txt | t upper
echo.
echo.

::REM Pause here so you can kick this off from the run bar if desired
pause


:EOF
::REM ----------------- End sample batch script -----------------------------

August 9, 2006

New Photo Gallery - Tokyo Station at Night

Night View of Tokyo Station, Tokyo Japan.  This Photograph is for sale in print, and poster format at john-seaman.smugmug.com More new photos - Tokyo Station at night. The Tokyo Station building is another iconic pre-war structure. It was heavily damaged in the fire bombings of Tokyo during the war, and after the war the top 3 floors were too heavily damaged to restore, so they were lopped off.


Click here to veiw the entire Photo Gallery.

Tokyo Station itself is a humongous structure with a great portion underground, and a much larger 1960's era station building on the Yaesu side. Until recently, all Shinkansen heading north from Tokyo departed from Tokyo station, and all those heading South departed from Shinagawa. This somewhat awkward setup required passengers traveling through Tokyo going North or South to get off the train, hop on a local train and travel several stations to get back on the Bullet Trains. In the last few years the Tokaido Shinkansen was extended through Tokyo Station to Shinagawa.

New Photo Gallery - The Atomic Dome (Genbaku Dome) in Hiroshima, Japan

I've finally posted my photographs of the Atomic Dome (Genbaku Dome in Japanese) in Hiroshima, Japan.

Click here to veiw the entire Photo Gallery.

Night View of the Atomic Dome (Genbaku Dome) in Hiroshima, Japan.


The building was originally designed by the Czech architect Jan Letzel and was completed in 1915 as the Prefectural Products Exhibition Hall, a kind of building common in Japan where locally made agricultural and industrial products are put on display and sold. (Think of a museum where the items displayed are for sale).

During the war years the building was used by the government agency in charge of fuel rationing. The building was the closest structure to the epicenter of the atomic blast that destroyed Hiroshima to survive. This was truly a well built and lovely building, and because the blast happened almost directly overhead, the force pancaked the roof and floors down to ground level, but left the walls and the iconic dome standing.

The Atomic Dome had some metal structural reinforcing bars added in the 1960's to prop up the aging walls, but is otherwise preserved just as it was shortly after the bombing. At night the Dome is lighted up brightly, from the outside with quartz lighting that give the walls a green color, and from the inside with tungsten based lights that give it an eerie orange glow.


It was added to the UNESCO World Heritage list in December of 1996.

More info about the building itself is available on Wikipedia

Sample Script - Runas MMC

I've just about completed a 2500 user Exchange 5.5 to 2003 migration (you'd be surprised how many laggards are still using Exchange 5.5). One of the challenges was quickly logging into several different AD domains to perform account maintenance.

Since Windows 2000 the "run as" feature has greatly simplified this, but you still have to click SHIFT while right clicking the icon. What if I'm too lazy? Write a batch script, of course.

So, here's a sample script to fire off a custom MMC console with one double click.

1. Create the console and save it. I give mine a specific name like NTDOMAIN_ADUC.msc and save them under c:\batch\runas .
2. Create a NTDOMAIN_ADUC.cmd script, copy the sample code below in and change it for your login.
3. Create a shortcut from the script to your desktop or quicklaunch toolbar.
4. You're done !

You could embed your domain password in the script, but I prefer to be promtped. That way when I change my password every 14 days (yah, right!) I don't have to touch the script.

You can create your own ASCII art on http://www.network-science.de/ascii/

This batch script has been tested on Windows 2000, XP and 2003.


::REM ---- Begin sample script ---
::REM Windows XP / 2000 / 2003 sample batch script "Runas MMC"
::REM By John D. Seaman, www.japan-page.net/batch

@echo off
cls

::REM ASCII art generator on the web @ http://www.network-science.de/ascii/
(Remember to neutralize the command characters with a "^".

echo _____ __ __ __ __ _____
echo ^| __ \ /\ ^| \/ ^| \/ ^|/ ____^|
echo ^| ^|__) ^| _ _ __ / \ ___ ^| \ / ^| \ / ^| ^|
echo ^| _ / ^| ^| ^| '_ \ / /\ \ / __^| ^| ^|\/^| ^| ^|\/^| ^| ^|
echo ^| ^| \ \ ^|_^| ^| ^| ^| ^|/ ____ \\__ \ ^| ^| ^| ^| ^| ^| ^| ^|____
echo ^|_^| \_\__,_^|_^| ^|_/_/ \_\___/ ^|_^| ^|_^|_^| ^|_^|\_____^|
echo.
echo R u n A s M M C S a m p l e S c r i p t
echo www.japan-page.net/batch

cd c:\windows\system32
runas /user:NTDomain\UserID "%windir%\System32\mmc.exe C:\batch\runasMMC\NTDOMAIN_ADUC.msc"

exit
::REM ---- End sample script ---

The Japan Page has moved...

Yes, the server is now up on a proper ISP, www.hostgator.com.

Before this, The Japan Page had been running on a very nice private server (1U) wiith a severe bandwidth limitation. Not that I get that many daily hits, but at least updating the site won't be quite as slow.