Skip to content

Stop using Write-Information in auto-generated PowerShell code, please! #371

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
3 tasks
KirkMunro opened this issue Sep 14, 2020 · 1 comment
Closed
3 tasks

Comments

@KirkMunro
Copy link

KirkMunro commented Sep 14, 2020

Today the auto-generated code that the Microsoft.Graph bundle of modules is comprised of uses Write-Information very liberally to output additional information to the caller. This is a bad design decision because Write-Information is handled differently than other information streams ([related: PowerShell/PowerShell/issues/13631). When you invoke PowerShell programmatically using the SDK, information records will always be output to the information stream in PowerShell 7.0.3 and earlier as well as in Windows PowerShell 5.1 and earlier. The end result is information stream content showing up by default in scripts run through a platform or service that runs PowerShell scripts, unless the platform is smart enough to work around the issue with information stream handling at the SDK level (but that workaround should not be necessary!).

Even putting that SDK issue aside, the Information stream is a bad choice for what you are trying to do.

The Verbose stream is used to deliver information about command processing that is meant to be helpful to a scripter that is debugging/troubleshooting a command that they are using.

The Debug stream is used to deliver information about command processing that is meant to be helpful to the command author that is debugging/troubleshooting a command that they have written.

The Information stream is a newer stream, intended to support the transmit of structured data between a script and its callers (or hosting environment).

You are clearly using the Information stream as if it was the Verbose stream today.

Further, the last message you output from each of your modules does not add any value. For example, you have the following in your Microsoft.Graph.Users.User.psm1 file at the end:

Write-Information "Loaded Module '$($instance.Name)'"

This message does not provide me as a user any additional information that will help me debug or troubleshoot a command. It appears at the end, after the import of the module has finished, at which point I already know if the command was successful or not based on the presence of warnings or errors.

My request to you to clean this up is threefold:

  • Replace all use of Write-Information with Write-Verbose in your auto-generated PowerShell code.
  • Remove the "Loaded Module '$($instance.Name)'" message from the bottom of your psm1 files as it is not helpful or necessary.
  • Reconsider other places where you use Write-Verbose, and only keep those messages if they will actually help a scripter diagnose or troubleshoot an issue when a Graph module is not loading as expected.

AB#7391

@peombwa
Copy link
Member

peombwa commented Dec 2, 2021

This got fixed in 1.8.0.

@peombwa peombwa closed this as completed Dec 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants