You did not put the command code line Set-Item
.
The parameter Credential
is used to execute a command as if it were in another account. You could only access the branch HKEY_CURRENT_USER
if you knew the password for this account. I believe this is not your reality.
In the context of your doubt, it is wrong to speak in credential created. Probably what you meant is profile created.
Starting from the premise that one wants to change some information in the branch HKEY_CURRENT_USER
of a profile created, being in a third party account, this would only be possible if the account executing the command has administrative powers in the operating system.
The steps to change the record of a created profile that is not loaded are not trivial. For example, there is no native command in powershell to load and download a log branch. The external command "reg.exe" needs to be used.
## Inicializa variáveis gerais
$EditorDeRegistro = [Environment]::GetFolderPath('System') + '\reg.exe'
$ArquivoDeRamificaçãoDoPerfil = 'D:\Usuários\João Ninguém\ntuser.dat'
$AcessoAoPerfil = 'Acesso'
Push-Location -LiteralPath ( Get-Location )
## Libera memória
[GC]::Collect()
[GC]::WaitForPendingFinalizers()
## Carrega perfil
$ParâmetroSimplificado = @{
FilePath = $EditorDeRegistro
ArgumentList = 'LOAD', "HKU\$AcessoAoPerfil", """$ArquivoDeRamificaçãoDoPerfil"""
Wait = $true
WindowStyle = 'Hidden'
PassThru = $true
}
$CódigoDeSaída = Start-Process @ParâmetroSimplificado
$CódigoDeSaída
## Vai para a ramificação do perfil carregado
Set-Location -LiteralPath "Registry::HKEY_USERS\$AcessoAoPerfil"
## Execute os comandos que quiser, desde que LiteralPath ou Path comece com '.\'
Set-ItemProperty -LiteralPath '.\Environment\' -Name 'teste de variável de ambiente' -Value 'teste de associação para variável de ambiente'
## Descarrega perfil
$ParâmetroSimplificado.ArgumentList = 'UNLOAD', "HKU\$AcessoAoPerfil"
$CódigoDeSaída = Start-Process @ParâmetroSimplificado
$CódigoDeSaída
## Libera memória
[GC]::Collect()
[GC]::WaitForPendingFinalizers()
## Retorna à pasta inicial
Pop-Location
- I use this solution in powershell 2.0 (Windows 7) and powershell 5.1 (Windows 10).