Creating Form to Check if AD user exists

Use this forum to ask questions after your subscription maintenance expires or before you buy. Need information on licensing or pricing? Questions about a trial version? This is the right place for you. No scripting questions, please.
Forum rules
Only the original author and our tech personnel can reply to a topic that is created in this forum. If you find a topic that relates to an issue you are having, please create a new topic and reference the other in your post.
Posts: 1
Last visit: Sun Oct 30, 2022 8:40 pm

Creating Form to Check if AD user exists

Post by kevinsray2022 »

Hi All,
I am new to PSS, but am loving what I see so far.
I have been writing PS1 scripts for several years and all has been nice, but this is a great tool to consolidate a lot of what I have done.

I am trying to create a form where I type in user first and surnames, and it checks if the user exists on Active Directory.
I have many scripts which run natively in PS and work, however, when I try to use them, they don`t see to work correctly.
When using Get-ADUser to see if a user exists, I can`t get PSS to give correct feedback.
Is there something I am missing....
My code looks like this:

if (dsquery user -samid $userID){$label1.Text="Y"}
elseif ($userID = "null") {$label1.Text="N"}

Any pointers would be greatly appreciated.
Posts: 15337
Last visit: Wed Nov 30, 2022 12:48 am
Answers: 27
Has voted: 4 times
Been upvoted: 30 times

Re: Creating Form to Check if AD user exists

Post by jvierra »

  1. if{Get-Aduser -Filter "SamAccountName -eq '$userID'"}(
  2.     $label1.Text = 'Y'
  3. }else{
  4.     $userID = $null
  5.     $label1.Text = 'N'
  6. }
I suggest learning how to use logic in PowerShell. It is the most critical thing to completely understand in PowerShell or in any other computer language.

The following free book (pdf) will help you to understand how logic works and how to use logic statements correctly. ... werShell-4