Ask your PowerShell-related questions, including questions on cmdlet development!
Forum rules Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 5 years and 2 days old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
I am looking for some assistance using the Start-Job cmdlet. I am trying to run a background job to query some data from my Exchange environment. I need to build the connection to Exchange first, I currently use the following code to do so...
This code will not work inside the scriptblock for Start-Job since it's a different thread and will not allow me to interact with it. What methods could I look at to go about connecting to my Exchange environment so I can query data inside the Start-Job scriptblock?
jvierra wrote: ↑Thu Apr 11, 2019 1:12 pm
You would have to run all of your code as a job. Why use a job? The connection only takes 10 seconds even on a slow computer.
Your scriptblock is also not written correctly which may cause many weird issues.
I'm aware that the connection runs rather quickly, that is not the part I am worried about, and it is not written incorrectly, I run it a dozen times a day, you may chose to modify it, but it runs with the desired result as per my configuration requires.
I am trying to query large amounts of data in my Exchange environment, that is the code I use to build the connection from my local PC, I can't just run the Exchange cmdlet's in the Start-Job script block because the Exchange module needs to be loaded, which gets pulled down upon making the connection. My issue is, I can't just run the connection code I posted above in the Start-Job script block because I need it to prompt for my credentials so I can enter them. So I am trying to figure out the best approach to this here, which is the help I am asking for.
Ok, thanks for the help on that one. I actually prompt the user for their credentials at the start of my program. Is there any way I could take those credentials already entered and just pass them through here? In your example above, the user is prompted. It wouldn't scale very well if I had to make the user enter their credentials every time I try to run a job.
You do not need to use the credential in the job if the job is running with the correct credential. You don't need to specify the authentication as that will be automatic.
This topic is 5 years and 2 days old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.