Solved

vbscript help

Posted on 2013-05-23
11
397 Views
Last Modified: 2013-06-04
I have created this script that will reside on the server, it will run from a server account.  The point of this script is that it will be a schedule task, it will check the txt file every 15 minutes and if it the file has a computer name it will check against active directory...if it finds it..it will install McAfee, after its done it it reverts back the original computers.txt file to blank until some one puts another computer name on it again....
MY question is,,,is this correct what do i need to fix it and if some one could help me out on log files such as after its done it creates a text file of the out put code..also i was wondering if i don't have permissions to the server to run as a share, is there a way to copy the file to the local machine and execute it from there....any help would be appreciated...

'This will check Active Directory for a computer

Const ADS_SCOPE_SUBTREE = 2
Const ForReading = 1

Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection


objCommand.Properties("Page Size") = 1000

objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE


Set objFSO = CreateObject("Scripting.FileSystemObject")

Set objFile = objFSO.OpenTextFile("C:\Scripts\Computers.txt")


Do Until objFile.AtEndOfStream
    strComputer = objFile.ReadLine
    objCommand.CommandText = "SELECT Name FROM 'LDAP://dc=microsoft,dc=contoso,dc=com' " & _
        "WHERE objectCategory='computer' AND Name = '" & strComputer & "'"
    Set objRecordset = objCommand.Execute
    If objRecordset.RecordCount = 0 Then
        Wscript.Echo strComputer & " does not exist."
    Else
      ReturnValue=Install(strComputer)
        'Wscript.Echo strComputer & " is in Active Directory."
       Wscript.Echo "ReturnValue = " & ReturnValue
    End If
Loop


'this code will load MaCafee
'Install Software on a Remote Computer

Function Install(strComputer)
Const wbemImpersonationLevelDelegate = 4

Set objWbemLocator = CreateObject("WbemScripting.SWbemLocator")
Set objConnection = objwbemLocator.ConnectServer ("NOSTROVOS", "root\cimv2")

objConnection.Security_.ImpersonationLevel = wbemImpersonationLevelDelegate
Set objSoftware = objConnection.Get("Win32_Product")
errReturn = objSoftware.Install("\\NOSTROVOS\smspackages$\MCafee\4_6_FramePkg_Install_for_MS_Windows_20130211.exe",,True)
Install=ErrReturn
End Function




'Last step in the script

'Create a new file after everything is done
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.CreateTextFile("C:\Scripts\Computers.txt")
0
Comment
Question by:erwin_miranda
  • 6
  • 4
11 Comments
 
LVL 42

Expert Comment

by:Rob Jurd, EE MVE
ID: 39193300
Are you running McAfee ePolicy Orchestrator?  This should remove the need for your scripts
0
 

Author Comment

by:erwin_miranda
ID: 39194142
I am but its something else we are trying to do..
0
 

Author Comment

by:erwin_miranda
ID: 39200544
I've requested that this question be deleted for the following reason:

It did not make anysense..and the script is not completed
0
 
LVL 42

Expert Comment

by:Rob Jurd, EE MVE
ID: 39200545
Sorry I wasn't notified with your response. What are you trying to do other than deploying the agent etc?
0
 

Author Comment

by:erwin_miranda
ID: 39200783
Other than automate the process and not have a need for the McAfee policy administrators or myself have to do..nothing...but again if you want the points, they are yours..u responded.
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 42

Expert Comment

by:Rob Jurd, EE MVE
ID: 39203128
See the confusing thing for me is, epo should automatically deploy when a new machine appears in active directory. In other words you should not have to do anything anyway.
I'd like to answer this properly before getting any points ;-)
0
 
LVL 42

Expert Comment

by:Rob Jurd, EE MVE
ID: 39203129
Do you have ad sync on?
0
 

Author Comment

by:erwin_miranda
ID: 39210603
Okay...come to find out and apparently I am not a McAfee Admin...the people that are Mcafee Admin do not administrative priviliges..so I need the script..or help with it..
0
 
LVL 42

Expert Comment

by:Rob Jurd, EE MVE
ID: 39212145
Ok I understand your predicament. Now I'm not trying to be difficult but it seems you are trying to mimic what epo does. My concern it's with ongoing Maintenance. Do the agents automatically register with epo after installing using your script?
Instead of giving admin permissions to the McAfee guys, work with them to set up an automated task and enter your credentials (or a specific admin one set up by you for this purpose) and save the username And hidden password as part of the task. It's that a viable option?
More than happy to help with the script but I wanted us clear on the consequences of doing so.
0
 
LVL 42

Accepted Solution

by:
Rob Jurd, EE MVE earned 200 total points
ID: 39218135
Going down the script route:
You are going to need to make sure you're installing the right version / architecture of McAfee for the machine.  It looks like you're assuming it's Windows and relying on the executable to determine 32/64bit architecture.  
Are you also planning to notify the McAfee guys when you do install a new machine? Are you sure that the new machine will be placed in the right "group" for policy administration?
Adding in a log file is easy, just requires you to have a text file you append to and add in your logs between lines of code.  A simple solution would be to create a simple function at the bottom of your script that takes an input, which is the log text, and outputs to a file.  You can build on that later if need be
You may want to include email notification when your install fails for whatever reason (can't access file share, can't access remote machine etc etc)
I'm sure there's other issues you'll come across going down this path that really ePO does for you... sorry to bang on about it but I don't see the point in reinventing the wheel, unless I"m missing something??
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

If like me you are one who spends a lot of time working and scripting with cmd.exe, sometimes it is handy to be able to quickly view a calendar for a given month and year. This script will quickly do just that!  Save the code posted below to a .bat …
You may have already been in the need to update a whole folder stucture using a script. Robocopy does it well and even provides a list of non-updated files in a log (if asked to). Generally those files that were locked by a user or a process by the …
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now