Jump to content

Help with inventory script


Recommended Posts

I created a script that grabs service tag, pc name, pc model, user name, full name of user, ram, os, and check-in date. The script itself works great. Howver I need this script to execute every 2 hours on every machine. So I created a different script (an installer) that I psexeced out to all machines. In the installer it created a scheduled task which would run the hardware inventory script every 2 hours. Which was perfect, until I saw the report. When I created the scheduled task within the installer script, I used administrator for run as user. So my inventory shows administrator for user name and password, since its running the script as administrator.

I'm open for 2 options, a way to get around the issue of the scheduled task running as admin and reporting back admin is the user, instead of the currently logged in user

or

An installer script which will install my script to the pc, create a tray icon, and run the hardware inventory script every 2 hours. Which would eliminate the need for using scheduled tasks.

Thanks in advance guys, I certainly appreciate it!

Link to comment
Share on other sites

do you really need it to take an inventory every 2 hours? or could you set it up as a login script? you could also setup the scheduled task to run as currently logged on user using @username as the run as name. not sure if it will work correctly without a password but it should if you're just pulling information about the machine

Dating a girl is just like writing software. Everything's going to work just fine in the testing lab (dating), but as soon as you have contract with a customer (marriage), then your program (life) is going to be facing new situations you never expected. You'll be forced to patch the code (admit you're wrong) and then the code (wife) will just end up all bloated and unmaintainable in the end.

Link to comment
Share on other sites

do you really need it to take an inventory every 2 hours? or could you set it up as a login script? you could also setup the scheduled task to run as currently logged on user using @username as the run as name. not sure if it will work correctly without a password but it should if you're just pulling information about the machine

Yes, we need inventory every 2 hours, based on users working all kinds of different times. users travel quite frequently. Offices are in different timezones. Also have the script grab ip address, and based on the subnet report what location the machine is in.

I wanted to do login script, but not feasible, as alot of users, log in monday and lock computer every night, and dont log in for another week.

Tried running the scheduled task as @username, but script asks for a password, which would be a PITA for users.

I'd really like to stick with my 2 options above which are a way around user name reporting back as administrator due to running scheduled task as administrator

or

Creating an actual program, that runs constantly in the system try, with a timer that will run the script every 2 hours.

Link to comment
Share on other sites

If my math is correct this is a 2 hour delay

Sleep(((60*1000)*60)*2)

Dating a girl is just like writing software. Everything's going to work just fine in the testing lab (dating), but as soon as you have contract with a customer (marriage), then your program (life) is going to be facing new situations you never expected. You'll be forced to patch the code (admit you're wrong) and then the code (wife) will just end up all bloated and unmaintainable in the end.

Link to comment
Share on other sites

once you compile it into an exe its a stand alone exe. just push it to the machine with psexec like you did before, then have psexec to start it after it copies to to the remote machine.

Dating a girl is just like writing software. Everything's going to work just fine in the testing lab (dating), but as soon as you have contract with a customer (marriage), then your program (life) is going to be facing new situations you never expected. You'll be forced to patch the code (admit you're wrong) and then the code (wife) will just end up all bloated and unmaintainable in the end.

Link to comment
Share on other sites

Copy it to the root directory, and make it a start-up item.

Dating a girl is just like writing software. Everything's going to work just fine in the testing lab (dating), but as soon as you have contract with a customer (marriage), then your program (life) is going to be facing new situations you never expected. You'll be forced to patch the code (admit you're wrong) and then the code (wife) will just end up all bloated and unmaintainable in the end.

Link to comment
Share on other sites

Copy it to the root directory, and make it a start-up item.

Alright, got it perfect. And I have deployed it with psexec. Is there another program, or something else I can use to deploy the script. Like if a machine hasnt received it yet that will report back that it hasn't been installed yet? So I don't have to run psexec every single day to ensure each computer has received it?

Link to comment
Share on other sites

OK, so my options have been changed to only have it set as a scheduled task. And I have tried deploying it as a scheduled task, and to execute the scheduled task as admin. But the problem is my script then reports the user logged in as admin due to running the task as admin. With a network of 500 pcs, I need to be able to deploy the scheduled task without setting up each scheduled task to run as the current user. Is there any way to do this or a different command to grab the user name instead of using @username?

Link to comment
Share on other sites

like i said earlier you can try and set it up with thier user name as a scheduled task without a password, or you could retrieve thier username using WMI. Create a simple script to deploy to each computer run the script and have it report back machine name and currently logged on user name / full name...

Func GetFullName($sUserName)
    $colItems = ""
    $strComputer = "localhost"
    $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
    $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_UserAccount WHERE Name = '" & $sUserName & "'", "WQL", 0x10 + 0x20)
    If IsObj($colItems) Then
        For $objItem In $colItems
            Return $objItem.FullName
        Next
    Else
        Return SetError(1, 0, "Username not found.")
    EndIf
EndFunc   ;==>GetFullName

This func retrieves full name from a username (comes in handy for tech support ^_^ )

go to --> http://msdn.microsoft.com/en-us/library/aa394507(VS.85).aspx for more information about using WMI to get the classes and such.

along with this make sure to use @computername and have it return name of machine and user.

Dating a girl is just like writing software. Everything's going to work just fine in the testing lab (dating), but as soon as you have contract with a customer (marriage), then your program (life) is going to be facing new situations you never expected. You'll be forced to patch the code (admit you're wrong) and then the code (wife) will just end up all bloated and unmaintainable in the end.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...