Home > Mobile >  is their a way to loop through an array to grab path and driver description to a if statment
is their a way to loop through an array to grab path and driver description to a if statment

Time:09-01

$values = @("Name",$value1 ,$value2,$value3,$value4,$value5,$value6,$value7,$value8,$value9)

$value1 = Get-ItemPropertyValue -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Class\{4d36e972-e325-11ce-bfc1-08002be10318}\0000" -name "DriverDesc" | out-string
$value2 = Get-ItemPropertyValue -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Class\{4d36e972-e325-11ce-bfc1-08002be10318}\0001" -name "DriverDesc" | out-string
$value3 = Get-ItemPropertyValue -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Class\{4d36e972-e325-11ce-bfc1-08002be10318}\0002" -name "DriverDesc" | out-string
$value4 = Get-ItemPropertyValue -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Class\{4d36e972-e325-11ce-bfc1-08002be10318}\0003" -name "DriverDesc" | out-string
$value5 = Get-ItemPropertyValue -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Class\{4d36e972-e325-11ce-bfc1-08002be10318}\0004" -name "DriverDesc" | out-string
$value6 = Get-ItemPropertyValue -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Class\{4d36e972-e325-11ce-bfc1-08002be10318}\0005" -name "DriverDesc" | out-string
$value7 = Get-ItemPropertyValue -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Class\{4d36e972-e325-11ce-bfc1-08002be10318}\0006" -name "DriverDesc" | out-string
$value8 = Get-ItemPropertyValue -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Class\{4d36e972-e325-11ce-bfc1-08002be10318}\0007" -name "DriverDesc" | out-string
$value9 = Get-ItemPropertyValue -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Class\{4d36e972-e325-11ce-bfc1-08002be10318}\0008" -name "DriverDesc" | out-string

if ($values -like "Ethernet")

{

Get-Item $values # including the path

}

CodePudding user response:

If you want to loop through a specific path, you can use Get-ChildItem with ForEach-Object.
Then, you can use Get-ItemProperty and check values in registry key properties.

Get-ChildItem "HKLM:\SYSTEM\CurrentControlSet\Control\Class\{4d36e972-e325-11ce-bfc1-08002be10318}\000*" | ForEach-Object {
    $regkey = (Get-ItemProperty $_.PSPath) 
    if ($regkey.DriverDesc -like "*Ethernet*"){
        #Set-ItemProperty ...
    }
} 
  • Related