title: Pass a variable as a switch parameter in Powershell
body: <p>I'm trying to create a powershell script that will grab all Active Directory accounts that are enabled, and inactive for 90 days. The script will prompt the user to choose between querying computer or user accounts. 
  Depending on the choice, it will pass it over to the main command as a variable.</p>
  
  <p>The commands work correctly if I don't pass a variable.</p>
  
  <p>I'm not sure if what I'm trying to do is possible.</p>
  
  <p>Sorry for any bad code formatting. Just starting out.</p>
  
  <pre><code>Clear-Host
  write-host "`nProgram searches for Enabled AD users account that have not logged in for more than 90 days. `nIt searches the entire domain and saves the results to a CSV file on users desktop." "`n"
  
  $choice = Read-host -Prompt " What do you want to search for Computer or Users Accounts`nType 1 for users`nType 2 for Computers`n`nChoice"
  
  $account
  if ($choice -eq 1) {
      $account = UsersOnly
  }
  Elseif ($choice -eq 2) {
      $account = ComputersOnly
  }
  Else {
      write-host "This is not an option `n exiting program"
      exit
  }
  
  $FileName = Read-Host -Prompt "What do you want to name the CSV file"
  $folderPath = "$env:USERPROFILE\Desktop\$FileName.csv"
  
  Search-ADAccount -AccountInactive -TimeSpan 90 -$account | Where-Object { $_.Enabled -eq $true } | select Name, UserPrincipalName, DistinguishedName | Export-Csv -Path $folderPath
  </code></pre>