VMware Cloud Community
jstedler5480
Contributor
Contributor
Jump to solution

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

I have a very simple function I've created that creates Tags (if they don't exist), then assigns them to a VM. I created and tested this code in a normal .ps1 file first before porting it over to the Form Project. As stated in the subject, this code works perfectly fine in a .ps1, but if I try to add the exact same code to my Form Project, or even a bare-minimum .psf (with a single button to 'GO'), the script execution hangs/freezes forever when trying to execute the New-TagAssignment statement.

PLEASE NOTE: to test the code, change the Connect-VIServer and $VMname lines to be applicable to your environment.

I'm attaching 2 files to demonstrate what I'm talking about.  The code to do the Tag query and assignment are the same between the two files.  The only difference is one file is a regular .ps1 whereas the other file contains a GUI (.psf). 

  1. Doesn't_Work.psf - This is a very stripped down version of the GUI from my actual project. This file only contains the form and a single "GO" button to execute the code.  Even in this very basic version, the script hangs/freezes forever when trying to execute the New-TagAssignment cmdlet.
  2. Working.ps1 - This is strictly the code without a GUI.  This works perfectly...

After doing a tremendous amount of troubleshooting on my own, contacting Sapien support (the IDE I use for GUI powershell projects - Powershell Studio 2017 5.4.145.0), and massive Googling, I've come to the conclusion that there must be a bug in the cmdlet that is causing the hang/freeze.  There aren't any messages (error or otherwise) displayed; just straight up hangs/freezes forever.

I've seen many people with similar issues like I have (all concerning the "Tag" cmdlets), but I haven't seen any real/working resolution.

Here is the requested version info:

Name                       Value
PSVersion                  5.1.16299.98
PSEdition                  Desktop
PSCompatibleVersions       {1.0, 2.0, 3.0, 4.0...}
BuildVersion               10.0.16299.98
CLRVersion                 4.0.30319.42000
WSManStackVersion          3.0
PSRemotingProtocolVersion  2.3
SerializationVersion       1.1.0.1

ModuleTypeVersionName
Binary6.5.4.6983166VMware.VimAutomation.Cis.Core
Manifest6.5.4.6979861VMware.VimAutomation.Common
Binary6.5.2.6234650VMware.VimAutomation.Core
Manifest1.0.0.5334677VMware.VimAutomation.Sdk

vCenter ServerVersionBuild
**********.prime.cisco.com6.5.05973321
Reply
0 Kudos
1 Solution

Accepted Solutions
jstedler5480
Contributor
Contributor
Jump to solution

I just wanted to follow-up on this post especially since others are having similar problems.

A Sapien support person pointed me to a potential workaround they are suggesting to people having this problem.  The link is here:

https://info.sapien.com/index.php/guis/gui-advanced-tips/powershell-studio-creating-responsive-forms

When I started to play around with this, it wasn't exactly what I was looking for as it added a TON of 'extra' code that is nice if needed, but for what I am wanting, it was extraneous.  However, it did introduce me to the Timer control and how Jobs can be used in conjunction with them.

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.

I hope this helps others.  It's taken me quite a bit to get this working but it does indeed work...

View solution in original post

Reply
0 Kudos
3 Replies
LucD
Leadership
Leadership
Jump to solution

When you use forms in your script, you are of course running in a different environment (additional DLLs loaded).

I have no fix for you issue, but you indeed seem to be not alone in seeing issues when combining forms and Tags.

See for example PowerCLI - New-TAG hangs in a script

As a possible alternative, you could try with the cmdlets in the rCisTag module.

These are based on the REST API, and might not experience the issue.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
jstedler5480
Contributor
Contributor
Jump to solution

I just wanted to follow-up on this post especially since others are having similar problems.

A Sapien support person pointed me to a potential workaround they are suggesting to people having this problem.  The link is here:

https://info.sapien.com/index.php/guis/gui-advanced-tips/powershell-studio-creating-responsive-forms

When I started to play around with this, it wasn't exactly what I was looking for as it added a TON of 'extra' code that is nice if needed, but for what I am wanting, it was extraneous.  However, it did introduce me to the Timer control and how Jobs can be used in conjunction with them.

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.

I hope this helps others.  It's taken me quite a bit to get this working but it does indeed work...

Reply
0 Kudos
JHassig
Contributor
Contributor
Jump to solution

Hello,

​I have your same issue where I use some intricate GUI (not built in Sapien) and I run into the issue with the tags not working - this ONLY started after we upgraded to vCenter 6.5. Can you please advise more details on how you applied the fix?

​My code:

​1. Builds out a # of VM's per the users request (they use checkboxes to identify which servers to build out for a specific foot print)

​2. COnfigures VM's with standard settings, and applies tags.

​Everything blows up with it gets to the tags!

I don't feel like i need the timer due to the fact i'm running the VM Creations as 'tasks' and using the wait-task $vmcreation before running the tagging script.

DO I just need to do a start-job {tagging code here} to move forward?

Reply
0 Kudos