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 ?
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
What did you already try?
And where do you get stuck?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
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.
After replying to your message, it was disappearing immediately. Thats the reason I have replied as an image.
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
I am still getting that message:
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
I have changed csv columns to :
Following this article: https://virtuallythatguy.co.uk/add-descriptions-or-notes-to-multiple-vms-using-powercli-virtuallytha...
What does the following return?
$PSVersionTable
$env:PSModulePath.Split(';')
Get-Module -ListAvailable | Select -ExpandProperty Name
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
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>
Import-Csv "C:\VM Notes\VM_Notes.csv"
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I did like this:
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.
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 ?
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
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:
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
Thank you. It is updating with the VMs. But it is replacing the existing notes.
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
Thank you very much. You saved my 50 days..