From the Directory

by stephen mcgroarty 6/15/2010 8:54:57 PM

Sometimes it is easy to actually come up with content, other times not so much. This is one that it took a bit of finding but it was something I got stuck on.

How do you get the Active Directory Schema information without remote desktop/console access. Now there are other ways to do this, but i was looking for a simple console scripted method. NTDSUTIL has the power to do this via a simple script

First an example

C:\Documents and Settings\smcgroarty>ntdsutil
ntdsutil:

Notice that the command prompt, it will continue to change for each section that you are in

ntdsutil: domain management
domain management:
domain management: connection
server connections: connect to server DCSRV1
Binding to DCSRV1…
Connected to DCSRV1using credentials of locally logged in user.
server connections: quit
domain management: select operation target
select operation target: list roles for connected server
Server "DCSRV1" knows about 5 roles
Schema - CN=NTDS Settings,CN=DCSRV2,CN=Servers,CN=Sites,CN=Configuration,DC=velcrohurts,DC=com Domain - CN=NTDS Settings,CN=DCSRV2,CN=Servers,CN=Sites,CN=Configuration,DC=velcrohurts,DC=com
PDC - CN=NTDS Settings,CN=DCSRV2,CN=Servers,CN=Sites,CN=Configuration,DC=velcrohurts,DC=com
RID - CN=NTDS Settings,CN=DCSRV2,CN=Servers,CN=Sites,CN=Configuration,DC=velcrohurts,DC=com
Infrastructure - CN=NTDS Settings,CN=DCSRV2,CN=Servers,CN=Sites,CN=Configuration,DC=velcrohurts,DC=com
select operation target:

After you get the values, you need to type quit, for each step.
select operation target: quit
domain management: quit
nntdsutil: quit
C:\Documents and Settings\smcgroarty>

Now to put this in a simple batch file:
ntdsutil domain management connection connect to server DCSRV1 quit select operation target “list roles for connected server” quit quit quit

Thanks the quick and dirty of it, hope someone finds this useful

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , , ,

Weekly Tip

Sometimes it can be handy

by Stephen McGroarty 6/8/2010 7:01:00 AM

Going to try something different here, I notice that I am not paying a lot of attention to my site lately, and there isn’t a good reason not to. So for the next 30 days, until July 8th, I am going to attempt to do a post a day. I am also going to try weekends as well. The reason for this is I have a lot of things that I want to share, and I have been meaning to share from basic tech knowledge and into cars. This will also be an exercise in brushing up on my writing skills, I seem to be lacking a little bit there.

For the first post lets do a scripts to remove all the scheduled tasks on servers. We want to list all the scheduled tasks on a server, ok not a problem if you have one server you can login and view them, or you can list them remotely with

schtasks /query /s ServerName
This will return a result such as

TaskName                             Next Run Time            Status        
============================================================
FileScript1                                        23:59:00, 1/5/2010       Running        
MyTasksForStuff2                          07:00:00, 1/6/2010       Running
       

Now, you want to check the tasks on 15 servers, this gets more cumbersome and a little time consuming. So lets say you have this neat little shell script that helps you loop items so that you can one script multiple times

@echo off
 
if x==%1x goto MyServers1
if x==%2x goto MyServers2
 
for /f %%a in (%1) do call %2 %%a
goto end
 
:MyServers1
 
echo.
echo.
echo.
echo Run.bat syntax:
echo ---------------
echo.
echo Example:  run.bat list.txt program.cmd
echo.
echo 'list.txt' should contain a list of computers/IPs 
echo (one to each line) to each execute 'program.cmd'
echo.
echo The names of files are not important as long as they 
echo are specified after the run command.
echo.
echo.
echo.
echo.
 
:end

Save this as run.bat

Next we want to take our 1 line from above and put it into its own bat file with 1 change.

echo “Server Name: %1”
schtasks /query /s %1

Save that as “ViewTasks.bat”

Next we need to setup a text file that contains all the servers we want to view the scheduled task on.

Server1
Server2
Server3

Now put it all together and you will see your results

run.bat list.txt ViewTakss.bat

 

"Server Name:" Server1
TaskName                             Next Run Time            Status        
============================================================
FileScript1                                        23:59:00, 1/5/2010       Running        
MyTasksForStuff2                          07:00:00, 1/6/2010       Running
       

ServerName: Server2
TaskName                             Next Run Time            Status        
============================================================
FileScript1                                        23:59:00, 1/5/2010       Running        
MyTasksForStuff2                          07:00:00, 1/6/2010       Running
       

And you can see your tasks running. Now lets say you want to delete them. Again test with the schtasks command

schtasks /delete  /s ServerName /TN * /f

This will remove the tasks with only a complete as the last line.

So if you save this as “DeleteTasks.bat”

schtasks /delete  /s %1 /TN * /f

You can now run it as a script on all your servers with

run.bat list.txt DeleteTasks.bat

And it will remove all the scheduled tasks from your servers that you have in your list.txt

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , ,

Administration | Weekly Tip

Where is my earth shattering Kaboom

by Stephen McGroarty 8/1/2009 9:17:07 PM

Well, I tried. I don’t have any RAM for my 64bit machine. Now, when i say not any RAM I actually mean very very little. It has 256MB of RAM. I think I need to get some for it before I can keep going with the VMware posts.

I do have VMware ESX 3i up and going, and right now I am installing Windows 2008 server on it. I am doing this as sort of my own personal tests. I want to see what is needed to update an Active Directory domain from 2003 to 2008.

Will update a few things after I get some RAM.

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , ,

Administration

Powered by BlogEngine.NET 1.4.5.0
Theme by Mads Kristensen
Hacked by Stephen McGroarty
Content © Stephen McGroarty


About the author

Stephen Mcgroarty - Avatar Stephen McGroarty

I am a Microsoft Certified Professional with Windows 2003 Server. I have a firm understanding of Linux, Windows, and everything needed for both workstation and servers.

E-mail me Send mail

Calendar

<<  September 2010  >>
SuMoTuWeThFrSa
2930311234
567891011
12131415161718
19202122232425
262728293012
3456789

View posts in large calendar

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2010