+ Post New Thread
Page 1 of 2 12 LastLast
Results 1 to 15 of 19
Scripts Thread, Script to install program based on AD group in Coding and Web Development; Hi, I would like a script that will install an application based on the AD group. I have the app ...
  1. #1

    FN-GM's Avatar
    Join Date
    Jun 2007
    Location
    UK
    Posts
    15,392
    Thank Post
    797
    Thanked 1,588 Times in 1,391 Posts
    Blog Entries
    10
    Rep Power
    427

    Script to install program based on AD group

    Hi,

    I would like a script that will install an application based on the AD group. I have the app and the switches.

    I would like it so it checks if the computer is in a group and if it is then check if a file exists on the local machine if it doesn't then run the installer. If not run to the next command for the next bit of software and so on..

    I would like it in .bat but i suspect it might need to be .vbs

    Does anyone have anything please?

    Thanks
    Last edited by FN-GM; 31st October 2011 at 10:15 AM.

  2. #2

    plexer's Avatar
    Join Date
    Dec 2005
    Location
    Norfolk
    Posts
    12,977
    Thank Post
    587
    Thanked 1,496 Times in 1,342 Posts
    Rep Power
    398
    If you use a GPO to apply it as a startup script to a spceific OU then only machines in that OU will run it.

    You can then do it in a batch file and use the if not exist or if exist statements in your batch file to control what is run.

    Ben

  3. #3

    FN-GM's Avatar
    Join Date
    Jun 2007
    Location
    UK
    Posts
    15,392
    Thank Post
    797
    Thanked 1,588 Times in 1,391 Posts
    Blog Entries
    10
    Rep Power
    427
    If you use a GPO to apply it as a startup script to a spceific OU then only machines in that OU will run it.
    I know that but i dont wish to go down that route. We will have lots of different apps on different machines and doing that will make things messy.

    thanks anyway

  4. #4

    plexer's Avatar
    Join Date
    Dec 2005
    Location
    Norfolk
    Posts
    12,977
    Thank Post
    587
    Thanked 1,496 Times in 1,342 Posts
    Rep Power
    398
    Ok then use groups to control who the gpo is applied to instead then saves needing to read ad groups from within your script and makes that simpler as well.

    Ben

  5. #5

    FN-GM's Avatar
    Join Date
    Jun 2007
    Location
    UK
    Posts
    15,392
    Thank Post
    797
    Thanked 1,588 Times in 1,391 Posts
    Blog Entries
    10
    Rep Power
    427
    Quote Originally Posted by plexer View Post
    Ok then use groups to control who the gpo is applied to instead then saves needing to read ad groups from within your script and makes that simpler as well.

    Ben
    I dont want to do that either. I know how to do this but as i originally asked for i would like a script to do this.

  6. #6

    dhicks's Avatar
    Join Date
    Aug 2005
    Location
    Knightsbridge
    Posts
    5,498
    Thank Post
    1,185
    Thanked 745 Times in 647 Posts
    Rep Power
    228
    Quote Originally Posted by FN-GM View Post
    I would like it so it checks if the computer is in a group and if it is then check if a file exists on the local machine if it doesn't then run the installer.
    We have a .vbs login script to assign printers by OU of the user or machine, if that's any use to get you started:

    Code:
    Option Explicit
    on error resume next
    
    Dim objNetwork, objSysInfo, strUserDN
    Dim objGroupList, objUser, objFSO
    Dim strComputerDN, objComputer, user
    
    Set objNetwork = CreateObject("Wscript.Network")
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objSysInfo = CreateObject("ADSystemInfo")
    strUserDN = objSysInfo.userName
    strComputerDN = objSysInfo.computerName
    
    ' Bind to the user and computer objects with the LDAP provider.
    Set objUser = GetObject("LDAP://" & strUserDN)
    Set objComputer = GetObject("LDAP://" & strComputerDN)
    
    ' Not quite sure why this is in a loop - maybe you just have to wait for Windows to get back to you?
    Do While User = ""
     User = lcase(objNetwork.UserName)
    Loop
    
    if InStr(strComputerDN, "OU=Staff Room") then
        Run command goes here.
    end if

  7. #7

    FN-GM's Avatar
    Join Date
    Jun 2007
    Location
    UK
    Posts
    15,392
    Thank Post
    797
    Thanked 1,588 Times in 1,391 Posts
    Blog Entries
    10
    Rep Power
    427
    Quote Originally Posted by dhicks View Post
    We have a .vbs login script to assign printers by OU of the user or machine, if that's any use to get you started:

    Code:
    Option Explicit
    on error resume next
    
    Dim objNetwork, objSysInfo, strUserDN
    Dim objGroupList, objUser, objFSO
    Dim strComputerDN, objComputer, user
    
    Set objNetwork = CreateObject("Wscript.Network")
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objSysInfo = CreateObject("ADSystemInfo")
    strUserDN = objSysInfo.userName
    strComputerDN = objSysInfo.computerName
    
    ' Bind to the user and computer objects with the LDAP provider.
    Set objUser = GetObject("LDAP://" & strUserDN)
    Set objComputer = GetObject("LDAP://" & strComputerDN)
    
    ' Not quite sure why this is in a loop - maybe you just have to wait for Windows to get back to you?
    Do While User = ""
     User = lcase(objNetwork.UserName)
    Loop
    
    if InStr(strComputerDN, "OU=Staff Room") then
        Run command goes here.
    end if
    Thanks, but i am not good enough to pull that apart.

    Does anyone have anything please?

    Thanks

  8. #8

    dhicks's Avatar
    Join Date
    Aug 2005
    Location
    Knightsbridge
    Posts
    5,498
    Thank Post
    1,185
    Thanked 745 Times in 647 Posts
    Rep Power
    228
    Quote Originally Posted by FN-GM View Post
    Thanks, but i am not good enough to pull that apart.
    You can just cut-and-paste most of that code - it simply sets up a couple of objects to then use to query active directory. You just need to edit the last 3 lines:

    if InStr(strComputerDN, "OU=Staff Room") then
    Run command goes here.
    end if

    In this case, replace "Staff Room" with the name of the organisational unit (OU) your computers are in, then add any commands you want to run in the "Run command goes here" - you can simply run an external command:

    Set objShell = WScript.CreateObject("WScript.Shell")
    objShell.Run "\\server\path\myfile.bat", 1, True

    A quick Google for "vbs if file exists" seems to bring up a bunch of code to check if a file exists or not.

  9. #9

    FN-GM's Avatar
    Join Date
    Jun 2007
    Location
    UK
    Posts
    15,392
    Thank Post
    797
    Thanked 1,588 Times in 1,391 Posts
    Blog Entries
    10
    Rep Power
    427
    How would i change from OU to AD group please? Reason being my computers will all be mixed in one OU.

    Thanks

  10. #10

    FN-GM's Avatar
    Join Date
    Jun 2007
    Location
    UK
    Posts
    15,392
    Thank Post
    797
    Thanked 1,588 Times in 1,391 Posts
    Blog Entries
    10
    Rep Power
    427
    Bump please

  11. #11
    ricki's Avatar
    Join Date
    Jul 2005
    Location
    uk
    Posts
    1,466
    Thank Post
    20
    Thanked 164 Times in 157 Posts
    Rep Power
    51
    HI

    What you could do is create a group and put all the computers that you want to install install the program into the group.

    Now create the script to install the program and set the ntfs permissions so that one the group can read it and link the script up to the domain as a group policy low down. I think this is a very strange way of wanting to do this but it would work,

    The other way you could do this is with environmental variables. On each machine set an environmental variables. We used to do this with printers say a room number. Then get the script to look for this. I am sorry I dont have the scripts we used here as I am at home.

    Richard

  12. #12

    FN-GM's Avatar
    Join Date
    Jun 2007
    Location
    UK
    Posts
    15,392
    Thank Post
    797
    Thanked 1,588 Times in 1,391 Posts
    Blog Entries
    10
    Rep Power
    427
    Quote Originally Posted by ricki View Post
    HI

    What you could do is create a group and put all the computers that you want to install install the program into the group.

    Now create the script to install the program and set the ntfs permissions so that one the group can read it and link the script up to the domain as a group policy low down. I think this is a very strange way of wanting to do this but it would work,

    The other way you could do this is with environmental variables. On each machine set an environmental variables. We used to do this with printers say a room number. Then get the script to look for this. I am sorry I dont have the scripts we used here as I am at home.

    Richard
    I did think of that but it's abit of a messy way to be honest.

  13. #13

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,218
    Thank Post
    2,769
    Thanked 935 Times in 875 Posts
    Rep Power
    343

  14. #14

    glennda's Avatar
    Join Date
    Jun 2009
    Location
    Sussex
    Posts
    7,714
    Thank Post
    269
    Thanked 1,116 Times in 1,012 Posts
    Rep Power
    345
    Can you not setup in gpo so that it only applies if machines are in a group like you can with users?

  15. #15

    FN-GM's Avatar
    Join Date
    Jun 2007
    Location
    UK
    Posts
    15,392
    Thank Post
    797
    Thanked 1,588 Times in 1,391 Posts
    Blog Entries
    10
    Rep Power
    427
    Quote Originally Posted by glennda View Post
    Can you not setup in gpo so that it only applies if machines are in a group like you can with users?
    As said before i am well aware of that but i do not wish to do that

    @mac_shinobi seen them but they are for checking users, not computers.

SHARE:
+ Post New Thread
Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 24
    Last Post: 16th July 2013, 10:33 AM
  2. Replies: 9
    Last Post: 6th October 2010, 03:54 PM
  3. Script to call another based on machine name
    By originofsymmetry in forum Scripts
    Replies: 5
    Last Post: 2nd May 2008, 12:04 PM
  4. Replies: 4
    Last Post: 23rd November 2006, 09:33 PM
  5. Script to change user email in AD (or Exchange)
    By SpuffMonkey in forum Scripts
    Replies: 16
    Last Post: 8th November 2005, 10:31 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •