$conn variable in global - can we make that optional? #541
Replies: 1 comment 1 reply
-
|
@evilclivegit That approach probably isn’t necessary today. PowerShell now offers cleaner ways to manage state, and relying on a global variable can cause name collisions with other code (if that code happened to use $conn and wasn't used for a connection to a dataverse environment). You can use your own connection variables and pass them into cmdlets, or even maintain multiple connections side by side to handle parallel connections and also the module itself wouldn't use the global variable (since you'd be passing it in via the -conn parameter): $connection1 = Connect-CrmOnline ... This approach avoids relying on the global variable and keeps your session state explicit - unfortunately, I don't think the cmdlets can determine if the user is assigning the output or not so it's not as simple as assuming it's assigned and detecting if it should fall back to a global. It's possible it could be re-written (though it could potentially break anything existing) also, this module isn't going to work in environments like powershell 7 and is limited by Crm Service Util which has since been replaced. If someone had bandwidth to take a run at modernizing while preserving backwards compatibility w/ the new libraries, it could continue to move on but there are some pretty big hurdles to that and may not be feasible. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
The use of $global:conn raises a few eyebrows for me for a couple of reasons - first, it's a global variable, which just seems a bit odd for module, and second, it's a variable name which could easily clash with other pieces of code. Do we need the global variable, and if we do, can it be made somewhat more unique to this?
(Is this bit based on code provided by MS? )
Beta Was this translation helpful? Give feedback.
All reactions