Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

String comparison not working when 'Run with Powershell' or as a scheduled task

$
0
0

I've been banging my head against the wall far too long on this, I'm hoping someone can help me spot what's going on.

I have a bit more complex script than what's posted below, but I stripped it down to the bare minimum and can still reproduce the problem on Windows Server 2008 and Windows 7, both x64, both with PS3 installed.

If I copy the code and paste it into a PS console it works fine.  If I call the script from a PS console it works too.  If I right-click the script file and Run with Powershell, or if I run it as a scheduled task, the string comparison fails.  I'm outputting the result to a file so I can easily see and track the results of my testing.  I first thought it was environmental because it was a scheduled task, but now the script is so minimal and the problem exists without the scheduled task or other user, so I'm at a loss to understand why it isn't working.

Here's the code:

$list = @" blah1 blah2"@ -split "`n" $cmd = "`"$($list[-2])`" -eq `"blah1`""

"$cmd`: $(invoke-expression $cmd)" | out-file c:\temp\junk\blah\result4.txt -append

Here's the output of the text file, first with code pasted into the PS console, then right-clicking on the file and select Run with Powershell.  The result is distinctly different:

Thanks in advance for any insight


I hope this post has helped!


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>