2

I am currently trying to access the registry, obtain all the sub keys with it's appropriate values and then substitute these values with an XML config.

For example:

Within the XML document the following value is stored:

<Name = "Test" Value = "\\somelocation\TOKEN\Application" />
<Name = "Test1" Value = "\\somelocation\TOKEN\Deployment" />

The registry key holds the token value:

TOKEN= LifeCycleManagement

Therefore I want powershell to subsitute "\somelocation\TOKEN*" with "\somelocation\LifeCycleManagement*"

Any ideas please?

Currently I am trying the following code:

$lineElement = @()

$regItems = Get-ItemProperty registrylocation
Get-ItemProperty registrylocation > c:\DEV\output.txt
$contents = Get-Content c:\DEV\output.txt

foreach ($line in $contents)
{
    $line = $line -split(":")
    $lineElement += $line[0]
}

foreach ($element in $lineElement)
{
    $element
    $regItems.$element
}

The $regItems.$element is not returning any results.

1 Answer 1

2

In your code, typically a $line will initially typically look like this:

Token........: LifeCycleManagement. When you split your line at : and take the first part you will get Token......... (the .'s are spaces). Obviously $regItems.Token......... is not what you are after. You should get rid of the spaces at the end of your $line. This can be done using Trim(). The example code below will fix your issue.

$lineElement = @()

$regItems = Get-ItemProperty registrylocation
Get-ItemProperty registrylocation > c:\DEV\output.txt
$contents = Get-Content c:\DEV\output.txt

foreach ($line in $contents)
{
    $line = $line -split(":")
    $lineElement += ($line[0]).Trim()
}

foreach ($element in $lineElement)
{
    $element
    $regItems.$element
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.