locked
How to export the Registry value on remote servers whether the value exist or not RRS feed

  • Question

  • Hi Team,

    I am in the process of  getting the remote registry value on remote servers.My requirement is to export the result to csv or notepad

    and excepting result should be like below

    PSComputerName HttpCompatibilityListener
    -------------- -------------------------
    Server1                             0
    Server2                HttpCompatibilityListener Value not exist
    Server3                HttpCompatibilityListener Value not exist
    Server4                        1

    I am trying below code. But  some servers will have registry path exists but value might be missing. I am not getting how to write the code using nested if.

    $servers = Get-Content -Path C:\users\user1\Desktop\servers.txt 
    
    $ro =@()
     ForEach ($server in $servers)
     
     {
     
     
     
    $RS = invoke-command  -ComputerName $server -scriptblock { Test-path  'HKLM:\Software\Policies\Microsoft\Windows\WinRM\Service' }
    $sr= {Get-ItemProperty 'HKLM:\Software\Policies\Microsoft\Windows\WinRM\Service'  -name HttpCompatibilityListener } 
    
    IF ($RS -eq $true){
           
    #Write-Host "path exist on $server"
    
    $ro  += Invoke-Command -ComputerName $server -ScriptBlock $sr | Select-Object PSComputerName,HttpCompatibilityListener 
    
    $r = $ro | Export-Csv -Path "c:\users\user1\\desktop\t.csv"  -NoTypeInformation
    
    
    }
    
    
     else
    
     {
     
     Write-output "path not exist on $server"
    
     }
    
    
     }
    


    • Moved by Bill_Stewart Friday, March 15, 2019 7:06 PM This is not "fix/debug/rewrite my script for me" forum
    Tuesday, February 5, 2019 1:09 PM

All replies

  • Please fix the format of your code. It is very hard to read and understand.

    To get the output you request you will need to create custom objects.


    \_(ツ)_/

    Tuesday, February 5, 2019 6:27 PM