Automation

 View Only
Expand all | Collapse all

PowerCLI - New-TAG hangs in a script

  • 1.  PowerCLI - New-TAG hangs in a script

    Posted Jan 07, 2018 10:02 PM

    Hi,

     

    I a creating a script that needs to do  the following thing. 

    I us Sapien Powershell 2017 Editor for this because it has a form with info on it

    check if a TAG exists (GET-TAG)

     $TagInfo = Get-Tag -Name $paramClassName .  

    This works perfect.  I get the info of the TAG if it exists and a $null if the TAG does not exist.

    if the TAG does not exist, creat it.

    $MyClassTAG = Get-TagCategory -name "Class" | New-Tag -name $paramClassName  -Verbose -Debug -Confirm:$false

    The TAG is created but the script does not continue, it stays in the NEW-TAG cmdlet...

    with the VERBOSE option I get following output

    VERBOSE: 07/01/2018 22:43:01 New-Tag Started execution
    VERBOSE: Create tag 'ECCS-Classroom-GERTGERT-1' in category 'Class'
    VERBOSE: 07/01/2018 22:43:01 New-Tag Started execution
    VERBOSE: Create tag 'MyTAG' in category 'Class'

     

    The next command, writing a sttus update in a text filed is never executed.    if I comment out the NEW-TAG command line, the status is written correctly

     

    Working with lates vCenter 6.5  and ESXi, on a windows 10 machine with latest PowerCLI modules installed.

    PowerCLI Version                                                       

    ----------------                                                       

       VMware PowerCLI 6.5.1 build 5377412                                 

    ---------------                                                        

    Component Versions                                                     

    ---------------                                                        

       VMware Cis Core PowerCLI Component 6.5 build 6983166                

       VMware VimAutomation Core PowerCLI Component 6.5 build 6234650      

     

    Can someone tell me what I am doing wrong?

     

    Thanks

     

    Gert



  • 2.  RE: PowerCLI - New-TAG hangs in a script

    Posted Jan 07, 2018 10:08 PM

    By the way

     

    When I just open a powershell screen, connect to the vCenter, and execute following line

    Get-TagCategory "Class"| new-tag -name "gert"

    This works perfectly.

     

    Help this makes me crazy.

     

    Gert

     
    Get-TagCategory "Class"| new-tag -name "gert"


  • 3.  RE: PowerCLI - New-TAG hangs in a script

    Posted Jan 08, 2018 05:34 AM

    Since this seems to work from a plain PS session, I would rather suspect an issue in the Sapien app.

    Did you check the forums over there?



  • 4.  RE: PowerCLI - New-TAG hangs in a script

    Posted Jan 08, 2018 06:14 PM

    Hi Luc,

    I have not found anything on the SAPIEN. posted the question there.

    Weird, if I run the powershell script outside sapien (the form project) then the script hangs on the same funtion.

    gert



  • 5.  RE: PowerCLI - New-TAG hangs in a script

    Posted Jan 08, 2018 06:32 PM

    It hangs as well?

    I thought you said earlier that it works outside the Sapien form?



  • 6.  RE: PowerCLI - New-TAG hangs in a script

    Posted Jan 08, 2018 06:36 PM

    Hi LUC

    if I open a powershell window.

         connect manual to the vcenter

         then add manual a tag using the new-tag cmdlet,

    then everything succeeds

    I have a project in SAPIEN, exeuting / debugging this in the SAPIEN posershell program, the new-tag cmdlet does not finish.

    if I run the powershell script created in sapien, from a powershell window (no SAPIEN IDE) the cmdlet does not finish..

    Gert



  • 7.  RE: PowerCLI - New-TAG hangs in a script

    Posted Jan 08, 2018 06:37 PM

    There were some Tag related issues in earlier PowerCLI builds.

    Some actions that solved those for a number of users

    • make sure to ignore certificate warnings (Set-PowerCLIConfiguration)
    • connect to the vCenter with the FQDN
    • stop/start your PowerShell session
    • restart the Inventory service
    • restart the VCSA


  • 8.  RE: PowerCLI - New-TAG hangs in a script

    Posted Jan 08, 2018 07:49 PM

    Hi Luc,

    updated the vCenter to the latest version (there is a update released today, rebooted the vCenter server (is an embedded appliance environment)

    executed  set-PowerCLIConfiguration -InvalidCertificationAction Ignore

    rebooted the machine with the SAPIEN app installed.

    still same issue.

    gert



  • 9.  RE: PowerCLI - New-TAG hangs in a script

    Posted Jan 08, 2018 07:52 PM

    Can you share that script generated in Sapien?

    I would like to see if I get the same behaviour in my lab.



  • 10.  RE: PowerCLI - New-TAG hangs in a script

    Posted Jan 08, 2018 08:28 PM

    Hi Luc,

    thanks already for looking in to this.

    Put both files need to be in same folder.

    the properties file can be used to prefill some stuff in the form.

    in the phc file search for lucd

    other comments on the script are welcome as well, first big powershell sript..

    gert



  • 11.  RE: PowerCLI - New-TAG hangs in a script

    Posted Jan 08, 2018 08:52 PM

    Ok, got i running to an extent (I'm obviously missing some of the expected objects).

    How did you create the TagCategory class? Cardinality, EntityType...

    Can you do a Get-TagCategory -Name class

    Are you sure that there is something in the variable $paramClassName when you enter the function CreateClass?

    Perhaps you could some Write-Verbose lines at the start of the function.

    Did you do a run with $verbosePreference = 'Continue' before the run?

    Would be interesting to see the verbose output around the point where the issue is occurring.



  • 12.  RE: PowerCLI - New-TAG hangs in a script

    Posted Jan 08, 2018 09:13 PM

    Hi Luc

    the Class Tag Category

    Cardinality : Single

    EntityType  : {All}

    Id          : urn:vmomi:InventoryServiceCategory:21486efa-028b-4589-a835-c4561275d70a:GLOBAL

    Name        : Class

    Uid         : /VIServer=vsphere.local\administrator@192.168.3.3:443/TagCategory=urn:vmomi:InventoryServiceCategory:2148

                  6efa-028b-4589-a835-c4561275d70a:GLOBAL/

    Client      : VMware.VimAutomation.ViCore.Impl.V1.VimClient

    the parameter $paramClassName as the correct value.

    The tag is created in the class category.

    verbose output

    VERBOSE: Start monitoring

    VERBOSE: 08/01/2018 22:19:45 Get-Tag Started execution

    VERBOSE: 08/01/2018 22:19:45 Get-Tag Finished execution

    ERROR: Get-Tag : 08/01/2018 22:19:45 Get-Tag Tag with name 'ECCS-CLASSROOM-1234-GERT-1' was not found using the specified filter(s).

    Globals.ps1 (370, 13): ERROR: At Line: 370 char: 13

    ERROR: +         $TagInfo = Get-Tag -Name $paramClassName

    ERROR: +                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    ERROR:     + CategoryInfo          : ObjectNotFound: (:) [Get-Tag], VimException

    ERROR:     + FullyQualifiedErrorId : Core_OutputHelper_WriteNotFoundError,VMware.VimAutomation.ViCore.Cmdlets.Commands.Tagging.GetTag

    ERROR:

    VERBOSE: 08/01/2018 22:19:45 Get-TagCategory Started execution

    VERBOSE: 08/01/2018 22:19:45 New-Tag Started execution

    VERBOSE: Create tag 'ECCS-CLASSROOM-1234-GERT-1' in category 'Class'

    and there stops the script.   The get-tag dilivers an error because I do a test to see if it exists.

    gert



  • 13.  RE: PowerCLI - New-TAG hangs in a script

    Posted Jan 09, 2018 05:56 AM

    Ok, at least that confirms that the New-Tag cmdlet seems to be hanging.

    No clue what is happening here I'm afraid.

    One final action you could take, before opening a SR on this.

    Try to uninstall/install PowerCLI, or even better, try to run the script from another station that has PowerCLI freshly installed.



  • 14.  RE: PowerCLI - New-TAG hangs in a script

    Posted Jan 10, 2018 07:21 PM

    Hi Luc,

     

    tried it on another machine with same result.

    also on a new W10 machine fresh installed I have the same issue...

    will open a SR

    gert



  • 15.  RE: PowerCLI - New-TAG hangs in a script

    Posted Jan 10, 2018 07:23 PM

    In parallel you could have a go at the rCIsTag module.

    It uses the REST API.