andrew_b
andrew_b

Reputation: 29

Powershell script to create reg keys

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

Upvotes: 0

Views: 67

Answers (1)

Eric Longstreet
Eric Longstreet

Reputation: 893

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

Upvotes: 1

Related Questions