Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9173907
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:39:44+00:00 2026-06-17T16:39:44+00:00

Christian helped me on the below and I have changed it a bit to

  • 0

Christian helped me on the below and I have changed it a bit to check the value of the key as well. Anyway, the problem I now have is still based on the output that I provide to the user. I do not want to display the key name but rather the value of the key.

The value of the key is based on what key(s) have been found to be TRUE (in the code below).

So, if the below result has a TRUE against keys 1 (value of key is ONE), 2 (value of key is TWO) and 3 (value of key is THREE) then how do I put a WRITE-HOST to the user based on the specific keys found only?

ie I want the result that is provided to have an output of one of the below when it is all the parameters in a specific case are 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"

Here is the code:

$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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T16:39:45+00:00Added an answer on June 17, 2026 at 4:39 pm

    Why are you duplicating the Get-ItemProperty calls? You already have the value (or lack thereof) stored in $keyvalue. You should be able to simplify this to something like this:

    $keyVals = @()
    $keyVals += (Get-ItemProperty hklm:\SYSTEM\CurrentControlSet\services\SNMP\Parameters\TrapConfiguration\$CommunityName -Name 1).1
    $keyVals += (Get-ItemProperty hklm:\SYSTEM\CurrentControlSet\services\SNMP\Parameters\TrapConfiguration\$CommunityName -Name 2).2
    $keyVals += (Get-ItemProperty hklm:\SYSTEM\CurrentControlSet\services\SNMP\Parameters\TrapConfiguration\$CommunityName -Name 3).3
    $keyVals += (Get-ItemProperty hklm:\SYSTEM\CurrentControlSet\services\SNMP\Parameters\TrapConfiguration\$CommunityName -Name 4).4
    
    Write-Host "The value of keys are " -NoNewLine
    $first = $true
    foreach ($keyVal in $keyVals) {
        if ($keyVal -ne $null) {
            if (!$first) { 
                Write-Host " and " -NoNewLine 
            }
            $first = $false
            Write-Host $keyVal -NoNewLine
        }
    }
    Write-Host 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I got following test case below and have a question to it. Why does
I have a problem, I can only create thumbnails of local video files but
I have a problem with the background compiler in Delphi7: in my project there
I have a code like this (still not finished because I don't know the
I want to use Christian Bach's tableSorter client-side table sorting jQuery plugin with my
Do I have to release the returnSet variable ? NSMutableSet* returnSet = [[NSMutableSet alloc]
I'm just starting to use Christian Bach's excellent TableSorter plugin, and I need to
I'm building an isometric map like the one done by Christian Weber . I've
Using WCF 3.5 and the FlatWsdl EndpointBehavior from Christian Weyer , I was able
I have the following dataset containing information about countries 5,1,648,16,10,2,0,3,5,1,1,0,1,1,1,0,0,0,0,0,1,0,0,1,0,0, 3,1,29,3,6,6,0,0,3,1,0,0,1,0,1,0,0,0,0,0,1,0,0,0,1,0, 4,1,2388,20,8,2,2,0,3,1,1,0,0,1,0,0,0,0,0,0,1,1,0,0,0,0, ... The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.