KMKMAHESH KMKMAHESH - 4 months ago 36
C# Question

how to set Set-VMFirmware on a single line in powershell

i am trying to make a small c# application to create my Hyper V VM's but i has got a problem with powershell in c# so i just running every powershell cmdlet using cmd.exe

but now i cant get how to set dvddrive as firstbootdevice in generation 2 virtual machine in just one line
for powershell script i use

$VMDVD = Get-VMDvdDrive -VMName $VMNAME
Set-VMFirmware -VMName $VMNAME -FirstBootDevice $VMDVD

but how can i do it in a single line


As a general rule, any variable reference can be substituted by a subexpression ($()):

Set-VMFirmware -VMName "SQL3" -FirstBootDevice $(Get-VMDvdDrive -VMName "SQL3")