VMware Cloud Community
NeenaJim
Enthusiast
Enthusiast
Jump to solution

VM notes

Hello,

We have almost 500+ VMs that need to get the notes updated.

Some of the VMs already have notes updated. But here the requirement is to update new fields they are 'Server Owner' and 'Functionality'. But do not overwrite for any existing notes. I have one excel sheet ready (C:\VM notes\VM_Notes.xlsx) that has 3 columns : VM Name, Server Owner, Functionality and updated all the information in it.

Is there anyway we can script this to update the notes? Can someone please help ?

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Then try this way

Import-Csv "C:\VM Notes\VM_Notes.csv" -UseCulture -PipelineVariable row |
ForEach-Object -Process {
    $vm = Get-VM -Name $row.VMName
    $notes = "Owner: $($row.Owner)`nFunction: $($row.Function)`n`n$($vm.Notes)"
    Set-VM -VM $vm -Notes $notes -Confirm:$false
}


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

View solution in original post

0 Kudos
20 Replies
LucD
Leadership
Leadership
Jump to solution

What did you already try?
And where do you get stuck?


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

0 Kudos
NeenaJim
Enthusiast
Enthusiast
Jump to solution

Hello @LucD , Thank you for your reply.

This is what I was able to see after my search:

Connect-VIServer -Server <vCenter Name>
Import-Csv​​ "C:\VM notes\VM_Notes.xlsx"​​ |​​ %​​ {​​ Set-VM​​ $_.VMName​​ -Description​​ $_.Notes​​ -Confirm:$false}

But I am getting the message: 

Import-Csv​​ : The term 'Import-Csv​​' is not recognized as the name of a cmdlet, function, script file, or operable program. Check
the spelling of the name, or if a path was included, verify that the path is correct and try again.

0 Kudos
NeenaJim
Enthusiast
Enthusiast
Jump to solution

After replying to your message, it was disappearing immediately. Thats the reason I have replied as an image. 

0 Kudos
LucD
Leadership
Leadership
Jump to solution

You are using the properties/columns VMname and Notes from the CSV, but you mentioned 3 columns in the CSV earlier.
Not sure what is now in the CSV


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

0 Kudos
NeenaJim
Enthusiast
Enthusiast
Jump to solution

NeenaJim_0-1616519006893.png

 

I am still getting that message:

NeenaJim_0-1616518942921.png

0 Kudos
LucD
Leadership
Leadership
Jump to solution

How are you running that code?
Can you also show the lines before that error message?


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

0 Kudos
NeenaJim
Enthusiast
Enthusiast
Jump to solution

NeenaJim_0-1667490682583.png

 

 

0 Kudos
NeenaJim
Enthusiast
Enthusiast
Jump to solution

0 Kudos
LucD
Leadership
Leadership
Jump to solution

What does the following return?

 

$PSVersionTable
$env:PSModulePath.Split(';')
Get-Module -ListAvailable | Select -ExpandProperty Name

 


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

0 Kudos
NeenaJim
Enthusiast
Enthusiast
Jump to solution

NeenaJim_0-1616524262565.png

 

PS C:\WINDOWS\system32> Get-Module -ListAvailable | Select -ExpandProperty Name
Get-RebootHistory
VMware.CloudServices
VMware.DeployAutomation
VMware.ImageBuilder
VMware.PowerCLI
VMware.Vim
VMware.VimAutomation.Cis.Core
VMware.VimAutomation.Cloud
VMware.VimAutomation.Common
VMware.VimAutomation.Core
VMware.VimAutomation.Hcx
VMware.VimAutomation.HorizonView
VMware.VimAutomation.License
VMware.VimAutomation.Nsxt
VMware.VimAutomation.Sdk
VMware.VimAutomation.Security
VMware.VimAutomation.Srm
VMware.VimAutomation.Storage
VMware.VimAutomation.StorageUtility
VMware.VimAutomation.Vds
VMware.VimAutomation.Vmc
VMware.VimAutomation.vROps
VMware.VimAutomation.WorkloadManagement
VMware.VumAutomation
ImportExcel
Microsoft.PowerShell.Operation.Validation
PackageManagement
Pester
Posh-SSH
PowerShellGet
PSReadline
AppBackgroundTask
AppLocker
AppvClient
Appx
AssignedAccess
BitLocker
BitsTransfer
BranchCache
CimCmdlets
ConfigCI
Defender
DeliveryOptimization
DirectAccessClientComponents
Dism
DnsClient
EventTracingManagement
HgsClient
HgsDiagnostics
HostNetworkingService
International
iSCSI
ISE
Kds
Microsoft.PowerShell.Archive
Microsoft.PowerShell.Diagnostics
Microsoft.PowerShell.Host
Microsoft.PowerShell.LocalAccounts
Microsoft.PowerShell.Management
Microsoft.PowerShell.ODataUtils
Microsoft.PowerShell.Security
Microsoft.PowerShell.Utility
Microsoft.WSMan.Management
MMAgent
MsDtc
NetAdapter
NetConnection
NetEventPacketCapture
NetLbfo
NetNat
NetQos
NetSecurity
NetSwitchTeam
NetTCPIP
NetworkConnectivityStatus
NetworkSwitchManager
NetworkTransition
PcsvDevice
PersistentMemory
PKI
PnpDevice
PrintManagement
ProcessMitigations
Provisioning
PSDesiredStateConfiguration
PSDiagnostics
PSScheduledJob
PSWorkflow
PSWorkflowUtility
ScheduledTasks
SecureBoot
SmbShare
SmbWitness
StartLayout
Storage
StorageBusCache
TLS
TroubleshootingPack
TrustedPlatformModule
UEV
VpnClient
Wdac
Whea
WindowsDeveloperLicense
WindowsErrorReporting
WindowsSearch
WindowsUpdate
WindowsUpdateProvider
Cisco.IMC
Cisco.UCS.Core
Cisco.UCS.DesiredStateConfiguration
Cisco.UCSCentral
Cisco.UCSManager
Microsoft.PowerShell.Operation.Validation
PackageManagement
Pester
PowerShellGet

PS C:\WINDOWS\system32>

0 Kudos
LucD
Leadership
Leadership
Jump to solution

That all looks ok.
What when you do the following from a PS prompt, not the IDE.
Import-Csv "C:\VM Notes\VM_Notes.csv"


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

0 Kudos
NeenaJim
Enthusiast
Enthusiast
Jump to solution

I did like this:

NeenaJim_0-1616525834455.png

The same second command working fine. Not sure what is wrong with the first one. I noticed % and Set-Vm color is different comparing with first one.

0 Kudos
NeenaJim
Enthusiast
Enthusiast
Jump to solution

Thanks @LucD 

Anyways the commands are working good. But like I mentioned earlier, we already have some notes updated with the VMs. So if I run the above commands then it is replacing the old notes, I dont want that. Is there any option we can update the new notes as in cvs without replacing the existing notes ?

0 Kudos
LucD
Leadership
Leadership
Jump to solution

You want the text from the CSV to be added to the Notes, instead of overwriting the Notes?


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

0 Kudos
NeenaJim
Enthusiast
Enthusiast
Jump to solution

Thank you for helping me @LucD 

Yes if possible. I dont want to overwrite the existing notes.

In addition I need to add the information like below:

NeenaJim_2-1616527134847.png

 

NeenaJim_1-1616527056824.png

 

 

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Try something like this

Import-Csv "C:\VM Notes\VM_Notes.csv" -UseCulture -PipelineVariable row |
ForEach-Object -Process {
    Get-VM -Name $row.VMName |
    Set-VM -Description "Owner: $($row.Owner)`nFunction: $($row.Function)`n`n$($_.Notes)" -Confirm:$false
}


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

0 Kudos
NeenaJim
Enthusiast
Enthusiast
Jump to solution

Thank you. It is updating with the VMs. But it is replacing the existing notes. 

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Then try this way

Import-Csv "C:\VM Notes\VM_Notes.csv" -UseCulture -PipelineVariable row |
ForEach-Object -Process {
    $vm = Get-VM -Name $row.VMName
    $notes = "Owner: $($row.Owner)`nFunction: $($row.Function)`n`n$($vm.Notes)"
    Set-VM -VM $vm -Notes $notes -Confirm:$false
}


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

0 Kudos
NeenaJim
Enthusiast
Enthusiast
Jump to solution

Thank you very much. You saved my 50 days..

0 Kudos