Back to Lab Listing

Lab Objective:

Active Directory – Learn how to create a Logon Script at the Domain we just created.

Lab Purpose:

You will learn how to create a Logon Script for the user of the Domain “lab.local”.

Lab Tool:

Windows Server 2012 R2 + Windows 10

Lab Topology:

Use two machines, either on your home network or on the same virtual network in VMware.

logon script active directory

Note:

You can use logon scripts to assign tasks that will be performed when a user logs on to a particular computer. These scripts can carry out operating system commands, set system environment variables, and call other scripts or executable programs. Some tasks commonly performed by logon scripts include:

Mapping network drives

Installing and setting a user’s default printer

Collecting computer system information

Updating virus signatures

Updating software

Basically, there are two ways to assign Logon scripts.

The first is done on the Profile tab of the user properties dialog in the Active Directory Users and Computers (ADUC).

logon script active directory2

The second is done via Group Policy Objects (GPO).

Note:

Using the first method via the Profile tab of the user properties will work for any Microsoft-based operating system, and is especially useful when you have older clients such as Windows 95/98 or Windows NT.

These types of operating systems do not use Group Policies. Therefore, it’s recommended you only use  one method.

Lab Walkthrough:

Task 1:

We will add a new virtual disk at the machine. The below example is for VMware, but you can easily do the same in VirtualBox and there are several ‘how to’ videos available on the web.

Shutdown the DC (Domain Controller).

logon script active directory3

logon script active directory4

Edit the virtual machine settings ➜ Click on ➜ Add…

logon script active directory5

Select ➜ Hard Disk ➜ then click on ➜ Next >

logon script active directory6

Click on ➜ Next.

logon script active directory8

Click on ➜ Next.

logon script active directory7

Give 10 GB disk size ➜ Store virtual disk as a single file ➜ then click on ➜ Next.

logon script active directory9

Click on ➜ Finish.

logon script active directory10

Click ‘OK’ and start the machine.

logon script active directory11

In the Server Manager ➜ Select ➜ File and Storage Services.

logon script active directory12

Click on ➜ Disks.

logon script active directory13

Right-click on disk 1 ➜ select ➜ New Volume…

logon script active directory14

Click on ➜ Next.

logon script active directory15

Click on ➜ Next.

logon script active directory16

Click on ➜ OK.

logon script active directory17

logon script active directory18

Select Drive letter: Z ➜ then click on ➜ Next.

logon script active directory19

At the Volume label, type: Network_Share ➜ then click on ➜ Next.

logon script active directory20

Click on ➜ Create.

logon script active directory21

Click on ➜ File Explorer icon.

logon script active directory22

Double-click ➜ Network_Share disk.

logon script active directory23

Right-click and then select ➜ New ➜ Folder.

logon script active directory24

Rename the new folder as: Users_Shares.

logon script active directory25

Right-click on the folder ➜ then select ➜ Properties.

logon script active directory26

In the Sharing tab, click on ➜ Share…

logon script active directory27

Select ➜ Everyone ➜ then click on ➜ Add.

logon script active directory28

Select ➜ Read/Write ➜ then click on ➜ Share.

logon script active directory29

Click on ➜ Done.

Task 2:

Create the logon script to map a network drive

logon script active directory30

Click on ➜ Folder Icon to open the Windows Explorer at your DC.

logon script active directory31

The default location for logon scripts is the NETLOGON share, which, by default, is shared on all Domain Controllers in an Active Directory forest, and is located in the following folder:

%SystemRoot%\SYSVOL\sysvol\<domain DNS name>\scripts

Where %SystemRoot% is usually “C:\Windows” and <domain DNS name> is the DNS name of the domain, similar to “lab.local”.

This folder, which is a part of the SYSVOL special folder, is replicated to all the Domain Controllers in the domain.

Please type: %SystemRoot%\SYSVOL\sysvol\ and then press ➜ Enter Key.

logon script active directory32

logon script active directory33

Double-click on ➜ lab.local .

logon script active directory34

Double-click on ➜ scripts.

logon script active directory35

As you can see at the moment, we don’t have any logon script at our system.

logon script active directory36

The Administrator of the Domain has assigned a new Hard Disk at the system and they created a new network share for all the users of the Domain lab.local .

Now, the Administrator wants to make this Network Drive available for each user that logs in at the Domain with their client machines.

For this reason, the Administrator instead of going to each client present at the company and mapping the drive manually, they will create a script which will map this drive automatically.

logon script active directory37

In the scripts folder ➜ right-click on ➜ New ➜ select ➜ Text Document.

logon script active directory38

Type: login ➜ and then press Enter.

logon script active directory39

Select ➜ View ➜ then flag ➜ File name extensions ➜ and ➜ Hidden items.

logon script active directory40

Now you can see the file name followed by its extension which is .txt .

logon script active directory41

We need to rename this file extension to transform this simple text file into an executable batch file.

Right-click on the login.txt file ➜ then select ➜ Rename.

Please rename ONLY the extension name from txt to bat as shown.

Then press ➜ ENTER.

logon script active directory42

Confirm with ‘Yes’.

logon script active directory43

Right-click again at login.bat and then ➜ select➜ Edit

logon script active directory44

In this window, we will now insert our code to map the network drive.

@echo OFF

NET USE Z: “\\DC1\Users_Shares”

logon script active directory45

We need to give Domain Users permission to this file before we can run it. Save the file and close it.

logon script active directory46

Right-click on the file ➜ then select ➜ Properties.

logon script active directory47

Select the Security TAB ➜ then click on ➜ Edit…

logon script active directory48

Click on ➜ Add…

logon script active directory49

Type: Domain Users ➜ then click on ➜ Check Names.

logon script active directory50

Click on ➜ OK.

logon script active directory51

Check that the Domain Users have ➜ Read & execute + Read permissions as shown above ➜ then click on ➜ OK.

logon script active directory52

Confirm 2 times with ‘Yes’.

logon script active directory53

Then click on ➜ OK to close this window.

C:\Windows\SYSVOL\sysvol\lab.local\scripts\login.bat

Task 3:

Create a Group Policy Object to connect the logon script we just created to the user profile at Active Directory

logon script active directory54

In Server Manager Click on ➜ Tools ➜ then select ➜ Group Policy Management.

logon script active directory55

Select Domains ➜ lab.local ➜ then click on ➜ Create a GPO in this domain, and Link it here…

logon script active directory56

Give the name: Logon Script GPO ➜ then click on ➜ OK.

logon script active directory57

Right-click on Logon Script GPO ➜ then click on ➜ Edit…

logon script active directory58

Select ➜ User Configuration ➜ select ➜ Windows Settings ➜ select ➜ Scripts (Logon/Logoff) ➜ double-click on ➜ Logon.

logon script active directory59

Click on ➜ Show Files…

logon script active directory60

Copy the login.bat file from:

C:\Windows\SYSVOL\sysvol\lab.local\scripts

And paste it to:

\\lab.local\SysVol\lab.local\Policies\{AA28168A-1AB0-4E74-9A24-16B15BDC52D3}\User\Scripts\Logon

logon script active directory61

You can browse to check if it’s there if you wish.

logon script active directory62

Click on ➜ Add…

logon script active directory63

Click on ➜ Browse…

logon script active directory64

As you can see, the script is there. Close all the windows.

Task 4:

Test the logon script at a Windows Client Machine

Please log off if you are logged in at your Windows Machine and log back in.

logon script active directory65

Right-click on the Start icon ➜ Select ➜ Shut down or sign out ➜ click on ➜ Sign out.

logon script active directory66

Log back in.

logon script active directory67

Navigate to your Windows Explorer and now you can see the new Z Driver mapped!

You have learned how to create a logon script to map a drive for a user of the Active Directory through GPO.

Newsletter Subscribe

Stay Informed, Stay Inspired: Subscribe for Cutting-Edge IT-Certification Insights

101 Labs Newsletter