Trial #13: Why is Write-Verbose not Doing Anything?
Problem:
I made a script with some functions in it and the built in PowerShell verbose switch is doing absolutely nothing.
./MyScript.ps1 -verbose #I'm having to revert to write host to have a clue what is happening!
Solution:
Give PowerShell a chance - it’s made it pretty easy for you - just put cmdletbinding attribute above your parameters in any given script.
[cmdletbinding()]
param()
Powershell will then give you some free common parameters including -verbose.
- Debug (db)
- ErrorAction (ea)
- ErrorVariable (ev)
- InformationAction
- InformationVariable
- OutVariable (ov)
- OutBuffer (ob)
- PipelineVariable (pv)
- Verbose (vb)
- WarningAction (wa)
- WarningVariable (wv)
Thanks to Ed Wilson, Microsoft Scripting Guy, for providing a solution to my problem and leading me into this interesting topic in his post.
There is a lot more you can do with the Parameter Binding Attribute
Pitfalls
- This is just a rare good thing
Leave a comment