Automation

 View Only
  • 1.  Changing the Custom Attributes Notes field for guests

    Posted Jan 21, 2010 01:38 PM

    Folks,

    I need a way via Powershell (I know I could probably do it via SQL, but I like to avoid editing the VC DB directly) to go through a cluster of hosts and be able to modify any guest VM that has a custom attribute set in the Notes field. Our issue is that we use Platespin for all of our P2V's and it places this long text string after every conversion in the Notes field:

    "Virtual Machine created by PowerConvert 7.0.0.5157 on 8/8/2008 11:47:46 PM"

    We want to shorten that string to a something simple since it shows up on reports and causes issues with formatting, something like "P2V 8/8/2008 11:47:46 PM".

    Anyone have any ideas?

    Thanks.



  • 2.  RE: Changing the Custom Attributes Notes field for guests

    Posted Jan 21, 2010 02:09 PM

    You could try

    $text = (Get-Vm <VM-name>).Description
    # Do your thing with the text
    
    # Write the new text back
    Set-Vm <VM-name> -Description $text
    



  • 3.  RE: Changing the Custom Attributes Notes field for guests

    Posted Jan 21, 2010 04:53 PM

    yeah, but I would also need to parse the existing string so the first couple of words gets removed and replaced with "P2V". Have to figure out the scripting for that yet.

    Thanks.



  • 4.  RE: Changing the Custom Attributes Notes field for guests
    Best Answer

    Posted Jan 21, 2010 05:12 PM

    You can use the -replace operator like this

    $text = "Virtual Machine created by PowerConvert 7.0.0.5157 on 8/8/2008 11:47:46 PM"
    $pattern = "Virtual Machine created by PowerConvert 7.0.0.5157"
    $newtext = $text -replace $pattern, "P2V"
    $newtext
    

    If the pattern is not constant then we could use a regular expression for the matching process.



  • 5.  RE: Changing the Custom Attributes Notes field for guests

    Posted Jan 21, 2010 05:20 PM

    Thanks for the help Luc... I'l work on it.