{"action":"created","issue":{"url":"https://api.github.com/repos/PowerShell/PSScriptAnalyzer/issues/267","labels_url":"https://api.github.com/repos/PowerShell/PSScriptAnalyzer/issues/267/labels{/name}","comments_url":"https://api.github.com/repos/PowerShell/PSScriptAnalyzer/issues/267/comments","events_url":"https://api.github.com/repos/PowerShell/PSScriptAnalyzer/issues/267/events","html_url":"https://github.com/PowerShell/PSScriptAnalyzer/issues/267","id":94424856,"number":267,"title":"Issues with PSAvoidUsingWriteHost","user":{"login":"rkeithhill","id":5177512,"avatar_url":"https://avatars.githubusercontent.com/u/5177512?v=3","gravatar_id":"","url":"https://api.github.com/users/rkeithhill","html_url":"https://github.com/rkeithhill","followers_url":"https://api.github.com/users/rkeithhill/followers","following_url":"https://api.github.com/users/rkeithhill/following{/other_user}","gists_url":"https://api.github.com/users/rkeithhill/gists{/gist_id}","starred_url":"https://api.github.com/users/rkeithhill/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rkeithhill/subscriptions","organizations_url":"https://api.github.com/users/rkeithhill/orgs","repos_url":"https://api.github.com/users/rkeithhill/repos","events_url":"https://api.github.com/users/rkeithhill/events{/privacy}","received_events_url":"https://api.github.com/users/rkeithhill/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2015-07-11T01:49:37Z","updated_at":"2015-08-18T17:50:38Z","closed_at":null,"body":"The message guides folks to use Write-Output but Write-Output has no equivalent of -BackgroundColor/-ForegroundColor/-NoNewLine.  Perhaps this rule shouldn't fire when any of these parameters are present?  However when it does fire, shouldn't it be pointing folks to use Write-Information instead - at least when they are on PowerShell V5?  \r\n\r\nI have helped quite a few folks with PowerShell functions where they were using Write-Output (implicitly) in their function to notify users of what's going on in the function.  Then they were confused by the fact that their function returned a collection instead of the single value they intended.  They're usually even more surprised because they used \"return $result\" and expected that to be the only return value.\r\n\r\nTelling a script analyzer user to use Write-Output instead of Write-Host, significantly changes semantics in a way that could break their script.  Seems like this tool should obey that tenant of the Hippocratic oath - do no harm.  :-)"},"comment":{"url":"https://api.github.com/repos/PowerShell/PSScriptAnalyzer/issues/comments/132294347","html_url":"https://github.com/PowerShell/PSScriptAnalyzer/issues/267#issuecomment-132294347","issue_url":"https://api.github.com/repos/PowerShell/PSScriptAnalyzer/issues/267","id":132294347,"user":{"login":"joeyaiello","id":1255187,"avatar_url":"https://avatars.githubusercontent.com/u/1255187?v=3","gravatar_id":"","url":"https://api.github.com/users/joeyaiello","html_url":"https://github.com/joeyaiello","followers_url":"https://api.github.com/users/joeyaiello/followers","following_url":"https://api.github.com/users/joeyaiello/following{/other_user}","gists_url":"https://api.github.com/users/joeyaiello/gists{/gist_id}","starred_url":"https://api.github.com/users/joeyaiello/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/joeyaiello/subscriptions","organizations_url":"https://api.github.com/users/joeyaiello/orgs","repos_url":"https://api.github.com/users/joeyaiello/repos","events_url":"https://api.github.com/users/joeyaiello/events{/privacy}","received_events_url":"https://api.github.com/users/joeyaiello/received_events","type":"User","site_admin":false},"created_at":"2015-08-18T17:50:38Z","updated_at":"2015-08-18T17:50:38Z","body":"We will discuss further in the meeting today, but I'd still like to capture my baseline thoughts:\r\n\r\nWrite-Host *can* be okay to use, but only in specific instances where are you very deliberately trying to build a UI of some kind, and can have a reasonable expectation of the host in which PowerShell is executing. For instance, PSReadline employs colored syntax highlighting as a feature of the module, but it can do some wonky stuff in the ISE (which is why we didn't enable it by default there in Windows 10). In these cases, global rule suppression makes the most sense, but it's still an edge case. \r\n\r\nGenerally speaking, scripts and modules should cater to a non-interactive context by default. (Obviously, there are some exceptions to this that use `$ConfirmPreference = High`, but we have `-Force` as a trapdoor to script writers.) We've built a set of functionality for capturing different kinds of outputs to appropriate places (e.g. `Write-Progress` is for long-running tasks without clogging up the pipeline, `Write-Error` will populate the error records, `Write-Verbose` only shows up when the user asks for it, etc., or you should be emitting a structured object to the pipeline) Therefore, the guidance that Write-Host should always be replaced by Write-Output is wrong because there's more nuance than that. It's not just that `Write-Host` shouldn't be used, but that string output should be used in different ways depending on the scenario.\r\n\r\nI'm not exactly sure how to tackle that through our existing rules, but we should talk about it today. "}}