![Windows Server 2016 Automation with PowerShell Cookbook(Second Edition)](https://wfqqreader-1252317822.image.myqcloud.com/cover/733/36700733/b_36700733.jpg)
Getting ready
To deploy a printer to a client, you first need a client computer system. Our demo lab includes a Windows 10 Enterprise client (SG-CL1), which we use in this recipe. To test this recipe, you need the client computer, the print server (PSVR), and the domain controller (DC1).
Once you create the client, you can run the following commands to add it to the domain in the Sales OU (created separately):
$Cred = Get-Credential 'Reskit\administrator'
# you enter the password $OUPath = 'OU=Sales, DC=Reskit,DC=Org' Add-Computer -DomainName 'Reskit' `
-DomainCredential $cred
Next, you need a Group Policy object that deploys the logon script. The easiest way to create this Group Policy Object (GPO) is to use the GUI-there are no PowerShell cmdlets (or WMI/.NET objects) that can help.
To create the GPO, you use the Group Policy Management Console (GPMC) tool. This tool is part of the management tools for Active Directory, and is also part of the Remote Server Admin Tools (RSAT) that you can download for client systems. Once you install the GPMC, you can run it and expand the domain to make our Sales OU visible:
![](https://epubservercos.yuewen.com/7D2E6F/19470404008937606/epubprivate/OEBPS/Images/1246aa8e-a929-46da-a0f0-0cef8ca38f6d.png?sign=1739013897-a6AT790wbEwF1ffdGRFjgR5t8cY4YkB3-0-f5a226a6ed3b3c42477c691b373771a1)
Next, you right-click the Sales OU, specify the Group Policy Name, and click OK:
![](https://epubservercos.yuewen.com/7D2E6F/19470404008937606/epubprivate/OEBPS/Images/f0488bf7-3fa4-4dea-a4b9-324f07c5aef9.png?sign=1739013897-wDBYBA6JDgsOLLYeqbXCcRR5AQfmiDl8-0-c5935c567c4790ab1f1231e47536d479)
With the GPO created, right-click the GPO and select Edit:
![](https://epubservercos.yuewen.com/7D2E6F/19470404008937606/epubprivate/OEBPS/Images/13f3a6f4-d7f8-408c-82e8-0c8d38609c3b.png?sign=1739013897-LVer7URdR0QYrrrKWXPo4ETxA3sqqPjU-0-f600740fd6f4873d33d9f9c9b6468112)
This brings up the Group Policy Management Editor. Select the User Configuration | Windows Settings | Scripts (Logon/Logoff):
![](https://epubservercos.yuewen.com/7D2E6F/19470404008937606/epubprivate/OEBPS/Images/c300f540-6f07-41a6-9e83-119a0782b19f.png?sign=1739013897-q4b5fmb36QYSYQk74Xsz7Rlw7OFiYBzH-0-904923db9487b74dd916ac20cb78bfe1)
Then double-click Logon to bring up the Logon Properties dialog, and then click on the PowerShell Scripts tab:
![](https://epubservercos.yuewen.com/7D2E6F/19470404008937606/epubprivate/OEBPS/Images/d4a876a0-35a0-4505-b8c6-fb863ffd6c13.png?sign=1739013897-5utuaNQ1Gfj57LykjdBVV65Jw8hmNjMY-0-6ef47302812b614c95784c5dd0e9e996)
From this dialog, click on Add to bring up the Add a Script dialog:
![](https://epubservercos.yuewen.com/7D2E6F/19470404008937606/epubprivate/OEBPS/Images/5a6aecd4-77e4-4b2b-9805-0b830cd819cf.png?sign=1739013897-yyt8YeiwbClpooXvileoFRPl3l7wWkbH-0-3169b75762b7514d608500135619104a)
From this dialog, enter the Script Name Sales Group Logon Script.ps1, then click on OK, which brings up the Logon Properties box with the script shown here:
![](https://epubservercos.yuewen.com/7D2E6F/19470404008937606/epubprivate/OEBPS/Images/82b0b0fd-abcf-4eab-8a5f-e537fdbebbeb.png?sign=1739013897-0q9i0XJvmtzBFMKOfCHYWIcUP4o2ogmn-0-a218d1706573c6d30e183d46000550d5)
Note the file name in this dialog box. This file (Sales Group Logon Script.ps1) is a file within the Logon Script folder inside the GPO object in your SYSVOL folder on your domain controller. The path for the Logon Script folder was Reskit.Org\SysVol\Reskit.Org\Policies\{CF4F8264-0FD7-4D21-8267-8F36D7CE3DCF}\UserScripts\Logon. If you are testing this, you should see a different GUID in this path.
From the Logon Properties dialog, click OK to close the dialog, then close the GPMC editor. These steps have created an empty logon script. You can add the content for this logon script by going through the following recipe.