JEA icon indicating copy to clipboard operation
JEA copied to clipboard

Set-VMFirmware -Firstbootdevice is not possible

Open Serkar1 opened this issue 4 years ago • 0 comments

Hello,

we are making use of JEA and want to establish, that our Hyper-V Operators are capable of toggling the pxe boot for their VMs.

Without JEA this can be accomplished like this:

Set-VMFirmware -VMName $vmname -FirstBootDevice (Get-VMNetworkAdapter -VMName $vmname -Name $adaptername) In order to set FirstBootDevice, you have to pass an object of type VMComponentObject.

So what we have done is, we changed the Operator.psrc file and included following cmdlets under visible cmdlets: 'Get-VMFirmware', @{Name ='Get-VMFirmware'; Parameters=@{Name='VMName'} }, 'Set-VMFirmware', @{Name ='Set-VMFirmware'; Parameters=@{Name='VMName'}, @{Name='FirstBootDevice'} }, 'Get-VMNetworkAdapter', @{Name ='Get-VMNetworkAdapter'; Parameters=@{Name='VMName'}, @{Name='Name'} },

I have tried to make use of it as following:

Invoke-Command -ComputerName localhost -ConfigurationName 'Manage-HyperV' -ArgumentList $script:vm_name, $networkadaptername -ScriptBlock { Set-VMFirmware -VMName $args[0] -FirstBootDevice (Get-VMNetworkAdapter -VMName $args[0] -Name $args[1]) }

The syntax is not supported by this runspace. This can be the case if the runspace is not in language mode. + CategoryInfo : ParserError: ( Set-VMFirmware...Name $args[1]) :String) [], ParseException + FullyQualifiedErrorId : ScriptsNotAllowed + PSComputerName : localhost

Gathering the VMNetworkadapter in a variable and tried to passing it over the argument list is not possible, since the invoke command does not pass the networkadapter as type of VMComponentObject.

Invoke-Command -ComputerName localhost -ConfigurationName 'Manage-HyperV' -ArgumentList $networkadapter -ScriptBlock {                   
    Param(                                  
            [PSObject]$networkadapter
    )
                                
    set-vmfirmware -FirstBootDevice $networkadapter                                  
}

In order to set FirstBootDevice, you have to pass an object of type VMComponentObject, so passing the ID or name does not function.

I also have created a script, which I tried to call, but this also does not help. Do you have an idea how to set the firstbootorder for the vmfirmware?

Serkar1 avatar Nov 24 '20 09:11 Serkar1