19 May, 2009

Smart Ping when restarting

Hi,
You restart a remote server because you installed some new MS updates and you need to know when it's back online.
What we all do?, start pinging the server and continue to do other things.
when we come back after few minutes to the ping window we see that the server is online but we missed to see it's gone offline.
The following script (I called it "Smart Ping") will check the output from the ping action and look for specific word to let you know that the server went down and went up again.

Fill free to change the words it searches as you see fit in your environment.

=======================================
echo off
cls
:dead
title Server [%1] is going to shut down [%time%]...
ping -n 1 -w 300 %1 find "Request timed out."
IF %ERRORLEVEL% == 0 (goto back_alive) ELSE (goto dead)
:back_alive
title Server [%1] is down [%time%]...
ping -n 1 -w 300 %1 find "TTL"
IF %ERRORLEVEL% == 0 (goto end) ELSE (goto back_alive)
:end
title Server [%1] is Back online [%time%]...
pause
=======================================

Enjoy...

10 May, 2009

How to get the DN from an NT name...

Hi,

If you are scripting you may came across the annoying problem of the DN name.
In everyday activity you use the NT name of an object from Active Directory but when you want to start scripting - no... you need the DN.

The following Script will help you convert on the fly the NT name to DN object.

===================================
private function TranslateNTName(ntname)
dim nto
dim result
const ADS_NAME_INITTYPE_SERVER = 2
const ADS_NAME_INITTYPE_GC = 3
const ADS_NAME_TYPE_1779 = 1
const ADS_NAME_TYPE_NT4 = 3
TranslateNTName=""
set nto = CreateObject("NameTranslate")
'on error resume next
nto.Init ADS_NAME_INITTYPE_GC , ""
nto.set ADS_NAME_TYPE_NT4, ntname
TranslateNTName = nto.Get(ADS_NAME_TYPE_1779)
on error goto 0
end function

wscript.echo TranslateNT4Name ("domain\user")
===================================

Enjoy

Get AD group members (including nesting)

I looked for some time now for a command that will give me all the members of a group even if it contains nesting groups.





I'm happy to inform you that the answer was allways under my nose.





The command was: DSGET.





The following syntax worked for me:


==================================


dsget group CN=Group_Name,OU=Groups,DC=domain,DC=local -members -expand


==================================





MS Link





You can mix it up with my tip on how to get the DN from an NT name and simplify the command...