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

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

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -