locked
Get Reg values, change reg value and pipe to csv RRS feed

  • Question

  • I am in the process of modifying a registry key. My desired result is the following..

    1) Run against list of computers

    2) Retrieve 3 registry values (ServerName, ServerNameList, Version)

    3) Modify ServerNameList

    4) Pipe Old registry values + the new registry value to csv

    5) Pipe "Unreachable" if host not available.

    This is what I have so far;

    $val = Get-ItemProperty -Path 'HKLM:\software\WOW6432Node\Program1\Program1 Client' -Name "ServerNameList"
    
    if($val.ServerNameList -ne 'ABCD.EFGH.IJKL.companyname.com')
    {
     set-itemproperty -Path HKLM:\software\WOW6432Node\Tanium\"Tanium Client" -Name "ServerNameList" -value ABCD.EFGH.IJKL.companyname.com
    }
    
    }
    	else {
    		Write-Host "$computername unreachable"
    	}
    }


    DHeinz

    Wednesday, April 24, 2019 5:28 PM

All replies

  • You will have to create a custom object and output that to your Csv file.


    \_(ツ)_/

    Wednesday, April 24, 2019 8:49 PM
  • Clear-Host
    
    $RegKey ="Software\WOW6432Node\Tanium\Tanium Client"
     Cd hklm:\$RegKey 
    
    Get-WMIObject Win32_ComputerSystem | Select-Object -ExpandProperty name 
    Get-ItemPropertyValue -Path. -Name Version
    Get-ItemPropertyValue -Path. -Name ServerName
    Get-ItemPropertyValue -Path. -Name ServerNameList
    
    $ourObject = New-Object -TypeName psobject 
    
    
    $ourObject | Add-Member -MemberType NoteProperty -Name "Computer Name" -Value $computerInfo.Name
    $ourObject | Add-Member -MemberType NoteProperty -Name "Version" -Value $RegKey.version
    $ourObject | Add-Member -MemberType NoteProperty -Name "Server Name" -Value $RegKey.ServerName
    $ourObject | Add-Member -MemberType NoteProperty -Name "Server List Name" -Value $RegKey.ServerNameList
    
    $ourObject


    DHeinz

    Wednesday, April 24, 2019 9:32 PM
  • Does this help?

    Set-ItemProperty hkcu:\key1 name1 value1 -PassThru | ConvertTo-Csv
    
    "name1","PSPath","PSParentPath","PSChildName","PSDrive","PSProvider" "value1","Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER\key1","Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER","key1","HKCU","Microsoft.PowerShell.Core\Registry"
    • Edited by JS2010 Wednesday, April 24, 2019 9:48 PM
    Wednesday, April 24, 2019 9:48 PM
  • Using the following;v

    Clear-Host
    
    $RegKey ="Software\WOW6432Node\Tanium\Tanium Client"
     Cd hklm:\$RegKey 
    
    Get-WMIObject Win32_ComputerSystem | Select-Object -ExpandProperty name 
    Get-ItemPropertyValue -Path. -Name Version
    Get-ItemPropertyValue -Path. -Name ServerName
    Get-ItemPropertyValue -Path. -Name ServerNameList
    
    $ourObject = New-Object -TypeName psobject 
    
    
    $ourObject | Add-Member -MemberType NoteProperty -Name "Computer Name" -Value $computerInfo.Name
    $ourObject | Add-Member -MemberType NoteProperty -Name "Version" -Value $Ver.Version
    $ourObject | Add-Member -MemberType NoteProperty -Name "Server Name" -Value $SN.ServerName
    $ourObject | Add-Member -MemberType NoteProperty -Name "Server List Name" -Value $SNL.ServerNameList
    
    $ourObject

    I get a returned result of;

     

    120706-YOGA370
    7.2.314.3211
    sectanv01.seattle.main.gatesfoundation.org
    sectanv01.seattle.main.gatesfoundation.org


    Computer Name  Version Server Name Server List Name
    -------------  ------- ----------- ----------------
    120706-YOGA370

    Which is close, I just need to pull in the remaining info for Version, Server Name and server Name List


    DHeinz

    Wednesday, April 24, 2019 9:53 PM
  • [pscustomobject]@{
          OldValue = $oldvalue
          NewValue = $newValu
    }

    I recommend reading the help for all CmdLets you want to use but first take the time to learn basic PowerShell.

    The code you are posting is just some nonsense that you copied from somewhere.  If you edited it you made the edits without reading the CmdLet help.

    Stop guessing.  Think about what you are doing.   Remember that thing that makes you more human than a computer is your ability to think.


    \_(ツ)_/

    Wednesday, April 24, 2019 10:05 PM
  • You question and all of the code you have posted make almost no technical sense.  This is what it appears you are asking:

    $regkey = 'HKLM:\software\WOW6432Node\Program1\Program1 Client'
    $oldValue = (Get-ItemProperty $regkey -Name ServerNameList).ServerList
    if ($oldValue -ne 'ABCD.EFGH.IJKL.companyname.com') {
        Set-itemproperty -Path 'HKLM:\software\WOW6432Node\Tanium\Tanium Client' -Name ServerNameList -value ABCD.EFGH.IJKL.companyname.com
        $newValue = 'ABCD.EFGH.IJKL.companyname.com'
    }
    [array]$objs += [pscustomobject]@{
        OldValue = $oldValue
        NewValue = $newValue
    }
    $objs | Export-Csv file.csv
    

    Please read the following: How to ask questions in a technical forum


    \_(ツ)_/

    Wednesday, April 24, 2019 10:11 PM