locked
Registry Query RRS feed

  • Question

  • Below is my attempt to query the registry for the value of "AllowRemoteRPC."  This is a dword key that has either a 0 or 1 value. When I run the script I get an error that says the "parameter value cannot be found."

    How do I get just the value of this key?

    ---------------------------------------------------------------------------------------------------------

    invoke-command -computername is-pc13 -scriptblock {get-itemproperty -path hklm:\system\currentcontrolset\control\"terminal server" -name allowremoterpc -value }

     

    Thursday, November 18, 2010 5:54 PM

Answers

  • Try this instead:

    invoke-command -computername is-pc13 -scriptblock {(get-itemproperty -path hklm:\system\currentcontrolset\control\"terminal server" -name allowremoterpc).AllowRemoteRPC}

    you can now do things like:

    if ((get-itemproperty -path hklm:\system\currentcontrolset\control\"terminal server" -name allowremoterpc).AllowRemoteRPC -eq 0) {"blah"}

     


    http://twitter.com/toenuff
    write-host ((0..56)|%{if (($_+1)%3 -eq 0){[char][int]("116111101110117102102064103109097105108046099111109"[($_-2)..$_] -join "")}}) -separator ""
    • Marked as answer by Myrt Webb Thursday, November 18, 2010 8:25 PM
    Thursday, November 18, 2010 7:11 PM

All replies

  • there is no -value parameter of get-itemproperty.

    invoke-command -computername is-pc13 -scriptblock {get-itemproperty -path hklm:\system\currentcontrolset\control\"terminal server" -name allowremoterpc }

    If the above doesn't work, what is your error?


    http://twitter.com/toenuff
    write-host ((0..56)|%{if (($_+1)%3 -eq 0){[char][int]("116111101110117102102064103109097105108046099111109"[($_-2)..$_] -join "")}}) -separator ""
    Thursday, November 18, 2010 6:00 PM
  • You have the -value parameter specified which cannot be used with get-itemproperty.

     

    Try:

    invoke-command -computername is-pc13 -scriptblock {get-itemproperty -path hklm:\system\currentcontrolset\control\"terminal server" -name allowremoterpc  }

     


    Sam Hays
    Thursday, November 18, 2010 6:05 PM
  • I tried the above and I get a list of all kinds of stuff to include the value I am looking for. The problem is that I want to use the value in a conditional script to list all the computers in the domain that do not have a value of "1."
    Thursday, November 18, 2010 6:11 PM
  • Try this instead:

    invoke-command -computername is-pc13 -scriptblock {(get-itemproperty -path hklm:\system\currentcontrolset\control\"terminal server" -name allowremoterpc).AllowRemoteRPC}

    you can now do things like:

    if ((get-itemproperty -path hklm:\system\currentcontrolset\control\"terminal server" -name allowremoterpc).AllowRemoteRPC -eq 0) {"blah"}

     


    http://twitter.com/toenuff
    write-host ((0..56)|%{if (($_+1)%3 -eq 0){[char][int]("116111101110117102102064103109097105108046099111109"[($_-2)..$_] -join "")}}) -separator ""
    • Marked as answer by Myrt Webb Thursday, November 18, 2010 8:25 PM
    Thursday, November 18, 2010 7:11 PM
  • It  works thanks.

    One ? If the "allowremoterpc" key does not exist in the registry, will that create an error I can catch?

    Thursday, November 18, 2010 8:36 PM
  • There's a few ways to handle that, but my favorite is to use the -ErrorAction to specify Stop so that it throws an exception.  You can then capture that in try{}catch{} blocks to capture when an error occurs.  You can inspect the $error variable to see the error details:

    $script = {
     try {
      if ((Get-itemproperty -path hklm:\system\currentcontrolset\control\"terminal server3" -ErrorAction Stop).AllowRemoteRPC -ne 1) {
       "Not Equal to 1"
      }
      else {
       "Equal to 1"
      }
     }
     catch {
      "There was an error getting the key"
      $error[0].Exception
     }
    }
    
    Invoke-Command -ComputerName is-pc13 -ScriptBlock $script

    The nice thing about this method is that it will also capture unknown errors like security permissions to the key or something like that.   


    http://twitter.com/toenuff
    write-host ((0..56)|%{if (($_+1)%3 -eq 0){[char][int]("116111101110117102102064103109097105108046099111109"[($_-2)..$_] -join "")}}) -separator ""
    Thursday, November 18, 2010 9:08 PM