Quantcast
Channel: VMware Communities : All Content - All Communities
Viewing all articles
Browse latest Browse all 183671

Adding notes to certain VM's in a folder

$
0
0

I am needing to add a description in the vm notes field..the script will query a datacenter and export the vm name and folder name to a csv file, from that if the folder matches it will input the description. The issue I'm having is it will annotate the description in the vm for the top level folder structure instead of the specified folder.

 

 


#Specifies which folder to target for pulling of Virtual Machines

$JPfolder = get-datacenter "LifePoint Hospitals" | get-folder "ITS-Information Technology" 

 

#Sets a Folder Variable

$Folder = "Test Machines"

 

#Sets a Note Variable

$note = "TEST BOX"

 

#Gets a list of Virtual Machines within the Folder that was identified before and assigns to a variable

$VMlist = get-vm -location $jpfolder

 

#Gets the VM's based on the variable from before and iterates through exporting them to a CSV with the relevant columns

Get-VM $vmlist | select Name,@{N="Folder";E={$_.Folder.Name}} | `

Export-Csv "C:\vm-folder.csv" -NoTypeInformation -UseCulture

 

 

#Imports the CSV created earlier and does a foreach with an IF switch to do the Set-VM Action

Import-Csv "C:\vm-folder.csv" -UseCulture | %{

    If ($_.Folder -eq $Folder)                                {Set-vm -vm $vmlist -Description $note -Confirm:$false}

 

}



Viewing all articles
Browse latest Browse all 183671

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>