Creating a folder with %samname% upon login RRS feed

  • Question

  • Hi,

    I need to make a script that creates a folder with the user's %samname% when the user logs in. This folder is going to be located on a share, and also needs correct permissions with that.

    If the user has already logged in once, it should not create another map but do nothing.

    Can anyone give me a little help on where to start with this? Never done anything with Powershell.


    • Moved by Bill_Stewart Friday, March 15, 2019 3:04 PM This is not "scripts on demand"
    Tuesday, December 11, 2018 12:02 PM

All replies

  • Hi,

    Is the user logging in to a local account or do you have a domain controller somewhere?

    Kind regards,

    Tuesday, December 11, 2018 12:18 PM
  • Hi Micke,

    The user is logging in on a session host on a network with a domain controller.
    Upon every login, the script needs to check if there's already a map created with the SAM name of the user logging in. If there is, nothing should happen, if there is not a map, it needs to be created.


    • Edited by Svennos_ Tuesday, December 11, 2018 12:23 PM
    Tuesday, December 11, 2018 12:22 PM
  • Hi,

    On a domain environment you can set log-on scripts when user logged in.

    In the script you can run, PowerShell which can check for the exiting folder at share path, if it is not created, script will create and assign proper permission nd also map the same on client system.

    Tuesday, December 11, 2018 1:07 PM
  • This is done via Group Policy using folder redirection.   Post in GP forum to find out how to set GP to automatically create and manage nuser private folders.


    • Edited by jrv Tuesday, December 11, 2018 6:22 PM
    Tuesday, December 11, 2018 6:22 PM
  • Hi,

    I have today found a way you can accomplish what you seek. However, it was done strictly by using my own limited knowledge about Windows and my solution should not be considered to be factual or optimal.

    I used "Drive Maps" for this and this is how I did it.

    1. Open server manager and navigate to "Tools > Group Policy Management".
    2. Enter your Forest > Domains > domain.
    3. Rightclick on the OU this is regarding, I created a new one for this experiment and added the computer and user I would be using to the OU. Proceed to "Create a GPO in this domain and link it here". Call it whatever.
    4. Edit the new GPO and go into its User Configuration > Preferences > Windows Settings > Drive Maps. Rightclick on "Drive Maps" and "New > Mapped Drive".
    5. Please set up your configuration like I did, please see attached image:
    (Unverified account, can't embed images, here it is: https://social.technet.microsoft.com/Forums/getfile/1370209)

    6. Go to the "Common"-tab and click the "Targeting..."-button next to "Item-level targeting" (also enable the checkbox).
    7. Add a new item called "File match" and select it. Click "Item Options" and select "Is Not". Please see the attached image to see how it should look like.
    (Unverified account, can't embed images, here it is: https://social.technet.microsoft.com/Forums/getfile/1370207)

    8. Exit the Drive Maps-tool and run a group policy update.

    Following these steps will create a drive called %username% (e.g. johndoe, administrator). The domain administrator can see the files that has been saved in the drive by going to the shared folders path and then to the relevant folder (which will also be called %username%).

    I hope this helps you and does what you want it to do. Also remember that I am not (yet) a professional in this area and my solution might not be the best or even correct. Have a good day regardless!

    Kind regards,

    Wednesday, December 12, 2018 10:06 AM