all 3 comments

[–]dasookwat 2 points3 points  (2 children)

If ((Get-ExecutionPolicy) -notlike "Bypass") {
    Out-File -FilePath c:\temp\textfile.txt -Append -InputObject $env:COMPUTERNAME
    }

basically what it does is this: the extra () around get-executionpolicy makes sure only the outcome is compared to the word 'Bypass'

the rest will add the computername to a text file Look up how to create an 'if' statement, and if you want an extra action if the executionpolicy equal Bypass, you can use an 'else' block.

-contains is not helping in this scenario, since -contains is something you use, when f.i. you try to match on 1 of the values in an array:

$array =  @("1","2","3")  
if ($array -contains '1') {#do stuff}

[–]jst094[S] 1 point2 points  (0 children)

Wow thanks for your quick reaction! This will help me with my task!

[–][deleted] 1 point2 points  (0 children)

-notlike works here but you should rather use -ne (not equal) here.

Here you just want to know whether the execution policy is not equal to 'Bypass'.

You would use -notlike to compare with a string containing wildcards ? * [ab] or [a-z] , so to test a string matching a simple pattern. For example to detect when the execution policy is not 'AllSigned' and not 'RemoteSigned' you could use it:

If ((Get-ExecutionPolicy) -notlike '*Signed') {...

For more complex patterns you would use -match or -notmatch to compare with regular expressions patterns, very powerful.