VMware Cloud Community
kcvman
Contributor
Contributor
Jump to solution

Changing the Custom Attributes Notes field for guests

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.

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

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.


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

View solution in original post

Reply
0 Kudos
4 Replies
LucD
Leadership
Leadership
Jump to solution

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


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

kcvman
Contributor
Contributor
Jump to solution

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.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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.


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

Reply
0 Kudos
kcvman
Contributor
Contributor
Jump to solution

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

Reply
0 Kudos