Skip to content
This repository was archived by the owner on Dec 11, 2020. It is now read-only.
This repository was archived by the owner on Dec 11, 2020. It is now read-only.

Set-VMFirmware -Firstbootdevice is not possible #65

@Serkar1

Description

@Serkar1

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions