Jump to content
squirrelc0de

AD OUS and persistant drives

Recommended Posts

squirrelc0de

Hi there, 

I have a question about persistent drives and AD. 
I am playing around with a script but I'm missing something. What i want to do is if a user is part of an OU, it will map a network drive and be persistent. However if a user is moved out of that OU, they will need to have the persistent drive removed. 

I'm using the ad plugin script, and i can map the drives if a user is in a specific ou, but i cannot seem to delete the drive if the user is out of the OU. 

Here's an example of code I'm using: 

 

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Compression=4
#AutoIt3Wrapper_Res_Fileversion=1.0.0
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <AD\AD.au3>

func MapDrives()
    _AD_Open()
    
    if _AD_RecursiveIsMemberOf(OU) Then
        Mapdrive1()
    Elseif _AD_RecursiveIsMemberOf(different ou)
    drivemapdel    
    EndIf
    
    _AD_Close()
EndFunc
    
Func MapDrive1()
    Drivemapdel ("Z:")
    DriveMapAdd ("Z:"."\\server\share",$DMA_PERSISTENT,0)
    
EndFunc

 

Share this post


Link to post
Share on other sites
Subz

Can you add some debugging for example:

func MapDrives()
    _AD_Open()
    
    if _AD_RecursiveIsMemberOf($OU) Then
        Mapdrive1()
        MsgBox(64, $OU, @UserName & " is member of " & $OU & @CRLF & DriveMapGet("Z:"))
    Elseif _AD_RecursiveIsMemberOf($differentou)
        DriveMapDel("Z:")
        MsgBox(64,$differentou, @UserName & " is member of " & $differentou & @CRLF & DriveMapGet("Z:"))
    EndIf
    
    _AD_Close()
EndFunc

 

Share this post


Link to post
Share on other sites
squirrelc0de

Hi there, 

I dont want a message box to pop up when a user signs in, but to have the script detect whether they are apart of a specific ou, and if they were moved into a different ou then the script would remove the previous persistent drive. I think I got the code right, but need to double check it with someone.

Thanks 

Share this post


Link to post
Share on other sites
Subz

The idea was for you to test to see what was occurring not for production, alternatively you could just write to a log and then check the information from there.

Share this post


Link to post
Share on other sites
squirrelc0de

thank you, i will give that a shot and get back to you in a day or so. 

Share this post


Link to post
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

  • Similar Content

    • Trinnon
      By Trinnon
      I have a question about the @error logging features in _AD_CreateUser.  Hopefully I am just missing something obvious.
      In my app I am creating a user if it does not exist then manipulating some attributes. 
      If the user does exist I would then call another function to remove groups from the user and modify some attributes.
      My question is...
      If the user already Exists, the _AD_CreateUser option gives $iValue = 0 and @error = 0.
      How can @error = 1 for the condition that the user already exists?
       
      I copied a small ship of the code in question along with my full .au3. 
      I am using AD UDF 1.4.9.0 (Water, thanks for the awesome work on this!!!).
      $iValue = _AD_CreateUser ($sOU, $sUser, $sCN)
      If $iValue = 1 Then
            _FileWriteLog ($Log, "Func UserCheck() - User '" & $sUser & "' successfully created ==> Calling UserAttribsNewUser Function.")
            Call ("NewUser")
      ElseIf @error = 1 Then
            _FileWriteLog ($Log, $sUser & " already exists ==> Calling UserAttribsExistingUser Function.")
            Call ("ExistingUser")
       
      AccountSettingConfigurations-Test1.au3
       
    • water
      By water
      Extensive library to control and manipulate Microsoft Active Directory.

      Threads: Development - General Help & Support - Example Scripts - Wiki
      Previous downloads: 30467
       
      Known Bugs: (last changed: 2018-06-01)
      None  
      Things to come: (last changed: 2018-06-01)
      None
      BTW: If you like this UDF please click the "I like this" button. This tells me where to next put my development effort
    • water
      By water
      ADAT is a tool to simplify common AD administration tasks. Every administration task has its own tab. It is easy to add new functions (tabs) to the tool. Some often used functions are already available: list users, computers, OUs. File ADAT.ini can be customized to hold the AD logon information if necessary.
      Known Bugs:
      2018-03-07: If the Script started from SciTE works but the "Process" button in the compiled exe does not do anything then please add the following line at the top of your script:
      #Au3Stripper_Ignore_Funcs=Process_Tab*
        BTW: If you like this tool please click the "I like this" button. This tells me where to next put my development effort
    • bouzzi
      By bouzzi
      Hi guys,
      I'm trying to make a script that could tell me, from a username list file,  if the username is active, inactive or not existant  in a multi-domain Active Directory....
      I found a few scripts giving me hints but I found nothing to help me to accomplish this task...
      Do you have any ideas !
      Thanks
      Bouzzi!
       
    • water
      By water
      On one/multiple big sheet(s) you get users (columns) and groups (rows). The list is sorted descending by number of members so you get the users with most groups and the groups with most members on top of the page. You can filter by (multiple) samaccountname(s), department or you can create your own LDAP query filter. You can filter the resulting list of groups using a Regular Expression.
      Version 2.0 uses maps so at the moment it requires the latest beta version of AutoIt!
      BTW: If you like this tool please click the "I like this" button. This tells me where to next put my development effort
×