How to remove remotely Outlook profile? Cannot find path 'HKEY_CURRENT_USER\Software\Microsoft\Office\16.0\Outlook\Profiles' because it does not exist.

Stanislav Dmytrenko 1 Reputation point
2022-11-16T11:08:18.017+00:00

Hello,

I am trying to remove remotely Outlook profile. I am local admin in my company.

When I use Invoke-Command:

Invoke-Command -ComputerName $currentPC -ScriptBlock {remove-item -Path "HKCU:\Software\Microsoft\Office\16.0\Outlook\Profiles"}

I'm getting the following error:

Cannot find path 'HKEY_CURRENT_USER\Software\Microsoft\Office\16.0\Outlook\Profiles' because it does not exist.

  • CategoryInfo : ObjectNotFound: (HKEY_CURRENT_US...utlook\Profiles:String) [Get-ChildItem], ItemNotFoundException
  • FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand

I run the script with admin rights, so I have a feeling that scriptblock cannot identify HKEY_USERS for current user who is logged on remote machine
and somehow points to my registry entries. How can I make this script work?
Should I use user's SID on HKEY_USERS? Tanks

Microsoft 365 and Office Development Other
Windows for business Windows Server User experience PowerShell
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Rich Matheisen 47,901 Reputation points
    2022-11-16T19:35:17.113+00:00

    Should I use user's SID on HKEY_USERS?

    Yes.

    0 comments No comments

  2. Anonymous
    2022-11-17T07:52:29.343+00:00

    Hi,

    HKCU is a symbolic link to a key representing the active user under HKEY_USERS key and the information in this key is built during the logon process. You can specify a user account with the -credential parameter.

    Best Regards,
    Ian Xue

    -----------------------------

    If the Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

  3. Limitless Technology 44,746 Reputation points
    2022-11-23T15:16:11.467+00:00

    Hello

    Thank you for your question and reaching out. I can understand you are having issues related to Outlook profile.

    From Outlook 2013 (which supports side-by-side installations), the profiles are stored in HKEY_CURRENT_USER\Software\Microsoft\Office\%version%\Outlook\Profiles, where %version% is 15.0 for Outlook 2013, 16.0 for Outlook 2016, etc. In your Script try to change to this path with user context may be with logon script.


    --If the reply is helpful, please Upvote and Accept as answer--

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.