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.
You can do like this
Get-VM -Name MyVM | Set-VM -Notes "$($_.Notes) New text"
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
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
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}}
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.
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
Hi LucD,
I got the same issue, the "new text" replaced existing Notes
Strange, works for me
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference