title: Create a SQL login for Windows user
body: <pre class="lang-psh prettyprint-override"><code>$Username = "test-usr"
  
  [System.Reflection.Assembly]::LoadWithPartialName('Microsoft.SqlServer.SMO') | out-null 
  
  $SqlServer = New-Object ('Microsoft.SqlServer.Management.Smo.Server') "servername"
  $SqlUser = New-Object -TypeName Microsoft.SqlServer.Management.Smo.Login -ArgumentList $SqlServer, "$Username"
  $SqlUser.LoginType = 'WindowsUser'
  
  $SqlUser.Create()
  </code></pre>
  
  <p>Getting Exception as follows:</p>
  
  <pre class="lang-none prettyprint-override"><code>Exception calling "Create" with "0" argument(s): "Create failed for Login 'test-usr'. "
  At line:7 char:1
  + $SqlUser.Create()
  + ~~~~~~~~~~~~~~~~~
      + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
      + FullyQualifiedErrorId : FailedOperationException
  </code></pre>
  
  <p>Does it require any special permission or any DLL to load?</p>