PowerCLI

 View Only
Expand all | Collapse all
NeenaJim

NeenaJimMar 23, 2021 05:04 PM

  • 1.  VM notes

    Posted Mar 23, 2021 03:27 PM

    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 ?



  • 2.  RE: VM notes

    Posted Mar 23, 2021 03:36 PM

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



  • 3.  RE: VM notes

    Posted Mar 23, 2021 04:07 PM

    Hello  , 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.



  • 4.  RE: VM notes

    Posted Mar 23, 2021 04:12 PM

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



  • 5.  RE: VM notes

    Posted Mar 23, 2021 04:36 PM

    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



  • 6.  RE: VM notes

    Posted Mar 23, 2021 05:04 PM

    NeenaJim_0-1616519006893.png

     

    I am still getting that message:

    NeenaJim_0-1616518942921.png



  • 7.  RE: VM notes

    Posted Mar 23, 2021 05:10 PM

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



  • 8.  RE: VM notes

    Posted Mar 23, 2021 05:57 PM

    NeenaJim_0-1667490682583.png

     

     



  • 9.  RE: VM notes

    Posted Mar 23, 2021 06:13 PM


  • 10.  RE: VM notes

    Posted Mar 23, 2021 06:16 PM

    What does the following return?

     

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

     



  • 11.  RE: VM notes

    Posted Mar 23, 2021 06:32 PM

    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>



  • 12.  RE: VM notes

    Posted Mar 23, 2021 06:44 PM
    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"


  • 13.  RE: VM notes

    Posted Mar 23, 2021 06:58 PM

    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.



  • 14.  RE: VM notes

    Posted Mar 23, 2021 07:01 PM

    Thanks  

    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 ?



  • 15.  RE: VM notes

    Posted Mar 23, 2021 07:09 PM

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



  • 16.  RE: VM notes

    Posted Mar 23, 2021 07:20 PM

    Thank you for helping me  

    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

     

     



  • 17.  RE: VM notes

    Posted Mar 23, 2021 07:31 PM

    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
    }
    


  • 18.  RE: VM notes

    Posted Mar 23, 2021 07:40 PM

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



  • 19.  RE: VM notes
    Best Answer

    Posted Mar 23, 2021 08:04 PM

    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
    }
    


  • 20.  RE: VM notes

    Posted Mar 23, 2021 08:17 PM

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



  • 21.  RE: VM notes

    Posted Mar 24, 2021 01:23 AM

    Hi,


     wrote:

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


    You can't possibly know this, but all those replies ended up as getting tagged as spam.
    Nobody knows why.. (it certainly did not look spammy to me)

    I dragged all those replies out of the spam queue, then put them back here... and performed a cleanup so that only one of the replies is still there and all the dupes are in the bin. All in all.. too much work really.. but it is how the forum works.

    Please next time a post disappears, don't keep on resubmitting it.
    We will pick it out of the spam queue.

    --
    Wil