I just tested this and I believe it is possible.
For testing:
$VMs = Get-VM
$VMs[0] | Select-Object -Property *
That will return all of the properties of a single VM object so you can see them.
Name : ComputerMusheen
PowerState : PoweredOn
Notes : For testing purposes
Guest : ComputerMusheen:Microsoft Windows 10 (64-bit)
NumCpu : 4
CoresPerSocket : 1
MemoryMB : 16384
MemoryGB : 16
VMHostId : HostSystem-host-123456
VMHost : esxi01.contoso.local
VApp :
FolderId : Folder-group-v654321
Folder : Workstations
ResourcePoolId : ResourcePool-resgroup-321654
ResourcePool : Resources
HARestartPriority : ClusterRestartPriority
HAIsolationResponse : AsSpecifiedByCluster
DrsAutomationLevel : AsSpecifiedByCluster
VMSwapfilePolicy : Inherit
VMResourceConfiguration : CpuShares:Normal/4000 MemShares:Normal/163840
Version : Unknown
HardwareVersion : vmx-19
PersistentId : 90eb8581-d5dd-4ade-8fd1-f7e9bd2f84b8
GuestId : windows9_64Guest
UsedSpaceGB : 0.0311394734308123588562011719
ProvisionedSpaceGB : 0.0311394734308123588562011719
DatastoreIdList : {Datastore-datastore-098765, Datastore-datastore-162534}
CreateDate : 4/19/2023 8:02:41 PM
SEVEnabled : False
BootDelayMillisecond : 0
MigrationEncryption : Opportunistic
MemoryHotAddEnabled : True
MemoryHotAddIncrement : 4
MemoryHotAddLimit : 262144
CpuHotAddEnabled : True
CpuHotRemoveEnabled : False
ExtensionData : VMware.Vim.VirtualMachine
CustomFields : {[XdConfig, ]}
Id : VirtualMachine-vm-019284
Uid : /VIServer=contoso\admin@vcenter.contoso.local:443/VirtualMachine=VirtualMachine-vm-019284/
If you want the Name, the OS from within the Guest property, and then everything else you can combine the -Property parameter and the -ExcludeProperty parameter like so.
$VMs[0] | Select-Object -Property Name,@{N="OS";E={$_.guest.osfullname}},* -ExcludeProperty Guest
For the following output
Name : ComputerMusheen
OS : Microsoft Windows 10 (64-bit)
PowerState : PoweredOn
Notes : For testing purposes
NumCpu : 4
CoresPerSocket : 1
MemoryMB : 16384
MemoryGB : 16
VMHostId : HostSystem-host-123456
VMHost : esxi01.contoso.local
VApp :
FolderId : Folder-group-v654321
Folder : Workstations
ResourcePoolId : ResourcePool-resgroup-321654
ResourcePool : Resources
HARestartPriority : ClusterRestartPriority
HAIsolationResponse : AsSpecifiedByCluster
DrsAutomationLevel : AsSpecifiedByCluster
VMSwapfilePolicy : Inherit
VMResourceConfiguration : CpuShares:Normal/4000 MemShares:Normal/163840
Version : Unknown
HardwareVersion : vmx-19
PersistentId : 90eb8581-d5dd-4ade-8fd1-f7e9bd2f84b8
GuestId : windows9_64Guest
UsedSpaceGB : 0.0311394734308123588562011719
ProvisionedSpaceGB : 0.0311394734308123588562011719
DatastoreIdList : {Datastore-datastore-098765, Datastore-datastore-162534}
CreateDate : 4/19/2023 8:02:41 PM
SEVEnabled : False
BootDelayMillisecond : 0
MigrationEncryption : Opportunistic
MemoryHotAddEnabled : True
MemoryHotAddIncrement : 4
MemoryHotAddLimit : 262144
CpuHotAddEnabled : True
CpuHotRemoveEnabled : False
ExtensionData : VMware.Vim.VirtualMachine
CustomFields : {[XdConfig, ]}
Id : VirtualMachine-vm-019284
Uid : /VIServer=contoso\admin@vcenter.contoso.local:443/VirtualMachine=VirtualMachine-vm-019284/
Then, if it were me, and you want to get fancy you could store your Select-Object parameters/values in a hashtable and splat them
$SelectArgs = @{
Property = @(
"Name",
@{Name="OS";Expression={$_.Guest.OSFullName}},
"*"
)
ExcludeProperty = @(
"Guest",
"VMHostId",
"VApp",
"FolderId",
"ResourcePoolId",
"HARestartPriority",
"HAIsolationResponse",
"DrsAutomationLevel",
"VMSwapfilePolicy",
"VMResourceConfiguration"
)
}
$Results = $VMs | Select-Object @SelectArgs
This will throw an error for every single object because we’re asking it to include the Name property, and then also capturing that with the wildcard statement so if you want you can include the ErrorAction parameter in the splat
$SelectArgs = @{
Property = @(
"Name",
@{Name="OS";Expression={$_.Guest.OSFullName}},
"*"
)
ExcludeProperty = @(
"Guest",
"VMHostId",
"VApp",
"FolderId",
"ResourcePoolId",
"HARestartPriority",
"HAIsolationResponse",
"DrsAutomationLevel",
"VMSwapfilePolicy",
"VMResourceConfiguration"
)
ErrorAction = "SilentlyContinue"
}
Or you could use the calculated property method to turn “Name” in to something that doesn’t have a colision like “VMName” or something, then add “Name” to the exclusion list.