1
votes

I'm trying to make a report that lists a server name, vm name, and notes section from the vm but I cannot seem to get this code to run, it always gives me this error:

Select-Object : Cannot convert 'System.Object[]' to the type 'System.String' required by parameter 'ExpandProperty'. not supported. At C:\Cooper\Jobs\Get-VmNotes - Copy.ps1:32 char:48 + get-vm -server FA0150 | Select -expandproperty $server, Name, Notes +
~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (:) [Select-Object], ParameterBindingException + FullyQualifiedErrorId : CannotConvertArgument,Microsoft.PowerShell.Commands.SelectObjectCommand

I can get the vmname and notes to output together but I just want to have a column that lists the vcenter server it is associated with.

2
-Expandproperty supports single property technet.microsoft.com/en-us/library/hh849895.aspx - Deptor

2 Answers

0
votes

Expand property is like the same as saying (Get-VM -Server FA0150).Name. It expands the property name you are selecting. You were trying to expand 3 properties (System.Object[]), but it is looking for just a string name of the property you want to expand. Use -Property instead.

get-vm -server FA0150 | Select-Object -Property Name,Notes

get-vm -server FA0150 | Select-Object -Property Name,Notes | Format-Table -Autosize

To also include the server name I made it into a script form since it can no longer be a one-liner:

[CmdletBinding()]
Param ( $Server )
$VMs = Get-VM -Server $Server
$VMs | Select-Object -Properties @(
    @{ Label = 'Server';Expression = { $Server } }
    'Name'
    'Notes'
)
0
votes

I found a solution to my problem using New-ViProperty. The only problem is now it creates four separate csv files and I want to combine them all into one based on the filename, keeping the same format, and delete the four others based on their filename. Is there an easy way to do this?