2017-08-16 5 views
0

子キー内の値に基づいてレジストリ値を変更しようとしています。下記の図をご覧ください。レジストリ - 親値を変更するために子値を検索する

- scripts 
    - {ID} 
    + ScriptState = 0 #This is the value I am looking to change 
    - properties 
     + {ID},E = 'Activated' #based on the values of these registry values 
     + {ID},V = 'Hard Drive' #based on the values of these registry values 

凡例:

+ = Value - = Key

IDのすべてがランダムに生成され、そして私はトラブル/ランダムに生成されたキーIDのリストを取得してループを持っています。私はこれらのキーIDをループすることができたら、残りはかなり簡単にする必要があります。

以下は、私が使用しているチャイルドキー(まだ実装されていない親のキーの値を変更する)を探してフィルタリングしようとしている現在のスクリプトです。

V1:

Get-ChildItem -Path $key -rec | foreach { 
    Get-ChildItem -Path $_.PSPath -rec } | foreach { 
    $CurrentKey = (Get-ItemProperty -Path $_.PsPath) } | 
    select-string "REGEX TO FIND VALUES" -input $CurrentKey -AllMatches | 
    foreach {($_.matches)| select-object Value 
} 

V2:

Get-ChildItem -Path $key -rec | foreach { 
    Get-ChildItem -Path $_.PSPath -rec | foreach { 
    $CurrentKey = (Get-ItemProperty -Path $_.PsPath) 
    if ($CurrentKey -match "REGEX TO FIND VALUES") { 
     $CurrentKey 
    } 
}} 

どちらも上記のスクリプトは、任意の結果を生成し、私は誰かがそうではない理由を私は理解するのに役立つか記入してくださいすることができますことを願っています/これを達成するコードに私を向ける。


P.S.説明できないタイトルに申し訳ありませんが、これを数語で説明するのは難しいです。

+0

だから質問は何ですか? :-) –

+0

謝罪、私は最も重要な部分を省いた。私は今、質問で質問を更新しました... – Kickball

答えて

0

親に対してGet-ChildItem -Recurseを実行すると、ChildItemに-Recurseを追加する必要はありません。すべてのChildItemはすでにメモリに格納されており、パイプラインで使用できる状態になっています。私は以下が助けになるかどうかはわかりませんが、これは私がキーのリストのどこかで値を見つける方法です。

$DebugPreference = 'Continue' 
#Any Get-ChildItem with -Recurse will get all items underneath it, both childitems and their childitems. 
$regKeySet = Get-ChildItem -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall -Recurse 
foreach($childKey in $regKeySet) 
{ 
    Write-Debug -Message "Processing registry key $($childKey.Name)" 
    #You can pick any property you want, the -ErrorAction is set here to SilentlyContinue to cover the instances 
    #where the specific childitem does not contain the property you are looking for, the errors are typically non-terminating but it cleans up the red. 
    $publisherInfo = Get-ItemProperty $childKey.Name -Name Publisher -ErrorAction SilentlyContinue 

    if($publisherInfo.Publisher -ieq 'Microsoft Corporation') 
    { 
     #Do stuff here, you mention doing something to the parent, this is easily accomplished by 
     #just referecning the $childKey that is in this loop. If the publisher equals something you can then manipulate any property of the parent you would like. 
     Write-Host "Found the publisher I wanted: $($publisherInfo.Publisher)." -ForegroundColor Green 
    } 
} 
関連する問題