Problem running code from chapter 12 in PS Scripting in a month

First, I apologize if this is the wrong location for this question! I wasn’t sure which forum was correct.

I’m in a book group at work doing Powershell Scripting in a Month of Lunches. We were doing the last bit in chapter 12 (12.6.1. “Start Here” liveBook · Manning)

And we could only get that code to run using except in the ISE with dot sourcing. It wouldn’t run at all in a regular PS shell.

Any thoughts as to why this would be so? Is it expected behavior from that sample code?

Thanks!

Adam

The code you see there is a function. you have to put it into a text file and save it with .ps1 extension, which makes it a PowerShell script. Then dot source it in any PowerShell console and use it. PowerShell ISE is basically meant for developing.

When you use ISE you can define the function using play button(F5) and can be used in the same session. You can even do similar buy copy pasting the whole function in to a normal PowerShell console to use it without dot sourcing.

Hey Adam! This is the place for questions, however, some more details would help us help your group. It appears you are referring to the function Set-TMServiceLogon. There is nothing in that code that should run in ISE vs a standard host that I can see, so if you could provide details on what exactly is not working, errors, etc. would help. I can tell you if I paste the code into a Powershell host, hit enter to load it into memory, it is executing for me.