title: How to fix 'The remote server returned an error: (401) Unauthorized' when using Web Deploy on IIS 10 with IIS Manager Credentials?
body: <p>I am attempting to deploy a web application to IIS 10 on Windows Server 2019. I have a PowerShell script that executes the MsDeploy.exe command using basic authentication. The username and password is provided in the query string POSTed to the web server for the deployment. After a little playing around, I was able to replicate the problem using a simple command in the regular Windows command prompt:</p>
  <pre class="lang-sh prettyprint-override"><code>&quot;C:\Program Files\IIS\Microsoft Web Deploy V3\msdeploy.exe&quot; -setParamFile:C:\...\Deploy.ContinuousIntegration.xml -source:package=C:\...\Web.zip -dest:auto,computerName=https://hostname:8172/msdeploy.axd?site=,username=DeployUser,password=DeployPassword,authtype=Basic,includeAcls=False -verb:sync -disableLink:AppPoolExtension -disableLink:ContentExtension -disableLink:CertificateExtension -allowUntrusted -enableRule:AppOffline -enableRule:EncryptWebConfig
  </code></pre>
  <p>The same command formatted for better readability:</p>
  <pre class="lang-sh prettyprint-override"><code>&quot;C:\Program Files\IIS\Microsoft Web Deploy V3\msdeploy.exe&quot; ^
      -setParamFile:C:\...\Deploy.ContinuousIntegration.xml ^
      -source:package=C:\...\Web.zip ^
      -dest:auto,computerName=https://hostname:8172/msdeploy.axd?site=,username=DeployUser,password=DeployPassword,authtype=Basic,includeAcls=False ^
      -verb:sync ^
      -disableLink:AppPoolExtension ^
      -disableLink:ContentExtension ^
      -disableLink:CertificateExtension ^
      -allowUntrusted ^
      -enableRule:AppOffline ^
      -enableRule:EncryptWebConfig
  </code></pre>
  <p>Running the command above returns this response:</p>
  <blockquote>
  <p>Error Code: ERROR_USER_UNAUTHORIZED<br />
  More Information: Connected to the remote computer (&quot;hostname&quot;) using the Web Management Service, but could not authorize. Make sure that you are using the correct user name and password, that the site you are connecting to exists, and that the credentials represent a user who has permissions to access the site.  Learn more at: <a href="https://go.microsoft.com/fwlink/?LinkId=221672#ERROR_USER_UNAUTHORIZED.%5C" rel="nofollow noreferrer">https://go.microsoft.com/fwlink/?LinkId=221672#ERROR_USER_UNAUTHORIZED.\</a>
  Error: The remote server returned an error: (401) Unauthorized.<br />
  Error count: 1.</p>
  </blockquote>
  <p>I attempted to use a non-administrative user created in IIS, not Windows.</p>
  <p><strong>Process Used to Create IIS User</strong></p>
  <ol>
  <li>Open Internet Information Services Manager</li>
  <li>Chose the hostname for the server</li>
  <li>Opened &quot;Management Service&quot;</li>
  <li>Set &quot;Identity Credentials&quot; to &quot;Windows credentials or IIS Manager credentials&quot;</li>
  <li>Left everything else as the default value and started the Web Deploy service (which started successfully)</li>
  <li>Opened &quot;IIS Manager Users&quot; under the same hostname.</li>
  <li>Added a new user with a password (the password only contains letters and numbers).</li>
  <li>Opened &quot;IIS Manager Permissions&quot; under &quot;Default Web Site&quot; for the same hostname</li>
  <li>Allowed the user I previously created in &quot;IIS Manager Users&quot; (Level: Site)</li>
  </ol>
  <p>I used a parameter file for MsDeploy, the contents of which are below:</p>
  <pre class="lang-xml prettyprint-override"><code>&lt;parameters&gt;
      &lt;setParameter name=&quot;IIS Web Application Name&quot; value=&quot;Default Web Site/Folder&quot; /&gt;
  &lt;/parameters&gt;
  </code></pre>
  <p>I even tried changing the <code>computerName</code> parameter to <code>wmsvc</code> as suggested in <a href="https://stackoverflow.com/a/48939067/3092298">this answer</a>, but I still got the same error.</p>
  <p>Any idea how to fix the &quot;unauthorized&quot; error?</p>