Group Policy settings for applying scripts
You can use Group Policy scripts to perform a number of tasks. There might be actions that you need to perform every time a computer starts up or shuts down, or when users sign in or sign out. For example, you can use scripts to:
• Clean up desktops when users sign out and shut down computers.
• Delete the contents of temporary directories.
• Map drives or printers.
• Set environment variables.
• Assign scripts to the computer to run in the security context of the Local System account.
Infrastructure Requirement :
- 1 DC SERVER (DC-CLOUD)
- Client PC running Windows 10 (CLIENT-10)
Lets get started.
01 – Create a logon script to display a message
1 – On DC-CLOUD, click Start, type Notepad, and then click Notepad.
2 – In Notepad, type the following command, and then press Enter:
Msgbox “This is the script”
3 – Click the File menu, and then click Save As.
4 – In the Save As dialog box, in the File name text box, type . then navigation pane, click Desktop, and then click Save.
5 – On the Desktop, right-click the file, and then click Copy.
02 – Create and link a GPO to use the script
1 – Open Server Manager, click Tools, and then click Group Policy Management.
2 – Expand Forest: , and then expand Domains, Right-click , and then click Create a GPO in this domain and Link it here.
3 – In the New GPO dialog box, in the Name text box, type User Logon Script, and then click OK.
4 – Expand , right-click the User Logon Script GPO, and then click Edit.
5 – In the Group Policy Management Editor window, under User Configuration, expand Policies, expand Windows Settings, and then click Scripts (Logon/Logoff).
6 – In the details pane, double-click Logon.
7 – In the Logon Properties dialog box, click Show Files.
8 – In the details pane, right-click a blank area, and then right-click Paste.
Close the Logon window.
9 – In the Logon Properties dialog box, click Add.
10 – In the Add a Script dialog box, click Browse.
11 – Click the script, and then click Open.
12 – Click OK twice to close all dialog boxes.
Close both the Group Policy Management Editor window and the Group Policy Management Console.
03 – Sign in to a client computer and test the results
1 – On CLIENT-10, sign out and then sign in as Windows\Administrator with password [email protected].
2 – Right-click Start, and then click Command Prompt.
3 – In the Command Prompt window, type the following command, and then press Enter:
4 – If prompted, in the command prompt window, type the following, and then press Enter:
5 – On CLIENT-10, sign out and then sign in as Windows\Administrator with password [email protected].
Verify that the script runs, displaying the message you configured in the GPO earlier
Note: This could take up to ten minutes to display. If the message does not display,
restart CLIENT-10 and repeat step one through five.