XRM Tooling connection from GUI

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
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 1 year and 3 months 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.
Locked
rbutterworth
Posts: 6
Last visit: Thu Oct 05, 2023 8:13 am

XRM Tooling connection from GUI

Post by rbutterworth »

I'm automating some tasks in Dynamics CRM using a simple Windows Forms app, but when I connect to the CRM system the Initialization step of the command just hangs, per the attached. This works at the command line - anyone know what is going on?

$cred = Get-Credential -Message 'Please enter your email address and CRM password'
$conn = Get-CrmConnection -serverurl <CRM URL> -OrganizationName AmadeusCapital -Credential $cred
Attachments
ScriptDriver64_CvvD70sdRF.png
ScriptDriver64_CvvD70sdRF.png (2.77 KiB) Viewed 626 times
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: XRM Tooling connection from GUI

Post by jvierra »

This is an issue with many service type connections from WinForms in PowerShell. The thread that executes the form is blocked so the connection attempt will hang. Try making the connection before you call the form. In most cases this works. I have not used the CRM module so I can't say if this module has the same behavior. It likely does as MS has focused for the last few years on creating a common connection API at least for cloud services.

You may be able to create a global connection for the Windows session so all programs will be pre-authenticated. This likely will require MFA.

Use a WinForms project and connect in "startup.pss" in the "Main" function before the form is called.
rbutterworth
Posts: 6
Last visit: Thu Oct 05, 2023 8:13 am

Re: XRM Tooling connection from GUI

Post by rbutterworth »

Thanks - that worked. Had to re-arrange the code as it was just a script, but all working now.
This topic is 1 year and 3 months 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.
Locked