title: Powershell Invoke-Sqlcmd: xp_create_subdir() returned error 5, 'Access is denied.'
body: <p>I was trying to use run a powershell script, which using invoke-sqlcmd to execute my script file to backup my database into specific folder.</p>
  
  <p><code>Invoke-Sqlcmd -InputFile $scriptfile -ServerInstance $ServerName -Database "Master" -Username $sqlUser -Password $sqlPassword</code></p>
  
  <p>It works fine in <strong>D drive</strong> (or other drives), but whenever on/at <strong>C drive</strong> and place the backup database at <strong>C drive</strong>, it will hit:</p>
  
  <p><code>Invoke-Sqlcmd: xp_create_subdir() returned error 5, 'Access is denied.'</code></p>
  
  <p>I wonder if I have missed out any permission grant?</p>
  
  <p>The user permission (domain\ServiceAccount) was granted to <strong>FullControl</strong> to the output folder before invoke-sqlcmd.</p>
  
  <p>Please help.</p>