question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Redirection is treated as PSPossibleIncorrectUsageOfRedirectionOperator

See original GitHub issue

Before submitting a bug report:

  • Make sure you are able to repro it on the latest released version
  • Perform a quick search for existing issues to check if this bug has already been reported

Steps to reproduce

Line that triggers this message:

if (Get-ScheduledTask -TaskName $name 2>$null)

Expected behavior

No errors

Actual behavior

PSPossibleIncorrectUsageOfRedirecti Warning      Tasks.ps1  64    Did you mean to use the redirection operator '>'? The
onOperator                                                        comparison operators in PowerShell are '-gt' (greater than)
                                                                  or '-ge' (greater or equal).

If an unexpected error was thrown then please report the full error details using e.g. $error[0] | Select-Object *

Environment data

> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      5.1.19041.2364
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.19041.2364
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

> (Get-Module -ListAvailable PSScriptAnalyzer).Version | ForEach-Object { $_.ToString() }

1.21.0

Issue Analytics

  • State:closed
  • Created 9 months ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
bergmeistercommented, Feb 1, 2023

Why do you expect no errors? The whole point of the rule is to warn around possible unintentional usage of redirect operator (often the user meant to use -gt operator) in an if statement. Therefore if you know that this is what you want, then you are meant to suppress it, this way you can also document the rev of the warn in code. The only thing we could try and see if we can do is whether we can detect that a specific stream redirection is happening like in this case because it’s more about in that case that the user did it deliberately.

0reactions
cj-wongcommented, Feb 26, 2023

I’ve discovered a better way to handle error messages (-ErrorAction SilentlyContinue), so I’m closing this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Redirects and Google Search
Redirecting URLs is the practice of resolving an existing URL to a different one, effectively telling your visitors and Google Search that a...
Read more >
Redirects: How To Use, SEO Impact & Types (301 vs 302)
Redirection is the process of forwarding one URL to a different URL. What is a redirect? A redirect is a way to send...
Read more >
301 Redirects Explained: How They Impact SEO
301 redirects are pretty simple. They're used to redirect one webpage to another. But understanding how they relate to SEO is more complicated....
Read more >
URL Redirects For SEO: A Technical Guide
A URL redirect involves code implemented to a specific URL, or a group of URLs so that the user (or search engine) is...
Read more >
How to Get More Traffic from 301 Redirects
He has always said that redirects to the homepage or non-relevant pages can be treated as soft 404s. That means Google will essentially...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found