0

I've created this script to look at all the values in a reg key and change the value of the variable until it's finished looping, though When I run it only appears to give me the output listed below. It looks as though I might be using the wrong type of loop for this application. Can someone please give me some guidance on this? Thanks

Also the reg key values are User1, User2, User3.

Script:

$valueName = "User"
$existingValues = Get-Item -Path $regKeyPath | Select-Object property
foreach ($item in $existingValues.property){       
       $intInc = 0
       $intInc++
       $valueName = "User" + ($intInc).ToString()
       Write-Host $valueName   

}

Set-ItemProperty -Path $regKeyPath -Name $valueName -Type SZ -Value $userName 

Output:

User2
User2
User2

1 Answer 1

1

Move $intInc = 0 before the loop. Right now you are resetting the counter for every loop pass.

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.