KMKMAHESH KMKMAHESH - 1 year ago 147
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

Answer Source

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

Set-VMFirmware -VMName "SQL3" -FirstBootDevice $(Get-VMDvdDrive -VMName "SQL3")
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download