title: powershell, Variable: '_' found in expression: $_
body: <p>I am fairly new to powershell and I am currently employing it to work around a few administration tasks for the Helpdesk.</p>
  
  <p>I have a problem with trying to move an AD object (forgive me if the following terminology is used incorrectly) based on the property of on object from an imported CSV. </p>
  
  <p>The CSV is:
  UserPrincipalname,UserToAccess,DaysToLive</p>
  
  <p>joe@company.com,dave@company.com,90</p>
  
  <p>and so on...</p>
  
  <p>I then pass the array through a ForEach loop to move the AD account:</p>
  
  <pre><code>foreach ($line in $import) {Get-ADUser -filter {userPrincipalName -eq $_.UserToAccess} -SearchBase "DistinguishedName of OU" | Move-ADObject -TargetPath 'DistinguishedName of OU'}
  </code></pre>
  
  <p>Subsequently I am getting the following error:</p>
  
  <blockquote>
    <p>Get-ADUser : Variable: '<em>' found in expression: $</em>.UserToAccess is not
    defined. At D:\jason\EnableArchiveAccess.ps1:17 char:29
    + foreach ($line in $import) {Get-ADUser -filter {userPrincipalName -eq $<em>.UserToA ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidArgument: (:) [Get-ADUser], ArgumentException
        + FullyQualifiedErrorId : Variable: '</em>' found in expression: $_.UserToAccess is not defined.,Microsoft.ActiveDirec<br>
    tory.Management.Commands.GetADUser</p>
  </blockquote>
  
  <p>I have been able to use the above logic to unhide users from the GAL and I have checked the array and the properties are there as noteproperties.</p>
  
  <p>I assume it's because I am using not AD variables in the command but any help would be much appreciated but if I find the answer sooner I will post back. </p>