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
$VMNAME= "SQL3"
$VMDVD = Get-VMDvdDrive -VMName $VMNAME
Set-VMFirmware -VMName $VMNAME -FirstBootDevice $VMDVD
but how can i do it in a single line
通常,任何变量引用都可以由子表达式( $()
)代替:
Set-VMFirmware -VMName "SQL3" -FirstBootDevice $(Get-VMDvdDrive -VMName "SQL3")
If you have multiple DVD drives and know the ISO file
$DvdBootDrive = Get-VMDvdDrive -VMName $VmName | where {$_.Path -Like "*AutoInstall.iso*" }
Set-VMFirmware -VMName $VmName -FirstBootDevice $DvdBootDrive
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.