powershell - Logical condition not working -
i need powershell
i need script in logical comparison using csv: samaccountname
,othertelephone
,employeeid
,preferredlanguage
have developed script update ad user details based on condition.
employeeid
should abc , xyz only, no other id should taken. , field can blank.- sam account cannot blank
othertelephone
cannot blankpreferredlanguage
should en|es only.no other parameter should taken , field can blank.
script update user if above conditions met.
i stuck @ point 1, not ignoring blank field. if leave blank executes code block.
if($_.employeeid -notmatch 'abc|xyz' or $_employeeid.trim() -eq "") { write-output " id not proper" }
you don't need -or , condition test. add qualifier in regex:
$_.employeeid -notmatch '^(abc|xyz|\s*)$'
that test whitespace or null string, in addition abc , xyz values.
edit: if abc , xyz value tests need unbounded (they can appear anywhere in attribute value), isolate begin , end anchors null/whitespace test:
$_.employeeid -notmatch 'abc|xyz|^\s*$'
Comments
Post a Comment