{"id":18889,"date":"2015-09-22T10:29:40","date_gmt":"2015-09-22T09:29:40","guid":{"rendered":"https:\/\/aidanfinn.com\/?p=18889"},"modified":"2015-09-22T12:52:16","modified_gmt":"2015-09-22T11:52:16","slug":"install-windowsfeature-an-unexpected-error-has-occurred-error-when-you-run-install-windowsfeature-in-a-windows-server-container","status":"publish","type":"post","link":"https:\/\/aidanfinn.com\/?p=18889","title":{"rendered":"&ldquo;Install-WindowsFeature : An unexpected error has occurred&rdquo; Error When You Run Install-WindowsFeature In A Windows Server Container"},"content":{"rendered":"<p>This is one of those issues that makes me question a lot of step-by-step blog posts on Windows Server Containers that are out there &#8211; plenty of people were quick to publish guides on containers and didn&#8217;t mention encountering this issue which I always encounter; I suspect that there\u2019s a lot of copy\/pasting from Microsoft sites with little actual testing in a rush to be first to publish. It\u2019s clear that many bloggers didn\u2019t try to install things in a container that required administrator rights, because UAC was blocking those actions. In my case, it was installing IIS in a Windows Server 2016 (WS2016) Technical Preview 3 (TPv3) container.<\/p>\n<p>In my lab, I created a new container and then logged in using the following (I had already populated $Container by\u00a0 returning the container object into the variable):<\/p>\n<pre class=\"lang:default decode:true \">Enter-PSSession -ContainerId $Container.ContainerId -RunAsAdministrator<\/pre>\n<p>And then I tried to install some role\/feature, such as IIS using Install-WindowsFeature:<\/p>\n<pre class=\"lang:default decode:true\">Install-WindowsFeature -Name Web-Server\r\n<\/pre>\n<p>I logged in using -RunAsAdministrator so I should have no issues with UAC, right? Wrong! Because the installation fails as follows:<\/p>\n<blockquote><p>Install-WindowsFeature : An unexpected error has occurred. The system cannot find the file specified.\u00a0 Error: 0x80070002<br \/>\n+ CategoryInfo\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 : InvalidResult: (@{Vhd=; Credent&#8230;Name=localhost}:PSObject) [Install-WindowsFeature], Exception<br \/>\n+ FullyQualifiedErrorId : RegistryKey_OpenSubKey_Failed,Microsoft.Windows.ServerManager.Commands.AddWindowsFeatureCommand<\/p><\/blockquote>\n<p><a href=\"https:\/\/aidanfinn.com\/wp-content\/uploads\/2015\/09\/image8.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; display: block; padding-right: 0px; margin-right: auto; border: 0px;\" title=\"image\" src=\"https:\/\/aidanfinn.com\/wp-content\/uploads\/2015\/09\/image_thumb7.png\" alt=\"image\" width=\"600\" height=\"100\" border=\"0\" \/><\/a><\/p>\n<p>What\u2019s the solution? When you are remoted into the container you need to raise your administrator privileges to counter UAC. You can do this as follows, after you log into the container:<\/p>\n<p>Start-Process Powershell.exe -Verb runAs<\/p>\n<p>Run Install-WindowsFeature now and it will complete.<\/p>\n<p><a href=\"https:\/\/aidanfinn.com\/wp-content\/uploads\/2015\/09\/image9.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; display: block; padding-right: 0px; margin-right: auto; border: 0px;\" title=\"image\" src=\"https:\/\/aidanfinn.com\/wp-content\/uploads\/2015\/09\/image_thumb8.png\" alt=\"image\" width=\"550\" height=\"89\" border=\"0\" \/><\/a><\/p>\n<p>Sorted!<\/p>\n<p><em>Note: I have found in my testing that IIS behaves poorly in TPv3. This might be why Microsoft&#8217;s getting started guides on MSDN use nginx web server instead of IIS! I&#8217;ve confirmed that nginx works perfectly well.<\/em><\/p>\n<div id=\"scid:0767317B-992E-4b12-91E0-4F059A8CECA8:285d6adf-2974-4b30-8493-a8f368bb0fcc\" class=\"wlWriterEditableSmartContent\" style=\"float: none; margin: 0px; display: inline; padding: 0px;\">Technorati Tags: <a href=\"http:\/\/technorati.com\/tags\/Windows+Server+2016\" rel=\"tag\">Windows Server 2016<\/a>,<a href=\"http:\/\/technorati.com\/tags\/Containers\" rel=\"tag\">Containers<\/a>,<a href=\"http:\/\/technorati.com\/tags\/Hyper-V\" rel=\"tag\">Hyper-V<\/a>,<a href=\"http:\/\/technorati.com\/tags\/Virtualisation\" rel=\"tag\">Virtualisation<\/a>,<a href=\"http:\/\/technorati.com\/tags\/Deployment\" rel=\"tag\">Deployment<\/a>,<a href=\"http:\/\/technorati.com\/tags\/PowerShell\" rel=\"tag\">PowerShell<\/a>,<a href=\"http:\/\/technorati.com\/tags\/IIS\" rel=\"tag\">IIS<\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>This is one of those issues that makes me question a lot of step-by-step blog posts on Windows Server Containers that are out there &#8211; plenty of people were quick to publish guides on containers and didn&#8217;t mention encountering this issue which I always encounter; I suspect that there\u2019s a lot of copy\/pasting from Microsoft &hellip; <a href=\"https:\/\/aidanfinn.com\/?p=18889\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;&ldquo;Install-WindowsFeature : An unexpected error has occurred&rdquo; Error When You Run Install-WindowsFeature In A Windows Server Container&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":18900,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_uf_show_specific_survey":0,"_uf_disable_surveys":false,"footnotes":""},"categories":[20],"tags":[143,174,181,182,87,195,137],"class_list":["post-18889","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-hyper-v","tag-containers","tag-deployment","tag-hyper-v","tag-iis","tag-powershell","tag-virtualisation","tag-windows-server-2016"],"aioseo_notices":[],"jetpack_featured_media_url":"https:\/\/aidanfinn.com\/wp-content\/uploads\/2015\/09\/5315.powershell_2D00_logo.gif_2D00_550x01.png","amp_enabled":true,"_links":{"self":[{"href":"https:\/\/aidanfinn.com\/index.php?rest_route=\/wp\/v2\/posts\/18889","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/aidanfinn.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/aidanfinn.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/aidanfinn.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/aidanfinn.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=18889"}],"version-history":[{"count":11,"href":"https:\/\/aidanfinn.com\/index.php?rest_route=\/wp\/v2\/posts\/18889\/revisions"}],"predecessor-version":[{"id":18908,"href":"https:\/\/aidanfinn.com\/index.php?rest_route=\/wp\/v2\/posts\/18889\/revisions\/18908"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/aidanfinn.com\/index.php?rest_route=\/wp\/v2\/media\/18900"}],"wp:attachment":[{"href":"https:\/\/aidanfinn.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=18889"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/aidanfinn.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=18889"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/aidanfinn.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=18889"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}