need a script for active directory

I need two scripts

1. to get a lsit of all the computers that have not contacted any of our domain controllers for more than 90. it should create a csv or a txt file with the list of computers. all our client computers are in one ou called "computers OU" so in the list i want to make sure servers are not included thats why i want to get the list form this OU only

2. i need a script to move all the computers iin the list generated  by the first script to move the computers to a specific ou called "stale computers" as we can take a backup of AD before we delete the computers .

the process we will follow is generate the list using script 1. second we will pingall the computers to make sure they are not active. then we will mve the computers to the ou using the second script. and after taking a backup we will delete the computers. need help
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Chris DentPowerShell DeveloperCommented:

1 and 2:

It won't ping things, but there's little point in writing something from scratch to achieve all but that.

mgmohiuddinAuthor Commented:
thanks chris
please need som more help.

1. need to scan only one OU from where i can get a list of computers. our OU is "computers ou".  i dont want to scan the complete domain

2. i want to mone computers identified as old from the computers OU to another ou called "stale compuetr ou".

i am very bad with scripts and hoping i get some help

i do have the script to ping the computers in a list
Joe KlimisCommented:
If you would like to do this without instaling aditional 3rd party sofware , the following great post , will work with powershell v1 and above 

Discover the Answer to Productive IT

Discover app within WatchGuard's Wi-Fi Cloud helps you optimize W-Fi user experience with the most complete set of visibility, troubleshooting, and network health features. Quickly pinpointing network problems will lead to more happy users and most importantly, productive IT.

Chris DentPowerShell DeveloperCommented:

The Computers OU you refer to, is that the default folder for computers? Or one you've created?

If you're sticking with OldCmp, and I advise you do if you don't like / have no experience with scripting...

Reporting on stale computers from a specific OU (note this is the default Computers folder for an AD domain called

OldCmp -report -b "CN=Computers,DC=yourdomain,DC=com"

This generates an HTML report of all computers from the specified OU which have been inactive for 90 days or more.

Then if you're happy with the report you can tell it to move them. Note that you should create "Stale Computers" first.

OldCmd -move -newparent "OU=Stale Computers,DC=yourdomain,DC=com" -b "CN=Computers,DC=yourdomain,DC=com"

And if you're happy with what it does there, add "-forreal" onto the end.

OldCmd -move -newparent "OU=Stale Computers,DC=yourdomain,DC=com" -b "CN=Computers,DC=yourdomain,DC=com" -forreal

If you have trouble figuring out the values for -b and -newparent yell and I'll explain how to find those.

mgmohiuddinAuthor Commented:
Firstly the computers OU that i was mentioning is the one i created, not the default one.

the first command

OldCmp -report -b "CN=Computers,DC=yourdomain,DC=com"
will rightly create a list of computers of computers in the form of a htlm format. i will create the list in the csv format as there is an option to do that. so far fine

secondly i will use a script that i have to ping the computers in the list that i generated in step one.

now last thing is computers that are replying i will remove it from the list or some other entries in the list and i will finalize a list

i only want to move the computers in the list to the stale computers ou Chris.

is there a way.

Chris DentPowerShell DeveloperCommented:

Whether we use this or something else we'd need a way to identify the systems you want to keep. If there aren't too many can you move them (the ones you want to keep) into a different OU while you clean up?

mgmohiuddinAuthor Commented:

I am using this command

OldCmp -report -format csv -b "OU=Computers ou,DC=domain,DC=subdomain,DC=com"

it is generating a file as datetime.cvs.txt

i need the file in the csv format and it is still creating a txt file chris. any modifications i need to do for this
Chris DentPowerShell DeveloperCommented:

That should be it, drop off the .txt extension and you should be able to open it up in Excel.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Batch

From novice to tech pro — start learning today.