Share via

Get-VM cmdlet missing some properties intermittently.

Smit Pancholi 21 Reputation points
2021-12-23T07:31:32.137+00:00

Hello.

I am trying to use Get-VM in a ps1 script to fetch the details of all the VMs in a Windows Server. After fetching the details, I manipulate the details and ingest relevant data into Splunk.

While fetching the Hyper-V objects and its properties using the Get-VM command, I saw a certain properties gap in the output of Get-VM command.

I scheduled the script to run every 10 mins. When the script runs for first time, I saw the properties using Get-VM | Select-Object VMId, VMName, ID and Name command, it showed me VMId, VMName, ID and Name. But in the subsequent runs, it doesn't gave me VMId and VMName (it shows only ID and Name).

However, when I run the exact same command Get-VM | Select-Object VMId, VMName, ID and Name directly in powershell it shows me all the 4 properties every time.

Also, when I run Get-VM | Get-Member in powershell it shows that VMId and VMName are AliasProperty. It says VMId = ID and VMName = Name.

I've tried this on Windows Server 2012 and 2019.

Can anyone guide me what the issue could be here?

Windows for business | Windows Client for IT Pros | Storage high availability | Virtualization and Hyper-V
Windows for business | Windows Server | User experience | Other
0 comments No comments

Answer accepted by question author

Limitless Technology 40,106 Reputation points
2021-12-29T10:06:15.407+00:00

Hello SmitPancholi,

Thank you for your question and reaching out.

I can understand that you are getting different output when running PowerShell from Task scheduler and run manually.

Please note that VMId and VMName are AliasProperty of Id and Name respectively. and they are by design for all Hyper-V PowerShell modules of Windows 2012, 2016, 2019..etc.

Hence , there is no need to use this AliasProperty two times in your command which will generate duplicate output in the same command.

In your case I will advise you to create new Task scheduler with use of Get-VM | Select-Object ID ,Name to get unique output.
https://learn.microsoft.com/en-us/powershell/module/hyper-v/get-vm?view=windowsserver2022-ps

--------------------------------------------------------------------------------------------------------------------------------------------------

--If the reply is helpful, please Upvote and Accept as answer--

Was this answer helpful?

0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Smit Pancholi 21 Reputation points
    2022-01-10T16:06:17.357+00:00

    Thank you so much @Limitless Technology

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.