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
DO NOT POST SUBSCRIPTION NUMBERS, LICENSE KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM.
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.
This topic is 1 year and 5 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
kevinsray2022
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.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 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.

https://www.sapien.com/books_training/W ... werShell-4
This topic is 1 year and 5 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.