Click to See Complete Forum and Search --> : trying to inventory our computers


sbevill7
August 28th, 2008, 08:31 AM
Hello,
I have been reading through the forums for a while and received some great advice. But I'm working on this one project and can't seem to get it right. I'm very new to scripting (only been doing it a few weeks) and can't figure out why this script is acting like it does. The script is

@echo off
If exist c:\inventoried goto A

md c:\inventoried
systeminfo /nh /fo csv >> N:\is\scripts\inventory\inventory.csv
cscript n:\is\scripts\inventory\servicetag.vbs >> n:\is\scripts\inventory\servicetags\%computername%.txt
goto A

:A exit

When it runs the first time one a computer it will bypass the if statement and create the folder "c:\inventoried", but then it will exit. If you go in and delete the folder it will go through and do the script correctly. I have tried this on 6 different machines and gotten the same reaction each time. The problem with having to go in and manually delete a folder for it to work is we need to run this on a little over 300 computers and don't want to have to physically touch all of them. Do you guys have any suggestions on why the code may be acting the way it is? Thanks in advance for your help.

Edited: to put in code boxes.

javajawa
August 28th, 2008, 08:40 AM
Welcome to (posting on) the Forums! :wave:

You have the problem...because that's what you've programmed it to do! If the folder exists, it's told to goto A, so it'll jump to the bottom of the script...

What condition do you want to use? if it's an Inventory Once program, then your code surely is correct, and it acting correctly?

sbevill7
August 28th, 2008, 08:51 AM
Thank you for the welcome :D.

What I was intending to do is only have this script run once per computer (an inventory with 200 copies of the same computer isn't very useful). My line of thought was to have the script first check to see if this folder exists (which at this point it should not):

@echo off
If exist c:\inventoried goto A

Since it does not exist the if statement is not triggered so it moves on to the next part:

md c:\inventoried
systeminfo /nh /fo csv >> N:\is\scripts\inventory\inventory.csv
cscript n:\is\scripts\inventory\servicetag.vbs >> n:\is\scripts\inventory\servicetags\%computername%.txt
goto A

It will then create the folder (so that next time the user logs on it will see the folder and skip the inventory process), inventory the machine, and exit the script.

Like I said, that is just how it worked in my head which doesn't always translate well to notepad. Sorry for not making the intentions of the script clearer. I see your thought process on that and it makes perfect sense, but I don't know if it would do what we are really looking for.

javajawa
August 28th, 2008, 09:05 AM
Hmmm...
I can't see anything wrong with the theory or the coding of the script - in fact, I think I haven't quite cottoned onto what the error you're getting is!
When it runs the first time on a computer it will bypass the if statement and create the folder "c:\inventoried" That all makes sense...
, but then it will exit. I assume you mean the next time you run it. However, is the second run on the same machine, or did you try running it once on on machine, then once on another, without touching the folders?
If you go in and delete the folder it will go through and do the script correctly. I have tried this on 6 different machines and gotten the same reaction each time. Well, at least it's consistent...and it makes perfect sense, unless I'm missing something here...

sbevill7
August 28th, 2008, 09:24 AM
What i'm wanting it to do is on the first time it is run for it to skip the if statement, create the folder, inventory the machine, and exit. Then every time a user logs on after that it will catch on the if statement and exit (without creating the folder or running the inventory).

What is actually happening. The first time you run the script it skips the if statement (because the folder hasn't been created), and makes the folder, but after that it just exits. I'm wanting it to run the inventory commands. If you go back in and run it again it hits the if statement and exits. So without manually messing with the folder the systeminfo and vbs calls are never ran.

javajawa
August 28th, 2008, 10:04 AM
Have you tried removing @echo off, and seeing if an error is occurring?
Of sticking in something other than the script calls you've got, to see if anything runs?

sbevill7
August 28th, 2008, 10:06 AM
That is a brilliant idea that I have not tried yet. Let me try a few things and see if I get anywhere. Thanks for your help, javajawa! I'll post back when I know more.

sbevill7
August 28th, 2008, 01:39 PM
I have to admit, I don't think I would have ever guessed the cause of the issue. After a painstaking amount of trial and error and error and error I finally discovered that it was the creation and updating of the user profile at logon that was messing up the script. Once I found this out I put in a piece of code at the beginning like this:
ping 127.0.0.1 -n 16
This code gave the profile enough time to load before starting to look for the folder. This was really only a problem if the user had never logged onto the machine before (which was the case with my test user), but adding that ping command gave everything enough time to balance out. Thank you so much, javajawa for helping me out. Now we will be able to inventory hundreds of our machines in just a few short days with virtually no added work.