More than one Expand-properties

Welcome Forums General PowerShell Q&A More than one Expand-properties

This topic contains 5 replies, has 3 voices, and was last updated by

3 years, 6 months ago.

  • Author
  • #25826

    Points: 0
    Rank: Member

    I want to collect some info about my VM
    I used get-vm
    but it does not show the size of vhd file so I have to use expand properties of disk object
    also I need to get my vm IP
    so I have to use expand-properties network
    but for each one I use in separate cmdlet and I get separate out put
    the question
    how can I combine more than one expand- properties in single script
    so I have single line of out put
    vmname vhd size ip

  • #25827

    Points: 60
    Rank: Member

    Hey it,

    Are you saying that you only want the information from your own vm? If so, and you're absolutely sure you'll never have more than one ip address and more than one vhd, then you could use this.

    Otherwise, you'll need to cover more than one line with your data.

    Import-Module HyperV
    $vm      = Get-VM -Name machinename
    $ip      = $vm |
    Get-VirtualNetworkAdapter |
    Select-Object -ExpandProperty ipv4Addresses
    $vhd = $vm | Get-VirtualDiskDrive
    $vhdSize = $vhd[0].VirtualHardDisk[0].MaximumSize/1GB
    $newObj = [pscustomobject] @{
        vm      = $vm
        ip      = $ip
        vhdsize = $vhdSize
  • #25828

    Points: 0
    Rank: Member

    Hi Tim
    thanks for your quick reply
    actually I want to collect info about all the VMs
    so I though if I could do it for one I can do it for many, that why I said my vm
    but after I read your script I notice I was wrong
    as you need to do some looping and if statement which I'm not good at it yet

    1- I have many hyper-v servers
    2- some vms having more than one IP
    3- some vm having more than one VHD

    get-vm -computername (get-content "c:\serverslist.txt")
    this the first step
    how can I do IPs and VHDs for all vms from the above out put
    thanks again for your time and support

  • #25829

    Points: 0
    Rank: Member


    Something else you could try, it may however still involve looping as you have many machines.

    I don't the exact commands to hand but it would be something like this.

    Get-VM -Name TestMachine | Select -ExpandObject Name, @{n='Disk Size'; e={$_.Disks.DiskSize}}, @{n='Drive Letter'; e={$_.Disks.DriveLetter}}

    Sorry I don't have a Hyper-V Machine to give the exact commands but hopefully that gives you an idea of being able to do multiple expand objects.

  • #25830

    Points: 0
    Rank: Member

    ExpandProperty I mean

  • #25861

    Points: 0
    Rank: Member

    here is all the options of get-vm there is no Disks option
    only Harddives and even that it does not have size as properties
    I have to use get-vhd which made it hard as it need VMID not vmname

    PS C:\Windows\system32> get-vm|gm

    TypeName: Microsoft.HyperV.PowerShell.VirtualMachine

    Name MemberType Definition
    —- ———- ———-
    VMId AliasProperty VMId = Id
    VMName AliasProperty VMName = Name
    Equals Method bool Equals(System.Object obj)
    GetHashCode Method int GetHashCode()
    GetHostOnlyKeyValuePairItems Method string[] GetHostOnlyKeyValuePairItems()
    GetType Method type GetType()
    RemoveKeyValuePairItem Method void RemoveKeyValuePairItem(string name, Microsoft.HyperV.PowerShell.KeyValuePairIte...
    ToString Method string ToString()
    VerifyClusterPath Method void VerifyClusterPath(string path, bool allowUnverifiedPaths)
    AutomaticStartAction Property Microsoft.HyperV.PowerShell.StartAction AutomaticStartAction {get;}
    AutomaticStartDelay Property int AutomaticStartDelay {get;}
    AutomaticStopAction Property Microsoft.HyperV.PowerShell.StopAction AutomaticStopAction {get;}
    ComPort1 Property Microsoft.HyperV.PowerShell.VMComPort ComPort1 {get;}
    ComPort2 Property Microsoft.HyperV.PowerShell.VMComPort ComPort2 {get;}
    ComputerName Property string ComputerName {get;}
    ConfigurationLocation Property string ConfigurationLocation {get;}
    CPUUsage Property int CPUUsage {get;}
    CreationTime Property datetime CreationTime {get;}
    DVDDrives Property Microsoft.HyperV.PowerShell.DvdDrive[] DVDDrives {get;}
    DynamicMemoryEnabled Property bool DynamicMemoryEnabled {get;}
    FibreChannelHostBusAdapters Property System.Collections.Generic.List[Microsoft.HyperV.PowerShell.VMFibreChannelHba] Fibre...
    FloppyDrive Property Microsoft.HyperV.PowerShell.VMFloppyDiskDrive FloppyDrive {get;}
    Generation Property int Generation {get;}
    HardDrives Property Microsoft.HyperV.PowerShell.HardDiskDrive[] HardDrives {get;}
    Heartbeat Property System.Nullable[Microsoft.HyperV.PowerShell.VMHeartbeatStatus] Heartbeat {get;}
    Id Property guid Id {get;}
    IntegrationServicesState Property string IntegrationServicesState {get;}
    IntegrationServicesVersion Property version IntegrationServicesVersion {get;}
    IsClustered Property bool IsClustered {get;}
    IsDeleted Property bool IsDeleted {get;}
    Key Property Microsoft.HyperV.PowerShell.ObjectKey Key {get;}
    MemoryAssigned Property long MemoryAssigned {get;}
    MemoryDemand Property long MemoryDemand {get;}
    MemoryMaximum Property long MemoryMaximum {get;}
    MemoryMinimum Property long MemoryMinimum {get;}
    MemoryStartup Property long MemoryStartup {get;}
    MemoryStatus Property string MemoryStatus {get;}
    Name Property string Name {get;}
    NetworkAdapters Property System.Collections.Generic.List[Microsoft.HyperV.PowerShell.VMNetworkAdapter] Networ...
    Notes Property string Notes {get;}
    NumaAligned Property System.Nullable[bool] NumaAligned {get;}
    NumaNodesCount Property int NumaNodesCount {get;}
    NumaSocketCount Property int NumaSocketCount {get;}
    OperationalStatus Property Microsoft.HyperV.PowerShell.VMOperationalStatus[] OperationalStatus {get;}
    ParentSnapshotId Property System.Nullable[guid] ParentSnapshotId {get;}
    ParentSnapshotName Property string ParentSnapshotName {get;}
    Path Property string Path {get;}
    PrimaryOperationalStatus Property System.Nullable[Microsoft.HyperV.PowerShell.VMOperationalStatus] PrimaryOperationalS...
    PrimaryStatusDescription Property string PrimaryStatusDescription {get;}
    ProcessorCount Property long ProcessorCount {get;}
    RemoteFxAdapter Property Microsoft.HyperV.PowerShell.VMRemoteFx3DVideoAdapter RemoteFxAdapter {get;}
    ReplicationHealth Property Microsoft.HyperV.PowerShell.VMReplicationHealthState ReplicationHealth {get;}
    ReplicationMode Property Microsoft.HyperV.PowerShell.VMReplicationMode ReplicationMode {get;}
    ReplicationState Property Microsoft.HyperV.PowerShell.VMReplicationState ReplicationState {get;}
    ResourceMeteringEnabled Property bool ResourceMeteringEnabled {get;}
    SecondaryOperationalStatus Property System.Nullable[Microsoft.HyperV.PowerShell.VMOperationalStatus] SecondaryOperationa...
    SecondaryStatusDescription Property string SecondaryStatusDescription {get;}
    SizeOfSystemFiles Property long SizeOfSystemFiles {get;}
    SmartPagingFileInUse Property bool SmartPagingFileInUse {get;}
    SmartPagingFilePath Property string SmartPagingFilePath {get;}
    SnapshotFileLocation Property string SnapshotFileLocation {get;}
    State Property Microsoft.HyperV.PowerShell.VMState State {get;}
    Status Property string Status {get;}
    StatusDescriptions Property string[] StatusDescriptions {get;}
    Uptime Property timespan Uptime {get;}
    Version Property string Version {get;}
    VMIntegrationService Property System.Collections.Generic.List[Microsoft.HyperV.PowerShell.VMIntegrationComponent] ...
    OSName ScriptProperty System.Object OSName {get=...

The topic ‘More than one Expand-properties’ is closed to new replies.