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

Support for all customers who have purchased a SAPIEN PowerShell Studio product license. This forum does not offer a response time guarantee.
Forum rules
DO NOT POST SUBSCRIPTION NUMBERS, LICENSE 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.
User avatar
davidc
Posts: 5006
Joined: Thu Aug 18, 2011 4:56 am

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

Post by davidc » Tue Jan 09, 2018 11: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.
David
SAPIEN Technologies, Inc.

User avatar
jstedler
Posts: 14
Joined: Sun Mar 03, 2013 12:40 pm

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

Post by jstedler » Fri Jan 12, 2018 11:49 am

davidc wrote:
Tue Jan 09, 2018 11: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: 5006
Joined: Thu Aug 18, 2011 4:56 am

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

Post by davidc » Fri Jan 12, 2018 12:40 pm

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.