PowerShell / JEA

Just Enough Administration
http://aka.ms/JEAdocs
MIT License
257 stars 60 forks source link

Set-VMFirmware -Firstbootdevice is not possible #65

Open Serkar1 opened 3 years ago

Serkar1 commented 3 years ago

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.

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?