Quantcast
Channel: VMware Communities: Message List
Viewing all articles
Browse latest Browse all 252940

Re: Attempting to add custom annotations to an existing 'Export-VMInfo' script

$
0
0

Thankyou sir for the prompt response, it is truly appreciated. Getting back to this today, I tried the snippet of code you suggested, and, at least going against the 4.1 cluster, I didnt get any output besides the column header labelled 'Owner'. Alas, no joy.empty_owner_column_still.PNG

 

There are a number of ways I've been able to return the values of these custom attributes standalone, such as -

 

Get-VM -name *Redhat* | get-annotation -customattribute Created, Hostname, IP, OS, owner

Get-VM "*" | get-annotation -customattribute Created, Hostname, IP, OS, Owner | Format-Table AnnotatedEntity, Name, Value, Created, Hostname, IP, OS, Owner

Get-VM "*" | get-annotation -customattribute Created, Hostname, IP, OS, Owner | Select AnnotatedEntity, Name, Value

 

and even this works, albeit in a somewhat unexpected way from the format perspective....

 

Get-VM | Select Name,@{N="Owner";E={$_.CustomFields['Owner','Created','Hostname','IP','OS']}}

 

and then, each attribute broken out...

 

Get-VM | Select Name,@{N="Owner";E={$_.CustomFields['Owner']}},@{N="Created";E={$_.CustomFields['Created']}},@{N="Hostname";E={$_.CustomFields['Hostname']}},@{N="IP";E={$_.CustomFields['IP']}},@{N="OS";E={$_.CustomFields['OS']}}

 

From the code for my report however, not working like this:

 

$VCServerName = "sf1"
$VC = Connect-VIServer $VCServerName
$VMFolder = "ITAC_SF1_RandD_DC"
$date = Get-Date -f  Mdyyyy_HH_mm
$ExportFilePath = "C:\Users\U219715\Desktop\PowerCLI\Export-VMInfo_RING_$($date).csv"

$Report = @()
$VMs = Get-Folder -Server $VC -Location $VMFolder | Get-VM

$Datastores = Get-Datastore | select Name, Id
$VMHosts = Get-VMHost | select Name, Parent

ForEach ($VM in $VMs) {
      $VMView = $VM | Get-View
      $VMInfo = {} | Select VMName,Powerstate,OS,Folder,IPAddress,ToolsStatus,VMHost,Cluster,Datastore,NumCPU,MemMb,DiskGb, DiskFree, DiskUsed, Owner
      $VMInfo.VMName = $vm.name
      $VMInfo.Powerstate = $vm.Powerstate
      $VMInfo.OS = $vm.Guest.OSFullName
      $VMInfo.Folder = ($vm | Get-Folderpath).Path
      $VMInfo.IPAddress = $vm.Guest.IPAddress[0]
      $VMInfo.ToolsStatus = $VMView.Guest.ToolsStatus
      $VMInfo.VMHost = $vm.host.name
      $VMInfo.Cluster = $vm.host.Parent.Name
      $VMInfo.Datastore = ($Datastores | where {$_.ID -match (($vmview.Datastore | Select -First 1) | Select Value).Value} | Select Name).Name
      $VMInfo.NumCPU = $vm.NumCPU
      $VMInfo.MemMb = [Math]::Round(($vm.MemoryMB),2)
      $VMInfo.DiskGb = [Math]::Round((($vm.HardDisks | Measure-Object -Property CapacityKB -Sum).Sum * 1KB / 1GB),2)
      $VMInfo.DiskFree = [Math]::Round((($vm.Guest.Disks | Measure-Object -Property FreeSpace -Sum).Sum / 1GB),2)
      $VMInfo.DiskUsed = $VMInfo.DiskGb - $VMInfo.DiskFree

      $VMInfo.Owner = $vm.CustomFields['Owner']


      $Report += $VMInfo
}
$Report = $Report | Sort-Object VMName
IF ($Report -ne "") {
$report | Export-Csv $ExportFilePath -NoTypeInformation
}
$VC = Disconnect-VIServer -Confirm:$False

 

Please do know if something comes to mind. Many thanks

 

Ryan


Viewing all articles
Browse latest Browse all 252940

Trending Articles



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