Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Powershell Script Looking For User Account

$
0
0

Hey all, I am desparte for some help and please forgive me I know nothing about Powershell whatsoever. I need to test using Powershell for the existence of a user account in one of 3 domains and I can achieve this with the script below with the username hard coded. However what I need to do is pass a variable from the software that is calling the script and I do not know how to do this.

Here's the basic script that does work across all 3 domains for me

$searcher=[adsisearcher]'(sAMAccountname=UserName)'
# use either forest root or local domain
# the key is to use 'GC' instead of 'LDAP'
$searcher.SearchRoot='GC://dc=forest,dc=domain,dc=com'
$searcher.FindAll() 

Now what I'd like to do is use the variable in place of the UserName portion in line 1 but I understand I need to call the variable first as this will be passed as an argument when the script is called. The variable is{|2793:(usr_adloginname)|} so I need some way to replace UserName with this variable and then finally I need either a 1 or a 0 depending on if the user account is found.

Grateful



Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>