none
Unable to get the Registry value using if use Invoke-Command -ComputerName $server -ScriptBlock $sname | Out-String RRS feed

  • Question

  • Hi Team,

    I am trying to get the registry D word value from remote servers..it is working fine if used in ISE

    #########################################################

    $servers=Get-Content-Path C:\servers.txt

    Invoke-Command  -ComputerName $server -ScriptBlock {Get-ItemProperty "hklm:\Software\Microsoft\Windows\CurrentVersion\Policies\System" -name DisableCAD}

    ############################################################

    ###
     function get-regvalue{
     $outputBox.Clear()
     $outputBox.text= "GettingRegistry values please wait"
     $servers=$InputBox.lines.Split("`n")
     $date =Get-Date
     $ct = "Task Completed @ " + $date
     $sname = $filter2.text

     foreach ($server in $servers){

     $regresult= Invoke-Command -ComputerName $server  -ScriptBlock  $sname | Out-String

     
     $outputBox.Appendtext("{0}`n" -f $regresult + "`n $ct")
     }

     }
    ##

    I am trying to get this output in output box using out|string but getting below error..

    Invoke-Command : Cannot bind parameter 'SacriptBlock'. Cannot convert the {Get-ItemProperty "hklm:\Software\Microsoft\Windows\CurrentVersion\Policies\System" -name DisableCAD}



    Wednesday, September 6, 2017 5:28 AM

Answers

All replies

  • Spelling:

    Invoke-Command : Cannot bind parameter 'SacriptBlock'. Cannot convert the {Get-ItemProperty "hklm:\Software\Microsoft\Windows\CurrentVersion\Policies\System" -name DisableCAD}

    Please always use script posting tool to post your script.

    This is more likely to work:

    function get-regvalue {
    	$sb = {
    		(Get-ItemProperty 'hklm:\Software\Microsoft\Windows\CurrentVersion\Policies\System' -name DisableCAD).DisableCAD
    	}
    	$outputBox.text = 'GettingRegistry values please wait'
    	foreach ($server in $InputBox.lines) {
    		$regresult = Invoke-Command -ComputerName $server -ScriptBlock $sb
    		$outputBox.Lines += "$regresult Task Completed @ $(Get-Date)"
    	}
    }


    \_(ツ)_/



    • Edited by jrv Wednesday, September 6, 2017 5:48 AM
    Wednesday, September 6, 2017 5:47 AM
  • Thanks JRV..

    every time registry d word value location will be changed..so I want to query the values from a text box..

    using variable $sname = $filter2.text

    I will give the "hklm:\Software\Microsoft\Windows\CurrentVersion\Policies\System" -name DisableCAD

    in the text box form..but not able to get. Please advice

    Wednesday, September 6, 2017 6:02 AM
  • I answered your question.  We cannot rewrite your code for you.  Please open a new topic if you have new questions.


    \_(ツ)_/

    Wednesday, September 6, 2017 6:03 AM
  • Actually I have mentioned my requirement initially.

    Any way thanks for your reply..

    Wednesday, September 6, 2017 6:09 AM
  • And I answered your question.  We do not redesign scripts on request.  You are asking for help with a form.  That is not your original question.


    \_(ツ)_/

    Wednesday, September 6, 2017 6:13 AM
  • Ok Agreed Thanks for your help..Appreciate you..

    I have reposted the question with my exact requirement

    Wednesday, September 6, 2017 6:18 AM