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 4 years and 7 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.
I'm having always the same problem in Powershell Studio and i have tried a lot of things and i can't resolve this problem. I have check a lot of articles on google and nothing works You are my last hope
My problem is simple and happen in many exemples, i can't use my variables in commands like in Powershell ISE ! And i'm sure it's an easy mistake from me but i do not understand.
On powershell Studio i got nothing. $ADusers is empty and i think it's because my $getMembers is not transformed with her value "connor" in the command. But i maybe made a mistake about that. Maybe a full part of the command is not interpreted but i don't see why.
Can you help me ?
Thanks
Last edited by AMIGA1200 on Wed Aug 21, 2019 5:41 am, edited 1 time in total.
"Help me Obi Wan Kenobi ..."
You didn't post all your code, so its a bit of a guess, but these cases are *usually* caused by using variables out of scope.
It is interesting to note that you use $script:getMembers everywhere BUT in your query, where you use the default (local scope) $getMembers
If you use a scope modifier for a variable, do it ALWAYS, in each instance. Or do it never so you always use the local scope.
Using the ISE to judge anything is usually ... well, a difficult proposition at least.
Your local $getMembers my have the desired content in the ISE, but you never know if it is from this instance running a script or from 10 minutes ago toying with it on the command line.
The ISE has what is called "Runspace contamination" because it never resets the runspace (unless YOU do that), whereas PowerShell Studio and PrimalScript create a new runspace for each time you run a script.
We do that so that blaring omissions like uninitialized variables or out-of-scope use become immediately apparent and you don't suffer from "But it works on my machine" syndrome.
This topic is 4 years and 7 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.