{"id":17431,"date":"2010-08-14T00:01:00","date_gmt":"2010-08-14T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2010\/08\/14\/using-group-policy-to-deploy-a-windows-powershell-logon-script\/"},"modified":"2010-08-14T00:01:00","modified_gmt":"2010-08-14T00:01:00","slug":"using-group-policy-to-deploy-a-windows-powershell-logon-script","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/using-group-policy-to-deploy-a-windows-powershell-logon-script\/","title":{"rendered":"Using Group Policy to Deploy a Windows PowerShell Logon Script"},"content":{"rendered":"<p><strong><\/strong><\/p>\n<p><strong>Summary<\/strong>: The easiest way to deploy a <a href=\"http:\/\/technet.microsoft.com\/en-us\/scriptcenter\/powershell.aspx\">Windows PowerShell<\/a> script to users is to create a Group Policy logon script.<\/p>\n<p>&nbsp;<\/p>\n<p>Microsoft Scripting Guy Ed Wilson here. Oh&hellip;my eyes feel like they are glued to my eyelids. I am not a <a href=\"http:\/\/en.wikipedia.org\/wiki\/Night_owl_%28person%29\">night owl<\/a>, unlike the female who inhabits the house in Charlotte, who seems to enjoy howling at the moon on a regular basis. Anyway, I do like to read, and I found a fascinating book about Shakespeare for American readers at the library yesterday, and as soon as I began reading it, I felt compelled to finish it. Now it seems I must pay for my indulgence. <\/p>\n<p>I received an email from one of my friends in <a href=\"http:\/\/en.wikipedia.org\/wiki\/Monterrey\">Monterrey, Mexico<\/a>, who was asking about running a script on his workstations to empty the recycle bin. I told him the best way to do this would be to configure either a logon or logoff script via Group Policy. I was in Monterrey several years ago and have taught VBScript, <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/aa394582(VS.85).aspx\">WMI<\/a>, and Windows PowerShell workshops down there. It is a great town with excellent cuisine. Whenever I think of Monterrey, I am reminded of the <a href=\"http:\/\/en.wikipedia.org\/wiki\/Cerro_de_la_Silla\">Cerro de la Silla<\/a>, which is shown in this photo I took during my last visit. <\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/3527.wes081410011_03439DF2.jpg\"><img decoding=\"async\" height=\"454\" width=\"604\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/0066.wes081410011_thumb_29394E48.jpg\" alt=\"Photo Ed took of Cerro de la Silla\" border=\"0\" title=\"Photo Ed took of Cerro de la Silla\" style=\"border-bottom: 0px;border-left: 0px;border-top: 0px;border-right: 0px\" \/><\/a> <\/p>\n<p>I woke up this morning with a plan. I wanted to configure the Get-ProcessStartUpTimes.ps1 script I wrote <a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/2010\/08\/08\/weekend-scripter-automatically-collecting-process-snapshots.aspx\">last week<\/a> in a Weekend Scripter article to run on every computer on my network each time a user logs onto the network. In addition, because the Windows Search index service that exists in <a href=\"http:\/\/www.microsoft.com\/windows\/windows-7\/default.aspx\">Windows 7<\/a> does not exist on servers, I need to ensure that the script does not run when someone logs onto a server. <\/p>\n<p>To do this, I decided to create a new <a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/tags\/windows+powershell\/group+policy\/\">Group Policy<\/a> object (GPO) and link it to my nwtraders.com domain in my forest. In the Group Policy Management Editor, I right-click the domain, and then click <strong>Create a GPO<\/strong> in this domain. This is shown in the following image.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/0363.wes081410021_73C08C22.jpg\"><img decoding=\"async\" height=\"424\" width=\"604\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/4111.wes081410021_thumb_01269F29.jpg\" alt=\"Image of start of process to create GPO\" border=\"0\" title=\"Image of start of process to create GPO\" style=\"border-bottom: 0px;border-left: 0px;border-top: 0px;border-right: 0px\" \/><\/a> <\/p>\n<p>Right-clicking the newly created GPO in the Group Policy Management Console and clicking <strong>Edit<\/strong> opens the Group Policy Management Editor, which is shown in the following image. Because I am interested in tracking not only processes that start after the user logs onto the computer but also processes that start before the logon screen, I configure a logon script for the user. There are startup and shutdown scripts that can be configured in Group Policy that are assigned at the computer configuration level, but they would not be the best place to obtain the information I&rsquo;m looking for. To set a user logon script, open the User Configuration node of the Group Policy Editor, click <strong>Windows Settings<\/strong> and then click <strong>Scripts (Logon\/Logoff)<\/strong>. <\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/3122.wes081410031_4BADDD03.jpg\"><img decoding=\"async\" height=\"374\" width=\"604\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/5661.wes081410031_thumb_122ACD0C.jpg\" alt=\"Image of Scripts (Logon\/Logoff) window\" border=\"0\" title=\"Image of Scripts (Logon\/Logoff) window\" style=\"border-bottom: 0px;border-left: 0px;border-top: 0px;border-right: 0px\" \/><\/a> <\/p>\n<p>I double-click <strong>Logon<\/strong> in the right side of the pane, and click the <strong>PowerShell Scripts<\/strong> tab as shown in the following image.<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/qanda\/hsg\/2010\/august\/hey0814\/wes-08-14-10-04.jpg\" alt=\"Image of Logon Properties\" style=\"max-width: 550px;border: 0px initial initial\" \/><\/p>\n<p>From here, I click Add, and click Browse. The <strong>Add a Script<\/strong> dialog appears. The <strong>Browse<\/strong> button opens a Windows Explorer window that is centered on the SysVol share for my domain. The cool thing is this is a great way to copy the script to the SysVol share, and I drag and drop my Get-ProcessStartUpTimes.ps1 script into the Logon script folder. <\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/3515.wes081410051_3FABECCF.jpg\"><img decoding=\"async\" height=\"374\" width=\"604\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/8802.wes081410051_thumb_0628DCD8.jpg\" alt=\"Image of dropping script into Logon script folder\" border=\"0\" title=\"Image of dropping script into Logon script folder\" style=\"border-bottom: 0px;border-left: 0px;border-top: 0px;border-right: 0px\" \/><\/a> <\/p>\n<p>Because I do not want the script to run on my servers, I need to create a WMI filter. To do this, I right-click the <strong>WMI Filters<\/strong> node in the Group Policy Management Console and click <strong>New<\/strong>. The dialog appears that is shown in the following image. After adding my WMI query (tested using the <strong>Get-WMIObject<\/strong> cmdlet), I click <strong>Save<\/strong>. <\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/5661.wes081410061_09C6F7B5.jpg\"><img decoding=\"async\" height=\"439\" width=\"604\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/3515.wes081410061_thumb_1E4C4733.jpg\" alt=\"Image of creating WMI filter\" border=\"0\" title=\"Image of creating WMI filter\" style=\"border-bottom: 0px;border-left: 0px;border-top: 0px;border-right: 0px\" \/><\/a> <\/p>\n<p>The last thing I do is go to the <strong>AuditProcessStartUp<\/strong> GPO that I had created, and select the <strong>FilterWorkstation<\/strong> WMI filter I created. <\/p>\n<p><a href=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/qanda\/hsg\/2010\/august\/hey0814\/wes-08-14-10-07.jpg\"><img decoding=\"async\" height=\"424\" width=\"604\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/7416.wes081410071_08EE91CB.jpg\" alt=\"Image of selecting the WMI filter\" border=\"0\" title=\"Image of selecting the WMI filter\" style=\"border-bottom: 0px;border-left: 0px;border-top: 0px;border-right: 0px\" \/> <\/a><\/p>\n<p>&nbsp;<\/p>\n<p>Well, that is it. The GPO is now created, and I need to allow it to replicate among my various domain controllers. Tomorrow, I will create a Windows PowerShell script to connect to the network share and to parse the process objects. <\/p>\n<p>We invite you to follow us on <a href=\"http:\/\/bit.ly\/scriptingguystwitter\">Twitter<\/a> or <a href=\"http:\/\/bit.ly\/scriptingguysfacebook\">Facebook<\/a>. If you have any questions, send email to us at <a href=\"mailto:scripter@microsoft.com\">scripter@microsoft.com<\/a>, or post your questions on the <a href=\"http:\/\/social.technet.microsoft.com\/Forums\/en\/ITCG\/threads\/\">Official Scripting Guys Forum<\/a>. See you tomorrow. Until then, peace.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Ed Wilson and Craig Liebendorfer, Scripting Guys<\/strong><\/p>\n<p><strong><br \/><\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: The easiest way to deploy a Windows PowerShell script to users is to create a Group Policy logon script. &nbsp; Microsoft Scripting Guy Ed Wilson here. Oh&hellip;my eyes feel like they are glued to my eyelids. I am not a night owl, unlike the female who inhabits the house in Charlotte, who seems to [&hellip;]<\/p>\n","protected":false},"author":595,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[152,31,87,3,61,45],"class_list":["post-17431","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-group-policy","tag-operating-system","tag-processes","tag-scripting-guy","tag-weekend-scripter","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>Summary: The easiest way to deploy a Windows PowerShell script to users is to create a Group Policy logon script. &nbsp; Microsoft Scripting Guy Ed Wilson here. Oh&hellip;my eyes feel like they are glued to my eyelids. I am not a night owl, unlike the female who inhabits the house in Charlotte, who seems to [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/17431","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/595"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=17431"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/17431\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=17431"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=17431"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=17431"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}