New-TagAssignment works in .ps1, but not in .psf...

This forum can be browsed by the general public. Posting is limited to current SAPIEN license holders with active maintenance and does not offer a response time guarantee.
Forum rules
DO NOT POST LICENSE NUMBERS, ACTIVATION KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM.
Only the original author and our tech personnel can reply to a topic that is created in this forum. If you find a topic that relates to an issue you are having, please create a new topic and reference the other in your post.

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 6 years and 2 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.
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

Re: New-TagAssignment works in .ps1, but not in .psf...

Post by davidc »

As I mentioned previously, some cmdlets depend on eventing or asynchronous calls that will not work when a GUI in displayed in PowerShell. To get around this limitation, tru using the Button - Start Job to replace the current button_Go. Run the whole script portion of the click event using the Job Tracker from the control set.

Note: You will have to include the function declaration in the job script block since it runs in an isolated runspace / scope.
David
SAPIEN Technologies, Inc.
User avatar
jstedler
Posts: 17
Last visit: Tue Jan 31, 2023 10:46 am

Re: New-TagAssignment works in .ps1, but not in .psf...

Post by jstedler »

davidc wrote: Tue Jan 09, 2018 10:00 am As I mentioned previously, some cmdlets depend on eventing or asynchronous calls that will not work when a GUI in displayed in PowerShell. To get around this limitation, tru using the Button - Start Job to replace the current button_Go. Run the whole script portion of the click event using the Job Tracker from the control set.

Note: You will have to include the function declaration in the job script block since it runs in an isolated runspace / scope.
Hey David,

It's taken me a little bit, but I've finally got this working. I followed the 'Button-Start Job' link you provided earlier but it turned out to be far more than I needed. Not a bad thing, but I was/am really put off by adding a TON of code that I don't necessarily need to accomplish want I need to do. The positive thing though is that your suggestion got me introduced to "Timers" and how they work with "Jobs". So without all the extra code, I was able to simply add a "Timer" control to my form, used a normal Button control to kick the script off, and created a job to execute the Tag portion of code utilizing the Timer I added. Voila it works!

It still seems to me (I could be wrong) that this behavior points to either a bug or unintended interaction between the Tag cmdlets and powershell scripts utilizing GUI's. The release notes for the previous version of PowerCLI even includes notes that they were fixing other issues with the Tag cmdlets so maybe Vmware will correct this issue as well since many others are having the same issue.

In any case, thanks for your suggestion! Take care.
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

Re: New-TagAssignment works in .ps1, but not in .psf...

Post by davidc »

I'm glad you were able to resolve the issue. There are some gotchas and limitations when it comes to GUIs in PowerShell, but once you are aware of them, you can usually work around it.
David
SAPIEN Technologies, Inc.
This topic is 6 years and 2 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.