I found this script some where out there that lists datastores, name of vms in datastore and datastore's path. I want to also get the notes field in the report. Can any one help?
$report = @()
Get-VM | Get-View | % {
$row = "" | select Name, Datastore, Path
$row.Name = $_.Name
$row.Datastore = (Get-View $_.Datastore[0]).Summary.Name
$current = Get-View $_.Parent
$path = $_.Name
do {
$parent = $current
if($parent.Name -ne "vm"){$path = $parent.Name + "\" + $path}
$current = Get-View $current.Parent
} while ($current.Parent -ne $null)
$row.Path = $path
$report += $row
}
$report
thanks
Sorry, must have misread your question.
The Notes field makes it even a bit simpler.
Get-VM | % { $vmImpl = $_ $_ | Get-View | % { $current = Get-View $_.Parent $path = $_.Name do { $parent = $current if($parent.Name -ne "vm"){$path = $parent.Name + "\" + $path} $current = Get-View $current.Parent } while ($current.Parent -ne $null) $row = "" | select Name, Datastore, Path, Note $row.Name = $_.Name $row.Datastore = (Get-View $_.Datastore[0]).Summary.Name $row.Path = $path $row.Note = $vmImpl.Description $report += $row } } $report
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
You could do something like this
Get-VM | % { $vmImpl = $_ $_ | Get-View | % { $current = Get-View $_.Parent $path = $_.Name do { $parent = $current if($parent.Name -ne "vm"){$path = $parent.Name + "\" + $path} $current = Get-View $current.Parent } while ($current.Parent -ne $null) $VMnote = "" for($i = 0; $i -lt $vmImpl.CustomFields.Keys.Count; $i ++ ){ $VMnote += ($vmImpl.CustomFields.Keys[$i] + "=" + $vmImpl.CustomFields.Values[$i] + " ") } $row = "" | select Name, Datastore, Path, Note $row.Name = $_.Name $row.Datastore = (Get-View $_.Datastore[0]).Summary.Name $row.Path = $path $row.Note = $VMnote $report += $row } } $report
All custom attributes are appended to one string.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Sorry, must have misread your question.
The Notes field makes it even a bit simpler.
Get-VM | % { $vmImpl = $_ $_ | Get-View | % { $current = Get-View $_.Parent $path = $_.Name do { $parent = $current if($parent.Name -ne "vm"){$path = $parent.Name + "\" + $path} $current = Get-View $current.Parent } while ($current.Parent -ne $null) $row = "" | select Name, Datastore, Path, Note $row.Name = $_.Name $row.Datastore = (Get-View $_.Datastore[0]).Summary.Name $row.Path = $path $row.Note = $vmImpl.Description $report += $row } } $report
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference