powershell - Reading the output of a variable -


alright, i'm writing code mass user creation in active directory. code has automatically create user names well.

import-csv c:\users\myname\desktop\test\test.csv |  % { $firstname = $_.firstname $middleintial = $_.middleintial $lastname = $_.lastname $username = $firstname.substring(0,1).tolower()+$middleintial.tolower()+$lastname.tolower() $testname = (get-aduser $username) if($testname - $error){ write-host $username } } 

what i'm trying verify user name unique before code continues actual creation part.

after running get-aduser, can test value of $? see if last statement executed successfully:

$testname = get-aduser -filter "samaccountname -eq '$username'" if(-not $?){     # no users samaccountname $username found, go ahead } 

Comments

Popular posts from this blog

user interface - how to replace an ongoing process of image capture from another process call over the same ImageLabel in python's GUI TKinter -

javascript - Using jquery append to add option values into a select element not working -

javascript - Restarting Supervisor and effect on FlaskSocketIO -