Giter VIP home page Giter VIP logo

Comments (4)

Disassembler0 avatar Disassembler0 commented on July 25, 2024 1

Even if it may not show, this is not my first PowerShell rodeo, so I'm aware about the contents of the linked article. I thought about which Write- to use before. The topic is still open for discussion, but consider these:

  • First and foremost, it should be possible to use the script with the least effort possible. Since it's being used by unskilled BFUs for which even right-clicking and selecting Run in PowerShell is a complex task, Write-Verbose would either require manually entering the command or using $VerbosePreference = "Continue". Moreover all messages are prepended by "VERBOSE: " string. This may be matter of personal preference, but I personally don't like it.
  • It should be also possible to use the script as a base for provisioning automation and incorporate the functions into another PS script. Possible candidate would then be Write-Output but since the messages are intended to be informational for the user, redirecting such script to a log would eat them too. I'm aware about Tee-Object cmdlet but that doesn't help if the whole process output gets redirected. This again is a matter of personal preference, whether to "force" the information to show or whether to leave the decision on the downstream maintainer.

So I needed a Write- which would not be redirected but at the same time which would be always visible without any extraneous information or setting. Hence I got stuck with Write-Host.

What would your preference be and why?

from win10-initial-setup-script.

swedishstyle avatar swedishstyle commented on July 25, 2024 1

My apologies, I never meant to call into question your Powershell knowledge - you clearly know your stuff!

I only decided to bring this up as a best practices type of deal, but it seems you've clearly thought hard about the consequences of each possibility. From your explanations, I'd tend to agree with your choice of Write-Host in this case, although I've only been using Powershell for about 1 year now, so my opinion may not be 100% valid :)

I've switched my copy of the script with Write-Output for my own consistency and fixed the WaitForKey issue, but for complete novice users, Write-Host will do the trick just fine.

Thank you for keeping this up to date and writing it in the first place - it's incredibly useful!

from win10-initial-setup-script.

BlackDragonBE avatar BlackDragonBE commented on July 25, 2024

Just to chime in, I replaced all the Write stuff with Write-Output and it breaks the script, it just keeps asking for parameters now. Clearly it isn't just a case of find-replace.

from win10-initial-setup-script.

Disassembler0 avatar Disassembler0 commented on July 25, 2024

Just to chime in, I replaced all the Write stuff with Write-Output and it breaks the script, it just keeps asking for parameters now. Clearly it isn't just a case of find-replace.

That's just the Write-Host without parameter in WaitForKey function. It can't handle colors either. Can be replaced with

Function WaitForKey {
	Write-Output "`nPress any key to continue..."
	[Console]::ReadKey($true) | Out-Null
}

(Although this particular function won't be used in automation anyway due to the key press)

from win10-initial-setup-script.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.