{"id":4012,"date":"2013-03-17T00:01:00","date_gmt":"2013-03-17T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2013\/03\/17\/weekend-scripter-use-powershell-to-configure-a-new-laptop\/"},"modified":"2013-03-17T00:01:00","modified_gmt":"2013-03-17T00:01:00","slug":"weekend-scripter-use-powershell-to-configure-a-new-laptop","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/weekend-scripter-use-powershell-to-configure-a-new-laptop\/","title":{"rendered":"Weekend Scripter: Use PowerShell to Configure a New Laptop"},"content":{"rendered":"<p><strong>Summary<\/strong>: Microsoft Scripting Guy, Ed Wilson, talks about using Windows PowerShell to configure a new laptop.<\/p>\n<p>Microsoft Scripting Guy, Ed Wilson, is here. WooHoo! My new laptop arrived. Oh, no&hellip;I now have a lot of work to do to install and configure Windows&nbsp;8 on it. You see, I never, never simply turn on and use a new laptop&mdash;that is not the way I operate. I always do a fresh installation. I am not saying one needs to always do this, but I like to know what is going on and make my own decisions. So here I am with a lot of work to do.<\/p>\n<h2>Setting up the new laptop<\/h2>\n<p>A while back I began working on a new computer deployment module that helps me configure a number of things that simply irate me about default installs. Today I am going to discuss a few types of things that I need to configure.<\/p>\n<h3>I do not want to defrag my SSD drive<\/h3>\n<p>This one is easy. In Windows&nbsp;8, there is a Scheduled Task module, and all I need to do is disable one scheduled task. When I first tried the command, I received the following error message:<\/p>\n<p style=\"padding-left: 30px\">PS C:\\&gt; Get-ScheduledTask -TaskName *defrag* | Disable-ScheduledTask<\/p>\n<p style=\"padding-left: 30px\">Disable-ScheduledTask : Access is denied.<\/p>\n<p style=\"padding-left: 30px\">At line:1 char:40<\/p>\n<p style=\"padding-left: 30px\">+ Get-ScheduledTask -TaskName *defrag* | Disable-ScheduledTask<\/p>\n<p style=\"padding-left: 30px\">+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ~~~~~~~~~~~~~~~~~~~~~<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp; + CategoryInfo&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : PermissionDenied: (PS_ScheduledTask:Root\/Microsoft\/..<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp; .S_ScheduledTask) [Disable-ScheduledTask], CimException<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp; + FullyQualifiedErrorId : HRESULT 0x80070005,Disable-ScheduledTask<\/p>\n<p>When I started Windows PowerShell with Admin rights, the command came off without a hitch as shown here.<\/p>\n<p style=\"padding-left: 30px\">PS C:\\&gt; Get-ScheduledTask -TaskName *defrag* | Disable-ScheduledTask<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p style=\"padding-left: 30px\">TaskPath&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; TaskName&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Sta<\/p>\n<p style=\"padding-left: 30px\">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p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ScheduledDefrag&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dis<\/p>\n<h3>I do not want to hibernate<\/h3>\n<p>Windows&nbsp;8 has a cool feature called Fast Start. Unfortunately, I have a scavenged SSD in my laptop that is really small, so I cannot afford the disk space of Hiberfile.sys. Anyway, guess what? Windows&nbsp;8 on an SSD boots up pretty quickly anyway. So this is a simple one-line command using the PowerCfg command-line tool.<\/p>\n<p style=\"padding-left: 30px\">Powercfg \/H OFF<\/p>\n<p><strong>Note<\/strong>&nbsp;&nbsp;&nbsp;This command also requires Admin rights. If you run it without Admin rights, the following error arises:<\/p>\n<p style=\"padding-left: 30px\">PS C:\\&gt; powercfg \/H OFF<\/p>\n<p style=\"padding-left: 30px\">An unexpected error condition has occurred. Unable to perform operation. You may not have permission to perform this operation.<\/p>\n<h3>I want to manage my own page file<\/h3>\n<p>If I use <strong>Get-CimInstance<\/strong> to query for instances of Win32_PageFileSetting, guess what? It returns nothing&mdash;not a thing. There is not an instance of Win32_PageFileSetting because Windows is managing the page file.<\/p>\n<h4><strong>Disable auto management of the page file<\/strong><\/h4>\n<p>So the first thing I need to do is to turn off auto management of the page file. I use the Win32_ComputerSystem WMI class to do this. Here is the command.<\/p>\n<p style=\"padding-left: 30px\">PS C:\\&gt; Set-CimInstance -Query &#8220;Select * from win32_computersystem&#8221; -Property @{autom<\/p>\n<p style=\"padding-left: 30px\">aticmanagedpagefile=&#8221;False&#8221;}<\/p>\n<p style=\"padding-left: 30px\">PS C:\\&gt; Get-CimInstance win32_PageFileSetting<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MaximumSize Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Caption<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8212;&#8212;&#8212;&#8211; &#8212;-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8212;&#8212;-<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0 C:\\pagefile.sys&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;C:\\ &#8216;pagefile.sys&#8217;<\/p>\n<h4><strong>Specify the size of the page file<\/strong><\/h4>\n<p>To set the size of the page file, I can now use the <strong>Set-CimInstance<\/strong> cmdlet, and set the size by using the Win32_PageFileSetting cmdlet. Here is the script I used.<\/p>\n<p style=\"padding-left: 30px\">PS C:\\&gt; Set-CimInstance -Query &#8220;Select * from win32_PageFileSetting&#8221; -Property @{Init<\/p>\n<p style=\"padding-left: 30px\">ialSize=3072;MaximumSize=3072}<\/p>\n<p>It took a few times before I came up with the right combination. In the end, I looked up the <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/windows\/desktop\/aa394245(v=vs.85).aspx\" target=\"_blank\">Win32_PageFileSetting WMI class<\/a> on MSDN, and I found that it wants the values in megabytes.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/6012.wes-3-17-13-01.png\"><img decoding=\"async\" title=\"Image of command output\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/6012.wes-3-17-13-01.png\" alt=\"Image of command output\" \/><\/a><\/p>\n<p>I invite you to follow me on <a href=\"http:\/\/bit.ly\/scriptingguystwitter\" target=\"_blank\">Twitter<\/a> and <a href=\"http:\/\/bit.ly\/scriptingguysfacebook\" target=\"_blank\">Facebook<\/a>. If you have any questions, send email to me at <a href=\"mailto:scripter@microsoft.com\" target=\"_blank\">scripter@microsoft.com<\/a>, or post your questions on the <a href=\"http:\/\/bit.ly\/scriptingforum\" target=\"_blank\">Official Scripting Guys Forum<\/a>. See you tomorrow. Until then, peace.<\/p>\n<p><strong>Ed Wilson, Microsoft Scripting Guy<\/strong>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: Microsoft Scripting Guy, Ed Wilson, talks about using Windows PowerShell to configure a new laptop. Microsoft Scripting Guy, Ed Wilson, is here. WooHoo! My new laptop arrived. Oh, no&hellip;I now have a lot of work to do to install and configure Windows&nbsp;8 on it. You see, I never, never simply turn on and use [&hellip;]<\/p>\n","protected":false},"author":596,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[16,340,31,417,3,61,45],"class_list":["post-4012","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-desktop-management","tag-general-mgmt-tasks","tag-operating-system","tag-page-files","tag-scripting-guy","tag-weekend-scripter","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>Summary: Microsoft Scripting Guy, Ed Wilson, talks about using Windows PowerShell to configure a new laptop. Microsoft Scripting Guy, Ed Wilson, is here. WooHoo! My new laptop arrived. Oh, no&hellip;I now have a lot of work to do to install and configure Windows&nbsp;8 on it. You see, I never, never simply turn on and use [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/4012","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\/596"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=4012"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/4012\/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=4012"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=4012"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=4012"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}