How do I put a boolean result into a variable in Powershell? -
if i've got variable $count number in it, there one-liner set variable either true or false depending on whether $count = 1?
i thought that
$result = ($count -eq 1)
would it, end value of "1" or null stored in (depending on whether it's 1 or not).
any idea i'm doing wrong?
edit: mistake - didn't have "1" in variable. had arraylist looked number 1. closing this.
full code:
get-acl c:\windows\system32\drivers\etc | select -expand access | {$_.identityreference -eq "someacl"} | measure | select -expand count -outvariable aclcount $aclfound = ($aclcount –eq 1) $todaydate = get-date -format "dd/mm/yyyy hh:mm:ss" add-content f:\myfile.log "$todaydate $aclfound "
fixed putting [0] after $aclcount on line 2. (obviously acl in there 1 checking for)
you can use if/then/else it.
if($count -eq 1){$result = $true}else{$result = $false}
Comments
Post a Comment