title: Powershell exist local user ADSI
body: <p>I got the following code (working):</p>
  
  <pre><code>   #Import File
  $Users = Import-Csv C:\Users\Administrator\Desktop\userImport\users.csv
  
  # Setting data
  $compname = hostname
  $computer = [ADSI]"WinNT://$compname" 
  $userGroup = [ADSI]"WinNT://./Users,Group"
  
  # Loop to add all users
  $Users | %  { 
  
      # Create user itself
      $createUser = $computer.Create("User",$_.userid)
  
      # Set password (print1!)
      $createUser.SetPassword($_.password)
      $createUser.SetInfo()
  
      # Create extra data
      $createUser.Description = "Import via powershell"
      $createUser.FullName = $_.'full name'
      $createUser.SetInfo()
  
      # Set standard flags (Password expire / Password change / Account disabled)
      $createUser.UserFlags = 64 + 65536 # ADS_UF_PASSWD_CANT_CHANGE + ADS_UF_DONT_EXPIRE_PASSWD
      $createUser.SetInfo()
  
      # Adduser to standard user group ("SERVER02\Users")
      $userGroup.Add($createUser.Path)
  
      # Show that user X as been added
      $username = $_.'full name'
      echo "User  $username added"
  }
  </code></pre>
  
  <p>But how is possible to build an check if the user already exists?
  I can not really find anything on the web :x</p>