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--