help with -ea stop

Have this working with invoke command but not as local command.

The commands with the # was working on my desktop but I run this script on the server. So I needed to convert the commands to local commands


$Results += $("" | Out-String)
$Results += ‘Server TGCS012’ | out-string
#$results += invoke-command -computer TGCS012 -scriptblock {reg delete “HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager” /v PendingFileRenameOperations /f} -ea Stop
#$results += invoke-command -computer TGCS012 -scriptblock {(Get-ItemProperty -Path ‘Registry::HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager’ -Name PendingFileRenameOperations ).PendingFileRenameOperations} -ea Stop
$results += reg delete “HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager” /v PendingFileRenameOperations /f
$results += (Get-ItemProperty -Path ‘Registry::HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager’ -Name PendingFileRenameOperations ).PendingFileRenameOperations

catch { $Results += $_.exception.message}


reg : ERROR: The system was unable to find the specified registry key or value.
At line:7 char:13

  • $results += reg delete "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\C …
  • CategoryInfo : NotSpecified: (ERROR: The syst…y key or value.:String) [], RemoteException
  • FullyQualifiedErrorId : NativeCommandError

Get-ItemProperty : Property PendingFileRenameOperations does not exist at path
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager.
At line:8 char:14

  • … results += (Get-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\SYST …
  • CategoryInfo : InvalidArgument: (PendingFileRenameOperations:String) [Get-ItemProperty], PSArgumentException
  • FullyQualifiedErrorId : System.Management.Automation.PSArgumentException,Microsoft.PowerShell.Commands.GetItemPropertyCommand

PS C:\Util> $results
The operation completed successfully.

Server TGCS012


Any ideas


Thank you










You need to clear the basic concept of error handling. Please read this document. Each and every line is important.

Not really able to understand the question. The title and post content is confusing. Can you elaborate a little more on the expectation from your script.

Just a suggestion that may or may not help - check out using Remove-Item instead of “reg delete” to remove a registry key.

I like to use PowerShell cmdlets whenever I can, instead of going back to older commands.


PS C:\util> $Results += Remove-item ‘hklm:\SYSTEM\CurrentControlSet\Control\Session Manager\PendingFileRenameOperations’
-ea Stop
Remove-item : Cannot find path ‘HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\PendingFileRenameOperations’
because it does not exist.
At line:1 char:13

  • $Results += Remove-item 'hklm:\SYSTEM\CurrentControlSet\Control\Sessi …
  • CategoryInfo : ObjectNotFound: (HKLM:\SYSTEM\Cu…enameOperations:String) [Remove-Item], ItemNotFoundEx
  • FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.RemoveItemCommand


The command in a DOS Windows worked

C:>reg delete “HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager” /v PendingFileRenameOperations /f
The operation completed successfully.

How to get this to work in powershell?




You would use Remove-ItemProperty to do this.

# Take a backup of this registry key before testing.
Remove-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager' -Name PendingFileRenameOperations -WhatIf
# Remove -WhatIf to take the action.