VMware Cloud Community
RBohmann2
Contributor
Contributor

How to APPEND info into VM Notes field, leaving existing info intact.

Trying to determine if it is possible to APPEND information into the Notes field.   I am attemping to use Set-VM -Notes  cmdlet  and I can overwrite, but not append. Is this possible? 

vCenter 5.0U3 with PowerCLI 55 R2.

10 Replies
LucD
Leadership
Leadership

You can do like this

Get-VM -Name MyVM | Set-VM -Notes "$($_.Notes) New text"


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

0 Kudos
RBohmann2
Contributor
Contributor

Thanks for the reply Luc.     I tried that and it is overwriting the original text..

0 Kudos
LucD
Leadership
Leadership

Then try like this

$vm = Get-VM -Name MyVM

Set-VM -VM $vm -Notes "$($vm.Notes) New text" -Confirm:$false


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

ITSavant
Contributor
Contributor

The following will append to existing text in the notes object on a VM  if any exists, or just write a new value.

$VMnamearray = "VM1","VM2","VM3"

$TextToAppend = "`r`n"+"Line1 Text"+"`r`n"+"Line2 Text"

Foreach ($VM in $VMnamearray){$NotesTemp=(Get-VM $VM | Select -ExpandProperty Notes); If ($NotesTemp -ne ""){(Set-VM $VM -Notes "$($NotesTemp)$TextToAppend" -Confirm:$False -RunAsync)} Else {Set-VM $VM -Notes "$TextToAppend" -Confirm:$False -RunAsync}}

Devrawat2708
Contributor
Contributor

Hi Rob,

Not sure if this is already resolved. You can edit your script based on these commands :-

PowerCLI D:\VMware\Test_scripts> $vm = get-vm <vm_name>

PowerCLI D:\VMware\Test_scripts> $vm.notes

Text 1

PowerCLI D:\VMware\Test_scripts> $add_note = "Text 2"

PowerCLI D:\VMware\Test_scripts> $new_note = ($vm.notes + $add_note)

PowerCLI D:\VMware\Test_scripts> $new_note

Text 1Text 2

PowerCLI D:\VMware\Test_scripts> get-vm <vm_name> | set-vm -Notes $new_note

You can use escape characters like carriage return or space for formatting the new text.

0 Kudos
CCHAMEYRAT
Contributor
Contributor

  1. Sorry it is an old post, but the LucD command didn't work, it replaced old value by "new text".
0 Kudos
LucD
Leadership
Leadership

Looks like the pipeline behaves differently.
This seems to work

Get-VM | %{Set-VM -VM $_ -Notes "New text + $($_.Notes)"}


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

0 Kudos
CCHAMEYRAT
Contributor
Contributor

Hi LucD,
I got the same issue, the "new text" replaced existing Notes

0 Kudos
LucD
Leadership
Leadership

Strange, works for me


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

0 Kudos
CCHAMEYRAT
Contributor
Contributor

Instead to use @LucD  command, I used the @ITSavant  command and it worked fine.
Thanks a lot.


0 Kudos