I have several questions about Lab 5.6 in Learning Powershell in a Month of Lunches. The book gives a function that doesn’t work because of a scope issue. The solution that is given to solve it, is to make the scope global when creating the PSDrives. Yet, in the chapter, it says “We get particularly irritated when we see people writing scripts that dump things into some $global:variable in order to pass information from one function to another.” Seems to be contradictory.
Also, twice now, I’ve noticed that the book says when the function ends, the variables are no longer available. That is not true on my system. In the lab that we’re discussing, for instance, I can access the Appdata: and Temp: drives. Wondering what’s different about my system that I can access the drives after the script ends.
PSDrives and Variables are two different things. PSDrives are essentially always global. I don’t have the book in front of me to know what you’re referring to when you say “The book gives a function that doesn’t work because of a scope issue. The solution that is given to solve it, is to make the scope global when creating the PSDrives”, and the attachment would need to be renamed from .ps1 to .txt.