Registry items being removed with script












0















Good morning all,



I have an interesting issue with the code put together below, but first a bit of a background.



Onedrive doesn't like working with domain roaming profiles. When OneDrive is installed for a user it will install OneDrive on the PC's "Appdatalocal" folder instead of for the whole PC. This means it will use that installed version for that particular PC until it is updated to a newer version. If a user is to hotdesk from another PC where their version of Onedrive is older or newer Onedrive will fail to work for them on that PC as it pulls in account information from the roaming profile within the registry. The registry compares the version in the roaming profile to the version installed in Appdata/Local and fails to start.



The script below put together by me and the help of others (with a shoutout to tomalak) is supposed to do the following:




  • Delete two DWords within "HKCU:SOFTWAREMicrosoftOneDrive"

  • Remove a Key within "HKCU:SOFTWAREMicrosoftOneDrive" which corresponds to the version number for example 18.0289.187

  • Delete any new folders within "LOCALAPPDATAMicrosoftOneDrive"


It will perform the last task because when you delete the 2 DWords and Key from the Onedrive key and start OneDrive it will create another folder within "LOCALAPPDATAMicrosoftOneDrive" which is around 100MB. Ideally I would like to place this script in group policy to be run on login of every user.



$oneDriveInstallDir = "$env:USERPROFILEappdatalocalMicrosoftOneDrive"
$Versionarray = 13..20

if (Test-Path $oneDriveInstallDir) {
Stop-Process -Name "OneDrive" -Force
$currentVersion = (Get-ItemProperty HKCU:SOFTWAREMicrosoftOneDrive -Name "Version").Version
Remove-ItemProperty HKCU:SOFTWAREMicrosoftOneDrive -Name "Version" -Force
Remove-ItemProperty HKCU:SOFTWAREMicrosoftOneDrive -Name "CurrentVersionPath" -Force
Remove-Item "HKCU:SOFTWAREMicrosoftOneDrive$currentVersion" -Force
Start-Process $oneDriveInstallDir/OneDrive.exe
}
Get-ChildItem "$env:LOCALAPPDATAMicrosoftOneDrive" -Recurse | Where-Object {
$item = $_
$item -is [System.IO.DirectoryInfo] -and (
$Versionarray | Where-Object { $item.Name.Contains($_) }
)
} | Remove-Item -Recurse -Force
Stop-Process –Name invalidprocess -ErrorAction SilentlyContinue -ErrorVariable ProcessError;

If ($ProcessError) {

Write-Warning -Message "Some of these folders are in use.";
}


The Problem



When the script is run it will ask if I want to carry on and delete the items requested. I don't really want it to ask, even with the force commands it still asks. The major issue is it will then start to delete all of the items within the registry OneDrive key which it shouldn't do. I have tried going through a debug before asking but can't find the reason. Please see an example of the files it's attempting to delete below:




  • HKEY_CURRENT_USERSoftwareMicrosoftOneDriveClientConfigTelemetryTimeStamp

  • HKEY_CURRENT_USERSoftwareMicrosoftOneDriveMigrationCompleted

  • HKEY_CURRENT_USERSoftwareMicrosoftOneDriveStandaloneUpdaterSafeMode

  • HKEY_CURRENT_USERSoftwareMicrosoftOneDriveUpdateXMLRescanTime


Thank you for looking.










share|improve this question



























    0















    Good morning all,



    I have an interesting issue with the code put together below, but first a bit of a background.



    Onedrive doesn't like working with domain roaming profiles. When OneDrive is installed for a user it will install OneDrive on the PC's "Appdatalocal" folder instead of for the whole PC. This means it will use that installed version for that particular PC until it is updated to a newer version. If a user is to hotdesk from another PC where their version of Onedrive is older or newer Onedrive will fail to work for them on that PC as it pulls in account information from the roaming profile within the registry. The registry compares the version in the roaming profile to the version installed in Appdata/Local and fails to start.



    The script below put together by me and the help of others (with a shoutout to tomalak) is supposed to do the following:




    • Delete two DWords within "HKCU:SOFTWAREMicrosoftOneDrive"

    • Remove a Key within "HKCU:SOFTWAREMicrosoftOneDrive" which corresponds to the version number for example 18.0289.187

    • Delete any new folders within "LOCALAPPDATAMicrosoftOneDrive"


    It will perform the last task because when you delete the 2 DWords and Key from the Onedrive key and start OneDrive it will create another folder within "LOCALAPPDATAMicrosoftOneDrive" which is around 100MB. Ideally I would like to place this script in group policy to be run on login of every user.



    $oneDriveInstallDir = "$env:USERPROFILEappdatalocalMicrosoftOneDrive"
    $Versionarray = 13..20

    if (Test-Path $oneDriveInstallDir) {
    Stop-Process -Name "OneDrive" -Force
    $currentVersion = (Get-ItemProperty HKCU:SOFTWAREMicrosoftOneDrive -Name "Version").Version
    Remove-ItemProperty HKCU:SOFTWAREMicrosoftOneDrive -Name "Version" -Force
    Remove-ItemProperty HKCU:SOFTWAREMicrosoftOneDrive -Name "CurrentVersionPath" -Force
    Remove-Item "HKCU:SOFTWAREMicrosoftOneDrive$currentVersion" -Force
    Start-Process $oneDriveInstallDir/OneDrive.exe
    }
    Get-ChildItem "$env:LOCALAPPDATAMicrosoftOneDrive" -Recurse | Where-Object {
    $item = $_
    $item -is [System.IO.DirectoryInfo] -and (
    $Versionarray | Where-Object { $item.Name.Contains($_) }
    )
    } | Remove-Item -Recurse -Force
    Stop-Process –Name invalidprocess -ErrorAction SilentlyContinue -ErrorVariable ProcessError;

    If ($ProcessError) {

    Write-Warning -Message "Some of these folders are in use.";
    }


    The Problem



    When the script is run it will ask if I want to carry on and delete the items requested. I don't really want it to ask, even with the force commands it still asks. The major issue is it will then start to delete all of the items within the registry OneDrive key which it shouldn't do. I have tried going through a debug before asking but can't find the reason. Please see an example of the files it's attempting to delete below:




    • HKEY_CURRENT_USERSoftwareMicrosoftOneDriveClientConfigTelemetryTimeStamp

    • HKEY_CURRENT_USERSoftwareMicrosoftOneDriveMigrationCompleted

    • HKEY_CURRENT_USERSoftwareMicrosoftOneDriveStandaloneUpdaterSafeMode

    • HKEY_CURRENT_USERSoftwareMicrosoftOneDriveUpdateXMLRescanTime


    Thank you for looking.










    share|improve this question

























      0












      0








      0








      Good morning all,



      I have an interesting issue with the code put together below, but first a bit of a background.



      Onedrive doesn't like working with domain roaming profiles. When OneDrive is installed for a user it will install OneDrive on the PC's "Appdatalocal" folder instead of for the whole PC. This means it will use that installed version for that particular PC until it is updated to a newer version. If a user is to hotdesk from another PC where their version of Onedrive is older or newer Onedrive will fail to work for them on that PC as it pulls in account information from the roaming profile within the registry. The registry compares the version in the roaming profile to the version installed in Appdata/Local and fails to start.



      The script below put together by me and the help of others (with a shoutout to tomalak) is supposed to do the following:




      • Delete two DWords within "HKCU:SOFTWAREMicrosoftOneDrive"

      • Remove a Key within "HKCU:SOFTWAREMicrosoftOneDrive" which corresponds to the version number for example 18.0289.187

      • Delete any new folders within "LOCALAPPDATAMicrosoftOneDrive"


      It will perform the last task because when you delete the 2 DWords and Key from the Onedrive key and start OneDrive it will create another folder within "LOCALAPPDATAMicrosoftOneDrive" which is around 100MB. Ideally I would like to place this script in group policy to be run on login of every user.



      $oneDriveInstallDir = "$env:USERPROFILEappdatalocalMicrosoftOneDrive"
      $Versionarray = 13..20

      if (Test-Path $oneDriveInstallDir) {
      Stop-Process -Name "OneDrive" -Force
      $currentVersion = (Get-ItemProperty HKCU:SOFTWAREMicrosoftOneDrive -Name "Version").Version
      Remove-ItemProperty HKCU:SOFTWAREMicrosoftOneDrive -Name "Version" -Force
      Remove-ItemProperty HKCU:SOFTWAREMicrosoftOneDrive -Name "CurrentVersionPath" -Force
      Remove-Item "HKCU:SOFTWAREMicrosoftOneDrive$currentVersion" -Force
      Start-Process $oneDriveInstallDir/OneDrive.exe
      }
      Get-ChildItem "$env:LOCALAPPDATAMicrosoftOneDrive" -Recurse | Where-Object {
      $item = $_
      $item -is [System.IO.DirectoryInfo] -and (
      $Versionarray | Where-Object { $item.Name.Contains($_) }
      )
      } | Remove-Item -Recurse -Force
      Stop-Process –Name invalidprocess -ErrorAction SilentlyContinue -ErrorVariable ProcessError;

      If ($ProcessError) {

      Write-Warning -Message "Some of these folders are in use.";
      }


      The Problem



      When the script is run it will ask if I want to carry on and delete the items requested. I don't really want it to ask, even with the force commands it still asks. The major issue is it will then start to delete all of the items within the registry OneDrive key which it shouldn't do. I have tried going through a debug before asking but can't find the reason. Please see an example of the files it's attempting to delete below:




      • HKEY_CURRENT_USERSoftwareMicrosoftOneDriveClientConfigTelemetryTimeStamp

      • HKEY_CURRENT_USERSoftwareMicrosoftOneDriveMigrationCompleted

      • HKEY_CURRENT_USERSoftwareMicrosoftOneDriveStandaloneUpdaterSafeMode

      • HKEY_CURRENT_USERSoftwareMicrosoftOneDriveUpdateXMLRescanTime


      Thank you for looking.










      share|improve this question














      Good morning all,



      I have an interesting issue with the code put together below, but first a bit of a background.



      Onedrive doesn't like working with domain roaming profiles. When OneDrive is installed for a user it will install OneDrive on the PC's "Appdatalocal" folder instead of for the whole PC. This means it will use that installed version for that particular PC until it is updated to a newer version. If a user is to hotdesk from another PC where their version of Onedrive is older or newer Onedrive will fail to work for them on that PC as it pulls in account information from the roaming profile within the registry. The registry compares the version in the roaming profile to the version installed in Appdata/Local and fails to start.



      The script below put together by me and the help of others (with a shoutout to tomalak) is supposed to do the following:




      • Delete two DWords within "HKCU:SOFTWAREMicrosoftOneDrive"

      • Remove a Key within "HKCU:SOFTWAREMicrosoftOneDrive" which corresponds to the version number for example 18.0289.187

      • Delete any new folders within "LOCALAPPDATAMicrosoftOneDrive"


      It will perform the last task because when you delete the 2 DWords and Key from the Onedrive key and start OneDrive it will create another folder within "LOCALAPPDATAMicrosoftOneDrive" which is around 100MB. Ideally I would like to place this script in group policy to be run on login of every user.



      $oneDriveInstallDir = "$env:USERPROFILEappdatalocalMicrosoftOneDrive"
      $Versionarray = 13..20

      if (Test-Path $oneDriveInstallDir) {
      Stop-Process -Name "OneDrive" -Force
      $currentVersion = (Get-ItemProperty HKCU:SOFTWAREMicrosoftOneDrive -Name "Version").Version
      Remove-ItemProperty HKCU:SOFTWAREMicrosoftOneDrive -Name "Version" -Force
      Remove-ItemProperty HKCU:SOFTWAREMicrosoftOneDrive -Name "CurrentVersionPath" -Force
      Remove-Item "HKCU:SOFTWAREMicrosoftOneDrive$currentVersion" -Force
      Start-Process $oneDriveInstallDir/OneDrive.exe
      }
      Get-ChildItem "$env:LOCALAPPDATAMicrosoftOneDrive" -Recurse | Where-Object {
      $item = $_
      $item -is [System.IO.DirectoryInfo] -and (
      $Versionarray | Where-Object { $item.Name.Contains($_) }
      )
      } | Remove-Item -Recurse -Force
      Stop-Process –Name invalidprocess -ErrorAction SilentlyContinue -ErrorVariable ProcessError;

      If ($ProcessError) {

      Write-Warning -Message "Some of these folders are in use.";
      }


      The Problem



      When the script is run it will ask if I want to carry on and delete the items requested. I don't really want it to ask, even with the force commands it still asks. The major issue is it will then start to delete all of the items within the registry OneDrive key which it shouldn't do. I have tried going through a debug before asking but can't find the reason. Please see an example of the files it's attempting to delete below:




      • HKEY_CURRENT_USERSoftwareMicrosoftOneDriveClientConfigTelemetryTimeStamp

      • HKEY_CURRENT_USERSoftwareMicrosoftOneDriveMigrationCompleted

      • HKEY_CURRENT_USERSoftwareMicrosoftOneDriveStandaloneUpdaterSafeMode

      • HKEY_CURRENT_USERSoftwareMicrosoftOneDriveUpdateXMLRescanTime


      Thank you for looking.







      powershell registry onedrive






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 15 '18 at 11:31









      MarshalMarshal

      54731527




      54731527
























          1 Answer
          1






          active

          oldest

          votes


















          1














          The prompt



          Use the -Confirm:$false switch with your Remove-ItemProperty and / or Remove-Item commands to get rid of the prompt.



          The deletion of the OnDrive Registry Hive



          If there is no value set for $currentVersion, the follwing part of your script will delete the OnDrive Registry Hive:



          Remove-Item "HKCU:SOFTWAREMicrosoftOneDrive$currentVersion" -Force





          share|improve this answer

























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53318523%2fregistry-items-being-removed-with-script%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            The prompt



            Use the -Confirm:$false switch with your Remove-ItemProperty and / or Remove-Item commands to get rid of the prompt.



            The deletion of the OnDrive Registry Hive



            If there is no value set for $currentVersion, the follwing part of your script will delete the OnDrive Registry Hive:



            Remove-Item "HKCU:SOFTWAREMicrosoftOneDrive$currentVersion" -Force





            share|improve this answer






























              1














              The prompt



              Use the -Confirm:$false switch with your Remove-ItemProperty and / or Remove-Item commands to get rid of the prompt.



              The deletion of the OnDrive Registry Hive



              If there is no value set for $currentVersion, the follwing part of your script will delete the OnDrive Registry Hive:



              Remove-Item "HKCU:SOFTWAREMicrosoftOneDrive$currentVersion" -Force





              share|improve this answer




























                1












                1








                1







                The prompt



                Use the -Confirm:$false switch with your Remove-ItemProperty and / or Remove-Item commands to get rid of the prompt.



                The deletion of the OnDrive Registry Hive



                If there is no value set for $currentVersion, the follwing part of your script will delete the OnDrive Registry Hive:



                Remove-Item "HKCU:SOFTWAREMicrosoftOneDrive$currentVersion" -Force





                share|improve this answer















                The prompt



                Use the -Confirm:$false switch with your Remove-ItemProperty and / or Remove-Item commands to get rid of the prompt.



                The deletion of the OnDrive Registry Hive



                If there is no value set for $currentVersion, the follwing part of your script will delete the OnDrive Registry Hive:



                Remove-Item "HKCU:SOFTWAREMicrosoftOneDrive$currentVersion" -Force






                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Nov 15 '18 at 11:39

























                answered Nov 15 '18 at 11:34









                TobyUTobyU

                2,48511022




                2,48511022
































                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53318523%2fregistry-items-being-removed-with-script%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Florida Star v. B. J. F.

                    Danny Elfman

                    Lugert, Oklahoma