クリスチャンは以下で私を助けてくれました、そして私はそれを少し変更してキーの値もチェックしました。とにかく、私が今抱えている問題は、私がユーザーに提供する出力に基づいています。キー名ではなく、キーの値を表示したい。
キーの値は、(以下のコードで)TRUEであることが判明したキーに基づいています。
したがって、以下の結果がキー1(キーの値が1)、2(キーの値が2)、および3(キーの値がTHREE)に対してTRUEである場合、ユーザーベースにWRITE-HOSTを配置するにはどうすればよいですか?見つかった特定のキーのみ?
つまり、特定の場合のすべてのパラメーターがTRUEである場合に、提供される結果に以下のいずれかの出力が必要です。
Write-Host "The value of the keys are $keyvalue1"
Write-Host "The value of the keys are $keyvalue1 and $keyvalue2"
Write-Host "The value of the keys are $keyvalue1 and $keyvalue2 and $keyvalue3"
Write-Host "The value of the keys are $keyvalue1 and $keyvalue2 and $keyvalue3 and $keyvalue4"
コードは次のとおりです。
$keyvalue1 = (Get-ItemProperty hklm:\SYSTEM\CurrentControlSet\services\SNMP\Parameters\TrapConfiguration\$CommunityName -Name 1).'1'
$keyvalue2 = (Get-ItemProperty hklm:\SYSTEM\CurrentControlSet\services\SNMP\Parameters\TrapConfiguration\$CommunityName -Name 2).'2'
$keyvalue3 = (Get-ItemProperty hklm:\SYSTEM\CurrentControlSet\services\SNMP\Parameters\TrapConfiguration\$CommunityName -Name 3).'3'
$keyvalue4 = (Get-ItemProperty hklm:\SYSTEM\CurrentControlSet\services\SNMP\Parameters\TrapConfiguration\$CommunityName -Name 4).'4'
$testpath1 = (Get-ItemProperty hklm:\SYSTEM\CurrentControlSet\services\SNMP\Parameters\TrapConfiguration\$CommunityName -Name 1).'1' -ne $null 2>$null
$testpath2 = (Get-ItemProperty hklm:\SYSTEM\CurrentControlSet\services\SNMP\Parameters\TrapConfiguration\$CommunityName -Name 2).'2' -ne $null 2>$null
$testpath3 = (Get-ItemProperty hklm:\SYSTEM\CurrentControlSet\services\SNMP\Parameters\TrapConfiguration\$CommunityName -Name 3).'3' -ne $null 2>$null
$testpath4 = (Get-ItemProperty hklm:\SYSTEM\CurrentControlSet\services\SNMP\Parameters\TrapConfiguration\$CommunityName -Name 4).'4' -ne $null 2>$null
$a = $testpath1, $testpath2 , $testpath3 , $testpath4 # convert your true/false results in an array
$s = "" # empty string
$i = 1 # a simple variable as index
foreach ($b in $a)
{
if ($b -ne $true )
{
break
}
$s += "$i " # if true add index in string
$i++
}
"$($s)is/are true" #output the result