title: How to reference a property from another command?
body: <p>So im trying to setup a script for unlocking users accounts.</p>
  <p>Right now this is what i have:</p>
  <pre><code>function unlocktm
  
  {
  $user = read-host &quot;Who is the user?&quot;
  
  Unlock-ADAccount -Identity $user -Credential adminaccount
  
  Write-host &quot;Account for $user has been unlocked!&quot;
  }
  </code></pre>
  <p>now here is the difficult part, our users usernames are based off their email. and we switched email formats like last year. So some peoples emails are jdoe@company.com and others are john.doe@company.com</p>
  <p>So when that script i have now asks &quot;who is the user?&quot; i have to put in and know that users username style (either first.lastname or flastname). Well with 1500 users, i dont exactly know every ones emails off the top of my head.</p>
  <p>So what im trying to do is make it so that when it asks for &quot;who is this user?&quot; i can just put in John Doe, itll run a second script i have setup that can search for that user in AD, pull the attribute and apply it into the first script. Let me explain better. For the time being i have a second script that is this:</p>
  <pre><code>function findtm
  
  {
  $Firstname = Read-Host &quot;What is the users Firstname?&quot;
  $Lastname = Read-Host &quot;What is the Users Lastname?&quot;
  Get-ADUser -Filter &quot;Surname -like '$Lastname*' -and GivenName -like '$Firstname*'&quot;
  }
  </code></pre>
  <p>and that pulls the info about that user and shows me what their email style is. That email style is under the &quot;samaccountname&quot;.</p>
  <p>So ultimately, what i need it to do is:</p>
  <p>I run the function, it asks me for the user.</p>
  <p>I can just put in &quot;John Doe&quot;</p>
  <p>and it will then run that second script in the background that searches for &quot;John Doe&quot; and then if it finds a John Doe, its grabs the &quot;samaccountname&quot; property (either john.doe or jdoe), attaches that to the answer in replace of the &quot;john doe&quot; and then the script runs the unlockad command for john doe and unlocks his account.</p>
  <p>Im probably over thinking this by a large margin, but i was thinking a If-else could do it but i have no clue how to to set it up to pull that &quot;samaccountname&quot; property.</p>