简体   繁体   中英

“Illegal operation attempted on a registry key that has been marked for deletion” when creating a remote powershell session

I have a powershell script that runs on a Jenkins node and calls some commands that execute on separate servers. It attempts to register a powershell session configuration and create a new session using that configuration. Failing that, it falls back to a normal remote powershell session. However, I am seeing sporadic failure on seemingly random servers. It will fail to create any powershell session and the entire script fails. Are there some remote powershell settings that I'm missing?

I have tried to Enable the group policy "Do not forcefully unload the user registry at user logoff" but there was no change in behavior. The execution policy is set to "RemoteSigned".

I'm invoking the following command to register the powershell session configuration.

Register-PSSessionConfiguration -Name AdminSession -RunAsCredential $Credentials -Force -NoServiceRestart -WarningAction SilentlyContinue

I then force a restart of the WinRM service (required for the configuration to be accessible).

Invoke-Command -ComputerName $TargetServer -Credential $Credentials -ScriptBlock {Restart-Service -Name WinRM -Force} -ErrorAction SilentlyContinue | Out-Null

I attempt to create a new powershell session with the AdminSession configuration and if that fails, I try and create a normal powershell session.

$TargetSession = New-PSSession -ComputerName $TargetServer -Credential $Credentials

The error output is as follows: Illegal operation attempted on a registry key that has been marked for deletion.

I managed to find the issue. The windows user on the Jenkins node was not an administrator. Updating the user to be admin resolved this issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM