I have a working Powershell script usersearch.ps1 that searches Active Directory, but it uses read-host to prompt for input. Iam trying to change the script such that I can pass an argument to my the script or leave the argument blank, and have the script prompt me with the $var=read-host line and continue on with the search. If I call usersearch -[string], the script happily searches my AD and returns the correct results. If I leave out the -[string] it blows up with the error below and never runs the else portion of the IF statement which has the $var=read-host prompt.
Was that clear? Help...?
if ($u -ne $null)
$u=read-host "Enter the user's name or logon_id to search for"
$exact=(get-QADUser -SearchRoot Domain.com/Users $searchv).DirectoryEntry.samAccountName
Get-QADUser : Invalid identity
At C:\Tools\usersearch.ps1:13 char:20
+ $exact=(get-QADUser <<<< -SearchRoot Domain.com/Users $searchv).DirectoryEntry.samAccountName
+ CategoryInfo : NotSpecified: (:) [Get-QADUser], Exception
+ FullyQualifiedErrorId : Quest.ActiveRoles.ArsPowerShellSnapIn.Powershell.Cmdlets.GetUserCmdlet