{"id":324,"date":"2006-11-23T05:00:00","date_gmt":"2006-11-23T13:00:00","guid":{"rendered":"http:\/\/testblog.sapien.com\/index.php\/2006\/11\/23\/posh-and-logon-scripts\/"},"modified":"2006-11-23T05:00:00","modified_gmt":"2006-11-23T13:00:00","slug":"posh-and-logon-scripts","status":"publish","type":"post","link":"https:\/\/dev.sapien.com\/blog\/2006\/11\/23\/posh-and-logon-scripts\/","title":{"rendered":"PoSH and Logon Scripts"},"content":{"rendered":"<p><P>I&#8217;d been under the impression &#8211; and said so at some recent conferences &#8211; that PowerShell can&#8217;t be used for logon scripts. Not so, it turns out, although I still don&#8217;t think it&#8217;s well-suited for the task.<\/P><P>Let me be clear in that I don&#8217;t think <EM>logon scripts themselves<\/EM> are well-suited to a task. The primary purpose of logon scripts is to map drives and printers; both are tasks, I feel, better accomplished in other ways. Users can be given UNC shortcuts (or just given UNCs) to access network drives, for example. Yes, I know, I hear you: &#8220;My users cant <EM>handle<\/EM> UNCs!&#8221; Yes, they can. DFS UNCs &#8211; <A href=\"file:\/\/\\\\company\\users\\donj\">\\\\company\\users\\donj<\/A>, for example, rather than <A href=\"file:\/\/\\\\fs03frzwin03\\donj$\">\\\\fs03frzwin03\\donj$<\/A> &#8211; are easy to remember and write down, and you can make shortcuts to them. Force your users to use them instead of drive letters and within a month all the complaints will have gone away; catering to laziness &#8211; which is all most drive mapping is, really &#8211; just encourages more laziness.<\/P><P>But I digress. PoSH <EM>can<\/EM> be used as a logon script processor. Just run <STRONG>powershell -command <EM>scriptpath<\/EM><\/STRONG>and it&#8217;ll work. However, there are a couple of reasons I don&#8217;t think PowerShell is great for this &#8211; and most of these reasons aren&#8217;t because PowerShell lacks capability, understand, but because PowerShell comes from a more modern, &#8220;post-logon script&#8221; world, shall we say.<\/P><P>First, PoSH doesn&#8217;t inherently have the ability to map logon drives. Yes, it can add a PSDrive, assigning a drive letter to a UNC, but that assignment doesn&#8217;t &#8220;show up&#8221; outside of the PoSH shell session (e.g., it doesn&#8217;t pop up in Explorer). You <EM>can<\/EM> instantiate WScript.Network and use the MapNetworkDrive method &#8211; but you could do that more easily from within VBScript, or do something similar and more easily in KiXtart. <\/P><P>Second, unlike VBScript, PoSH isn&#8217;t installed (now) by default on Windows, which means you&#8217;d need to deploy it. Deploying isn&#8217;t hard since you can use SMS or GPO or whatever to do so; but it&#8217;s one more step. Even KiXtart is usually pretty easy to deploy (and depending on what version you&#8217;re using, you might not need to &#8220;deploy&#8221; it at all). <\/P><P>Third, PoSH has excellent security, and by default doesn&#8217;t run scripts at all. So to use PoSH for logon scripts, you need to set all your machines&#8217; PoSH execution policy to AllSigned (I won&#8217;t even get into how bad an idea it would be to sett <EM>every machine in your environment<\/EM> to any lesser execution policy).<\/P><P>So&#8230; yeah, while PoSH can run logon scripts, I&#8217;m sure that wasn&#8217;t a primary design consideration. I&#8217;d first seriously question the purpose of your logon scripts. I&#8217;m not saying they don&#8217;t exist, but I haven&#8217;t run across many logon scripts that didn&#8217;t exist solely to cater to user laziness, which is a horrible idea. I&#8217;d second question &#8211; assuming I gave in to the logon script argument &#8211; PoSH as my choice for logon scripts. I&#8217;d personally opt for a logon script language that was simpler and less capable of being used against me (VBScript doesn&#8217;t qualify for this, either, really, and KiXtart has gained too much functionality over the years, too).<\/P><P>The one argument I&#8217;d buy for PoSH as a logon script processor is its better security &#8211; you <EM>can<\/EM> ensure that only digitally-signed scripts run, which does make for a safer, more controlled environment. For example, control who has access to the code-signing cert, and you can create a workflow &#8220;choke point&#8221; to exercise change management over logon scripts. I like that idea. Of course, with TrustPolicy, you could be doing something similar with VBScript, too; PowerShell isn&#8217;t unique in this capability although it is <EM>much<\/EM> easier to centrally manage execution policy via Group Policy that it is with VBScript.<\/P><P>But here&#8217;s the real question: Do your existing logon scripts work? If so, just use &#8217;em. No need to translate them to PowerShell. If you just want to translate them &#8220;for fun,&#8221; well, okay; I&#8217;m sure it&#8217;ll be a great learning experience and a decent way of becoming accustomed to PoSH. However&#8230; I wish <EM>I<\/EM> had that kinda free time!<\/P><P>But then again&#8230; it&#8217;s 2006. Almost 2007. We&#8217;ve been using logon scripts for nigh unto 15 years. Isn&#8217;t it time to stop it? I mean, if your users can remember <A href=\"http:\/\/www.TimeWastingWebSite.com\">www.TimeWastingWebSite.com<\/A>, surely they can jot down a few UNCs for commonly-accessed files, no? And, remember, if you get a DFS tree on top of your existing UNC shares, users don&#8217;t need to know actual server names, and you&#8217;d be able to rearrange shares behind-the-scenes when necessary. Give it some thought, &#8216;kay?<\/P><\/p>\n","protected":false},"excerpt":{"rendered":"<p><P>I&#8217;d been under the impression &#8211; and said so at some recent conferences &#8211; that PowerShell can&#8217;t be used for logon scripts. Not so, it turns out, although I still don&#8217;t think it&#8217;s well-suited for the task.<\/P><P>Let me be clear in that I don&#8217;t think <EM>logon scripts themselves<\/EM> are well-suited to a task. The primary purpose of logon scripts &#8230;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[2,25],"tags":[],"class_list":["post-324","post","type-post","status-publish","format-standard","hentry","category-general","category-windows-powershell"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/324","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/comments?post=324"}],"version-history":[{"count":0,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/324\/revisions"}],"wp:attachment":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/media?parent=324"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/categories?post=324"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/tags?post=324"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}