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:
$StartButton.Add_Click(
{
$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
}}})
$objForm.Controls.Add($StartButton)
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 DeepL Translate: The world's most accurate translator