VMware Cloud Community
Maelito77
Contributor
Contributor
Jump to solution

PowerCLI Script to list all VM's disk type and OS

Hi

I wonder if you can help me.

I need a script to list all VM's Harddisk type and OS.

I can do one or another (using cli) but not both on the same report.

Thanks, Maelito

Maelito
Tags (4)
0 Kudos
1 Solution

Accepted Solutions
schepp
Leadership
Leadership
Jump to solution

Hi Maelito,

it could be done this way:

get-vm | Select Name,@{N="Configured OS";E={$_.ExtensionData.Config.GuestFullname}},@{N="Running OS";E={$_.Guest.OsFullName}}, @{N="disktype";E={(Get-Harddisk $_).Storageformat}}

(Configured OS it what you choose during the VM creating, Running OS is what is actually seen running by the VMware tools)

Tim

View solution in original post

0 Kudos
7 Replies
schepp
Leadership
Leadership
Jump to solution

Hi Maelito,

it could be done this way:

get-vm | Select Name,@{N="Configured OS";E={$_.ExtensionData.Config.GuestFullname}},@{N="Running OS";E={$_.Guest.OsFullName}}, @{N="disktype";E={(Get-Harddisk $_).Storageformat}}

(Configured OS it what you choose during the VM creating, Running OS is what is actually seen running by the VMware tools)

Tim

0 Kudos
Maelito77
Contributor
Contributor
Jump to solution

Tim,

Brilliant, that is exactly what I need - Thanks! :smileycool:

For my personal development would be able to tell me where I would find those expressions?

@{N="Configured OS";E={$_.ExtensionData.Config.GuestFullname}},@{N="Running OS";E={$_.Guest.OsFullName}}, @{N="disktype";E={(Get-Harddisk $_).Storageformat}}


Maelito

Maelito
0 Kudos
schepp
Leadership
Leadership
Jump to solution

Hi Maelito,

glad I could help.

You can for example do a

Get-VM | Get-Member

in the PowerCLI.

Or you look it up in the PowerCLI Reference, which is very nice: VirtualMachine

Tim

0 Kudos
Maelito77
Contributor
Contributor
Jump to solution

I looked it up and this is what I found out:

get-vm | where {$_.powerstate -eq "PoweredOn"} | Select Name,@{N="Configured OS";E={$_.ExtensionData.Config.GuestFullname}},@{N="Running OS";E={$_.Guest.OsFullName}}, @{N="disktype";E={(Get-Harddisk $_).Storageformat}} | Export-Csv .\DIsk-State.csv -NoTypeInformation -NoClobber

Get-VM test2008-01

Powerstate is a property

Name is a property

,@{N="Configured OS"; <<- Label on the CSV report

E={$_.ExtensionData.Config.GuestFullname}} <<- $vm = get-vm test2008-01

$vm.extensiondata.[tab tab tab and CONFIG is an option – GUESTFULLNAME is a PROPERTY]

@{N="Running OS";E={$_.Guest.OsFullName}}, <<- https://www.vmware.com/support/developer/PowerCLI/PowerCLI55R2/html/VirtualMachine.html

<<- $vm = get-vm test2008-01

$vm.guest[type “vm.” tab tab tab and GUEST is an option – OSFULLNAME is a PROPERTY]

@{N="disktype";E={(Get-Harddisk $_).Storageformat}} <<- get-harddisk test2008-01 | get-member

StorageFormat is a PROPERTY


During my google searches I came across Get-View command and everyone saying how fast it is... How can I have the same info but using get-view instead of get-vm?


Maelito

Maelito
0 Kudos
momox1
Contributor
Contributor
Jump to solution

Hello Guys,

I hope you are doing well,
any way to add to this line a "get-annotation -customattribute "Roles "   ? I could not find the way to concatenate the command...

 

get-vm -name "serversclients* "| Select Name,NumCpu,MemoryGB,@{N="VMDK";E={(Get-Harddisk $_).Filename}} ,@{N="SIZE";E={(Get-Harddisk $_).CapacityGB}} | Format-Table -AutoSize

0 Kudos
momox1
Contributor
Contributor
Jump to solution

...the idea is to get a list of VMs with the corresponding cpu, ram , vmdk per datastore and a specific annotation.

0 Kudos
momox1
Contributor
Contributor
Jump to solution

I've got an answer on another thread. thank you.

0 Kudos