title: Powershell issue with a defined variable
body: <p>I am pretty new to powershell and have a code that I found. I had it working but now it is no longer working. I didn't change anything with the variable so I am not sure what is going on. Here is a link to a Screenshot of the code and error. Please let me know if you need any other information</p>
  <p><a href="https://imgur.com/a/ntEhdoV" rel="nofollow noreferrer">https://imgur.com/a/ntEhdoV</a></p>
  <p>Thank you!</p>
  <pre class="lang-bsh prettyprint-override"><code>Import-Module activedirectory
   
  $ADUsers = Import-csv 'C:\Users\Desktop\Powershell files\EM-mis-new-AD.csv'
  
  foreach ($User in $ADUsers)
  {
      $Username   = $User.username
      $Password   = $User.password
      $Firstname  = $User.firstname
      $Lastname   = $User.lastname
      $OU         = $User.ou 
      $Password   = $User.Password
      
      if (Get-ADUser -F {SamAccountName -eq $Username})
      {
           Write-Warning &quot;A user account with username $Username already exist in Active Directory.&quot;
      }
      else
      {
          New-ADUser `
              -SamAccountName $Username `
              -UserPrincipalName &quot;$Username@Mydomain&quot; `
              -Name &quot;$Firstname $Lastname&quot; `
              -GivenName $Firstname `
              -Surname $Lastname `
              -Enabled $True `
              -DisplayName &quot;$Firstname, $Lastname&quot; `
              -Path $OU `
              -AccountPassword (convertto-securestring $Password -AsPlainText -Force) -ChangePasswordAtLogon $True
      }
  }
  </code></pre>
  <p>Error:</p>
  <pre><code>Get-ADUser : Variable: 'Username' found in expression: $Username is not defined.
  At C:\Users\jcarnovale\Desktop\Testing if.ps1:22 char:6
      if (Get-ADUser -F {SamAccountName -eq $Username})
          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      CategoryInfo          : InvalidArgument: (:) [Get-ADUser], ArgumentException
      FullyQualifiedErrorId : ActiveDirectoryCmdlet:System.ArgumentException,Microsoft.ActiveDirectory.Management.Commands.GetADUse
  </code></pre>