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.

  1. employeeid should abc , xyz only, no other id should taken. , field can blank.
  2. sam account cannot blank
  3. othertelephone cannot blank
  4. preferredlanguage 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

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -