PowerShell GUI for Discrete Device Assignment (DDA)

This topic contains 3 replies, has 3 voices, and was last updated by  Olaf Soyk 2 months ago.

  • Author
  • #96497


    Hi @all,

    I am new to PowerShell. However, I have planned a project, which is not quite so easy for a beginner. It is about creating a PowerShell GUI for Discrete Device Assignment (DDA). I've been working on it a little longer and it's going almost as intended. However, the last two commands, which are the main feature of the DDA, do not work.
    The two commands that don't work require a single string in $Locationpath, but it is a string array for me and therefore the commands don't work correctly.
    My problem is that I don't know how to change the string array into the right string, so the code does what it's supposed to do.
    I MUST finish the script today. It'd be great if any of you guys can help me who know more than I do.
    That would be great.
    Here are the lines of the code that contains the error:

    $vm = $objComboBox1.SelectedItem
    $device = $objComboBox2.SelectedItem
    $dev = Get-PnpDevice -PresentOnly | ?{$_.FriendlyName -eq $device}
    $locationPath = Get-PnpDevice -presentOnly | ?{$_.FriendlyName -eq $device} | Get-PnpDeviceProperty -KeyName DEVPKEY_Device_LocationPaths | select -Expand Data
    $vmName = Get-VM | ?{$_.Name -eq $vm}
    if ($vmName){
        Stop-VM -Name $vm -TurnOff -Force
        Set-VM -Name $vm -AutomaticStopAction TurnOff
        Set-VM -GuestControlledCacheTypes $true -Name $vm
        Set-VM -LowMemoryMappedIoSpace 3Gb -Name $vm
        Set-VM -HighMemoryMappedIoSpace 33280Mb -Name $vm
            }if ($locationPath){
                Disable-PnpDevice -InstanceId $dev.InstanceId -Confirm:$false
                foreach($lp in $locationPath){
                    Dismount-VMHostAssignableDevice -LocationPath $lp -Force -Verbose
                    Add-VMAssignableDevice -VMName $vm -LocationPath $lp -Verbose       

    After I run the script, select a VM and a PCI device, press the Start button the following error messages are displayed:

    EXECUTIVE: Dismount-VmHostAssignableDevice cancels the provision of an assignable device so that it can be assigned to a virtual machine.
    Dismount-VMHostAssignableDevice: Error during operation.
    The current configuration does not allow the operating system to control the PCI Express bus. Check the BIOS or UEFI settings.
    In C:\Users\Administrator\Desktop\Discrete Device Assignment.ps1:87 char:17
    + ... Dismount-VMHostAssignableDevice -LocationPath $lp -Force ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    CategoryInfo : InvalidArgument: (:)[Dismount VMHostAssignableDevice], VirtualizationException
    FullyQualifiedErrorId: InvalidParameter,Microsoft.HyperV.PowerShell.Commands.DismountVMHostAssignableDevice

    EXECUTIVE: Add-VMAssignableDevice adds an assignable device to the "Test DC1" virtual machine.
    Add-VMAssignableDevice: The specified device was not found.
    In C:\Users\Administrator\Desktop\Discrete Device Assignment.ps1:88 char:17
    + ... Add-VMAssignableDevice -VMName $vm -LocationPath $lp -Ver...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    CategoryInfo : InvalidArgument: (:)[Add-VMAssignableDevice], VirtualizationException
    FullyQualifiedErrorId: InvalidParameter,Microsoft.HyperV.PowerShell.Commands.AddVmAssignableDevice

    Translated with http://www.DeepL.com/Translator

  • #96500

    Evgeny Fedorov

    Let me guess. Do you need to convert the string array to a single string? If so, you can try this:

    Dismount-VMHostAssignableDevice -LocationPath [string]$lp -Force -Verbose
    Add-VMAssignableDevice -VMName $vm -LocationPath [string]$lp -Verbose  
  • #96513


    My search does not return a single string in $LocationPath, but a string array with multiple elements. I probably have to take this apart first and select the entry I need for VM commands. Or I iterate over the array and call the VM commands in a foreach loop. This has already been explained to me in another forum. I don't know how to do that, though. 🙁

    Unfortunately, your tip did not yield the desired result either, because now the "specified position path" can no longer be found.

  • #96518

    Olaf Soyk

    Didn't the answers in the German Powershell forum push you to the right direction? 😉

You must be logged in to reply to this topic.