Automation

 View Only
  • 1.  Reposition VM

    Posted Jul 01, 2022 03:33 AM

    I am looking to delete VM that is created and reposition.

     



  • 2.  RE: Reposition VM

    Posted Jul 01, 2022 06:13 AM

    The New-Timespan cmdlet is ideal for comparing two

    dates.
    For example




  • 3.  RE: Reposition VM

    Posted Jul 01, 2022 06:27 AM

    Thank you in advance. 

    As for comparing created dates for each template, what would be the optimal way?



  • 4.  RE: Reposition VM

    Posted Jul 01, 2022 07:09 AM

    I don't think the ChangeVersion will give you the creation date of a Template.

    I would look at the events (provided you keep those long enough on your VCSA).
    Something like this.
    it looks back 1 month and reports all templates older than 20 days.
    Note that the Get-VIEvent cmdlet might take quite a bit of time to complete.

     

     

    This only lists the templates, adding a delete step should be simple



  • 5.  RE: Reposition VM

    Posted Jul 01, 2022 02:18 PM

    Thank you



  • 6.  RE: Reposition VM

    Posted Jul 01, 2022 02:46 PM

    You could use my Get-VIEventPlus function.
    That allows specifying the entity and  eventype, meaning that the filtering already happens on the VCSA vs returning all events to the script.
    Retrieving the events would be like this (and should be a lot faster)

     



  • 7.  RE: Reposition VM

    Posted Jul 01, 2022 03:23 PM

    Question

    1) Does it support operation with 1 cmdlet



  • 8.  RE: Reposition VM

    Posted Jul 01, 2022 03:53 PM

    A word of warning, if the same Template was created for example 30 days ago, then removed, and then recreated 10 days ago, the name of the template will be listed. You will have to check something like the MoRef of the Template to make sure you are removing the correct one.

    1) Not sure I understand the question 100%, but if it is what I think it, you can use a WHer-clause on the Get-Template, and then pass only those on the Entity parameter

    2) See my remark above. 

    Yes, the Remove-Template cmdlet accepts an array of Templates, so you can remove all of them in 1 call to the cmdlet.



  • 9.  RE: Reposition VM

    Posted Jul 01, 2022 05:08 PM

    Thanks!! For deleting, I'd take it you mean to make 1 call to the cmdlet.

     



  • 10.  RE: Reposition VM

    Posted Jul 01, 2022 05:21 PM

    You need to pipe the result to a Where clause that filters on that condition



  • 11.  RE: Reposition VM

    Posted Jul 01, 2022 08:18 PM

    Thank you. I'll look at it. Does output an error.



  • 12.  RE: Reposition VM

    Posted Jul 01, 2022 08:30 PM

    That function also has a Finish parameter.
    What errors do you get?



  • 13.  RE: Reposition VM

    Posted Jul 01, 2022 08:55 PM

    I got it to work. Thanks. What do you mean to pipe it out?



  • 14.  RE: Reposition VM

    Posted Jul 01, 2022 09:20 PM

    You could do