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
Post a Comment