Mapping drives and printing: logon scripts and GPOs

When each person signs in, the PC must connect to the right folders (K: for administration, L: for production, S: for the common folder) and, for production, find the department's printer. Atlas…

Situation

When each person signs in, the PC must connect to the right folders (K: for administration, L: for production, S: for the common folder) and, for production, find the department’s printer. Atlas offers two ways to make the PC do these things:

Logon scripts Group policies (GPO)
Where Active Directory → Logon scripts Active Directory → Group policies and the «Drive letter» of each share
Who it applies to each user, chosen one by one in their card a container (domain root or organizational unit), filtered by group
What it can do any Windows command (net use, PowerShell…) only the catalog entries; for drives, the entry «Shares by group»
When at the next Windows sign-in within 90 minutes, at restart or with gpupdate /force; user settings at the next sign-in
Windows domain (coexistence) the entry is not there the entry is not there: scripts and policies belong to the Windows domain controller

The scenario shows both ways with the same results, because in a real company it happens that you start from the script and then move to policies. The rule is one way per drive letter: if S: is mapped both by the GPO and by a script, net use answers that the local device name is already in use, and Windows keeps one of the two mappings.

Tip For network drives the preferred way today is the GPO «Shares by group» (scenario Shared folders by department): it is per group, does not require editing every user’s account, and a mapping to a folder the user cannot open is not created. The logon script remains useful for what policies do not do: a command, a program, a printer.

What you need

  • An administrator (for example lwhite), the Atlas domain (not in coexistence with a Windows DC) and the shares administration, production, common already created.
  • A test PC in the domain and a test user, for example pblack (production).
  • For the printer block: the production printer, printer-prod, MAC 00:00:5e:00:53:70, already with the reserved address 10.20.1.50 (Network: DHCP reserves the address; the reservation can also be made from Tools → DHCP Leases, Administrator tools), and the driver installed on the PCs. Atlas is not a print server (there is no shared print queue on the appliance).
  • A text editor with which to write the scripts using only simple characters (see the limits below).

Steps

A. The scripts way: logon.bat

  1. Open Active Directory → Logon scripts. A new domain already contains an example one. Press «Add script» (+).

  2. In «Filename» write logon.bat. Only the name, without path or spaces: letters, digits, ., -, _, up to 128 characters, with an alphanumeric first character. After creation it cannot be changed.

  3. In «Content» write:

    @echo off
    rem Common folder for everyone
    net use S: \\atlas\common /persistent:no

    /persistent:no prevents Windows from remembering the drive after disconnection: every sign-in redoes it from scratch.

  4. Press «Create script» at the bottom right. The script appears in the list with its size. Opening «Details» you see «Size», «Created» and «Updated».

  5. The script does not apply by itself. Open Active Directory → Users and choose pblack.

  6. In the «Features» block, in the field «Logon script», choose logon.bat. (The list contains the scripts of the Logon scripts entry; «(none)» for none.)

  7. Press «Save». Repeat for every user who must run the script: the script is per user, not per group or per computer, so for twenty people you choose it twenty times.

  8. Have pblack sign out and in again in Windows.

Warning A .bat or .cmd file is saved as Windows reads it: CRLF line endings and OEM 850 encoding. Accented letters are fine, the € symbol is not. If the content has characters that encoding cannot represent, saving is refused and the console lists them («A .bat or .cmd file cannot contain: ….»). Other file types are saved in UTF-8.

  1. To edit it, open logon.bat, change the text in «Content» and press «Save». For example to change S: to T: just rewrite the line. Each user applies it at their next sign-in.
  2. To remove a script that is no longer needed (old.bat), open it and press «Delete». If no user uses it the confirmation is «Delete this script? No user has it.»; if some do, the window lists them («Delete this script? 3 users have it (jgreen, jbrown, pblack): it is taken off their accounts and no longer runs at their next sign-in.»). Confirm with «Delete». The message is «Script deleted and taken off 3 users.» If Atlas cannot remove it from the users, the script is not deleted: try again.

B. The printer in the script

  1. Reopen logon.bat and add the production printer at the bottom. Atlas offers neither a print queue nor a catalog entry for printers: the command is Windows’s and must be tried on a PC before assigning it to everybody. This is an example that uses PowerShell (the driver name must be the one installed on the PC; to read it: Get-PrinterDriver):

    @echo off
    net use S: \\atlas\common /persistent:no
    powershell -NoProfile -ExecutionPolicy Bypass -Command "if (-not (Get-Printer -Name 'Production printer' -ErrorAction SilentlyContinue)) { Add-PrinterPort -Name 'IP_10.20.1.50' -PrinterHostAddress '10.20.1.50'; Add-Printer -Name 'Production printer' -DriverName '<installed driver>' -PortName 'IP_10.20.1.50' }"
  2. Press «Save». Have pblack sign out and in again on a test PC and open Windows’s Printers & scanners.

Warning Adding a TCP/IP port and a local printer usually requires privileges that a normal user does not have: the script runs with the user’s rights. On many PCs the command works only if the driver is already there and Windows policy allows it. If it does not work for pblack, add the printer just once on the PC with an administrator, or assign the printer with Group Policy Preferences from your PC with GPMC (Group Policy Management): Atlas manages only the GPOs it creates, whose name starts with «Edon - …»; the others do not appear in the list and are managed with GPMC from a Windows PC (RSAT).

  1. In the command the reserved address (10.20.1.50) is better than the name: with the address the script does not depend on DNS. The name printer-prod works only if the reservation in IPAM created the record in the internal DNS (Network).

C. The policies way: drives by group

  1. Open Active Directory → Shares and, for each share, set the «Drive letter»: K: for administration, L: for production, S: for common (scenario Shared folders by department). It is the same GPO, «Edon - Condivisioni», which Atlas creates and updates by itself.
  2. Before enabling the drives from the GPO remove those of the script, so as not to have the same letter twice: edit logon.bat and delete the line net use S: ….
  3. Open Active Directory → Group policies and choose the GPO «Edon - Condivisioni». Its form has the «Drives» block: the rows written by Atlas show the letter, the path, the group and «from Shares» and cannot be edited from here. If a drive is not an Atlas folder (a NAS, another server), add it with «Add drive»: «Letter», «Path (\server\share)», «Group» (or «Everyone») and «Label».
  4. In «Where it applies» choose the «Container»: by default it is Edon-Pilot, a test unit that Atlas creates if missing and that PCs apply only if they are inside it. Move the test PC into Edon-Pilot with ADUC (Atlas’s Computers page does not move computers). When the test works, come back here and choose the domain root or the unit of the real PCs.
  5. Leave «Link enabled» on. The «Filter» is «Everyone»: the drive is seen anyway only by whoever belongs to the share’s group.
  6. If the container contains the PCs and not the users, leave «Apply to the users of the linked PCs» on (loopback).
  7. Press «Apply». The message is «Policy applied.» or «No change: the GPO is already like this, PCs do not re-apply it.» Atlas makes a backup of the GPO before every change.
  8. On the test PC run gpupdate /force, then sign pblack out and in again.

D. Other useful policies on this occasion

  1. With Group policies → «Add a policy from the catalog» you can add other entries for the PCs, always testing first on Edon-Pilot. The catalog holds, among others: «Single sign-on (SSO) from the intranet», «Screen lock», «Windows Update», «Network protection», «Wait for the network» and «Fast startup off» (which Atlas has already created for the whole domain), «Microsoft Edge», «USB storage», «Shares by group», «Sign-in security», «Outlook: calendars and contacts» and «Outlook: add-in settings». For example «Screen lock» with «Minutes of inactivity» 10. None concerns printers.
  2. For a computer policy filtered by group, the group must contain the PCs (not the users) and a PC sees a new group after a restart. Atlas’s Groups page offers only users as members: for a computer group use ADUC.

Check

  • Scripts: in the Logon scripts list logon.bat has today’s size and date. In Users, pblack shows logon.bat in «Logon script».
  • On pblack’s PC, after a new sign-in: File Explorer shows S: (with the script) or, with the GPO, L: and S: and not K:. With jgreen, K: and S: appear.
  • Printer: «Production printer» appears in Printers & scanners; a test print comes out.
  • GPO: in Group policies the GPO «Edon - Condivisioni» has the label «Edon» and not «Not linked». In the «Links» detail it shows the container as «Active», and the two rows «Version in Active Directory» and «Version in SYSVOL (GPT.INI)» match.

If something goes wrong

Symptom Cause and remedy
«Invalid filename. Use letters, digits, ‘.’, ‘-’, ‘_’ (no slashes).» You wrote a path or a space.
«A script with this filename already exists.» Choose another name.
«A .bat or .cmd file cannot contain: ….» Remove the listed characters (for example €).
The script does not start The PC is not in the domain, the user does not have the script in «Logon script», or the sign-in is the same as before: the script does not rerun on an already open session.
S: appears but net use complains The same letter also comes from the GPO: keep only one.
«Letter already used by another drive of the “Edon - Condivisioni” GPO.» Change one of the two letters.
The GPO has the label «Not linked» or «Links disabled» Choose a container and turn on «Link enabled», then «Apply».
«Folder missing» The GPO’s folder is not in SYSVOL: the PCs cannot apply it. Restore from backup or recreate the GPO.
«Versions differ» The version in AD and in SYSVOL do not match: saving it again from GPMC usually realigns it.
«The Edon-Pilot organizational unit could not be created.» The domain controller did not answer: try again.
The drives do not appear on the PC The PC is not in the unit to which the GPO is linked, gpupdate /force or a new sign-in is missing (user settings), or the user is not in the share’s group.
The printer is not added Probably missing privileges or driver (see above). Atlas cannot do it for you.
The entries «Logon scripts» and «Group policies» are not there The domain is in coexistence with a Windows domain controller: manage them from GPMC on the Windows DC. The page opened from the address says so.

Limits to remember

  • The script is per user; the name cannot be changed (to rename, create a new file, assign it and remove the old one).
  • Atlas manages only the GPOs it created (name «Edon - …»).
  • The ten catalog entries have been tested on Windows 11; Windows 10 has not been verified yet.
  • PCs apply changes within 90 minutes, at restart or with gpupdate /force; a user must sign in again for user settings.
  • A policy linked to the domain root concerns all PCs: test first on Edon-Pilot.
  • «Delete the GPO» unlinks and deletes the GPO; Atlas saves a copy but there is no button to bring it back to life. «Restore the previous parameters» reapplies the parameters in force before the last change (the last five).
  • The “Printer in the script” block is not tested by Atlas: it is an example to try.

For the technician The script files live in sysvol/<realm>/scripts and Windows reads them from \\<domain>\NETLOGON. The «Logon script» field writes the user’s scriptPath attribute. Each Atlas GPO has an edon.json file in its SYSVOL folder; backups are in /srv/data/pods/addc/lib/edon-gpo-backup/<guid>/<date>. After each write Atlas runs samba-tool ntacl sysvolreset; a daily check repairs SYSVOL’s permissions (System → Settings → File sharing, «Reset the SYSVOL permissions» forces it). Notes in info/done/GPO.md.

LET’S TALK INFRASTRUCTURE

Control starts with a conversation.

Tell us about your infrastructure. Let’s start with what you actually need.

Talk to an engineer