ML
    • Recent
    • Categories
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login

    Solved How can I remove these items with powershell?

    IT Discussion
    powershell remove-item
    4
    16
    1.1k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • JaredBuschJ
      JaredBusch @Obsolesce
      last edited by

      @Obsolesce said in How can I remove these items with powershell?:

      @JaredBusch If it throws a UAC prompt when doing through Windows Explorer GUI, then the script may need elevation. If you run it from an elevated PowerShell window, does it work then?

      That would not be correct. I'll have to get screen shots from the GUI to show you. The entire process is 100% user land. No admin required.

      ObsolesceO 2 Replies Last reply Reply Quote 0
      • ObsolesceO
        Obsolesce @JaredBusch
        last edited by

        @JaredBusch Are you sure it was with just using Remove-Item like in your example, and not doing anything else first?

        1 Reply Last reply Reply Quote 0
        • ObsolesceO
          Obsolesce @JaredBusch
          last edited by Obsolesce

          @JaredBusch I did not use an elevated ISE window:
          8751a4ce-0f7e-464d-8ba9-8145271586c2-image.png

          And it worked for me:
          07fae5dc-68ee-4f47-aa77-2de6d0c24e69-image.png

          gjacobseG JaredBuschJ 2 Replies Last reply Reply Quote 1
          • gjacobseG
            gjacobse @Obsolesce
            last edited by

            @Obsolesce said in How can I remove these items with powershell?:

            @JaredBusch I did not use an elevated ISE window:
            8751a4ce-0f7e-464d-8ba9-8145271586c2-image.png

            And it worked for me:
            07fae5dc-68ee-4f47-aa77-2de6d0c24e69-image.png

            Got to be careful with powershell,.. I feel. Powershell ISE is not the same as powershell…. At least for my system… some commands don’t seem to transfer.

            1 Reply Last reply Reply Quote 0
            • JaredBuschJ
              JaredBusch @Obsolesce
              last edited by

              @Obsolesce said in How can I remove these items with powershell?:

              @JaredBusch I did not use an elevated ISE window:
              8751a4ce-0f7e-464d-8ba9-8145271586c2-image.png

              And it worked for me:
              07fae5dc-68ee-4f47-aa77-2de6d0c24e69-image.png

              See, I swear this is what I did previously, but it did not work yesterday.

              What version of powershell did you have on your test?
              The system I just tried it on was a clean new install of Windows 10 21H2.

              ObsolesceO 1 Reply Last reply Reply Quote 0
              • DashrenderD
                Dashrender
                last edited by

                @JaredBusch is the machine domain joined?

                JaredBuschJ 1 Reply Last reply Reply Quote 0
                • JaredBuschJ
                  JaredBusch @Dashrender
                  last edited by

                  @Dashrender said in How can I remove these items with powershell?:

                  @JaredBusch is the machine domain joined?

                  Yes, but why is that relevant? This is a user land action.

                  1 Reply Last reply Reply Quote 0
                  • ObsolesceO
                    Obsolesce @JaredBusch
                    last edited by

                    @JaredBusch said in How can I remove these items with powershell?:

                    What version of powershell did you have on your test?
                    The system I just tried it on was a clean new install of Windows 10 21H2.

                    PowerShell:

                    Name                           Value                                                                                                                           
                    ----                           -----                                                                                                                           
                    PSVersion                      5.1.22000.832                                                                                                                   
                    PSEdition                      Desktop                                                                                                                         
                    PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                                                                         
                    BuildVersion                   10.0.22000.832                                                                                                                  
                    CLRVersion                     4.0.30319.42000                                                                                                                 
                    WSManStackVersion              3.0                                                                                                                             
                    PSRemotingProtocolVersion      2.3                                                                                                                             
                    SerializationVersion           1.1.0.1
                    

                    Windows:

                    Edition	Windows 11 Enterprise
                    Version	21H2
                    Installed on	‎10/‎19/‎2022
                    OS build	22000.856
                    Experience	Windows Feature Experience Pack 1000.22000.856.0
                    
                    JaredBuschJ 1 Reply Last reply Reply Quote 0
                    • JaredBuschJ
                      JaredBusch @Obsolesce
                      last edited by

                      @Obsolesce said in How can I remove these items with powershell?:

                      @JaredBusch said in How can I remove these items with powershell?:

                      What version of powershell did you have on your test?
                      The system I just tried it on was a clean new install of Windows 10 21H2.

                      PowerShell:

                      Name                           Value                                                                                                                           
                      ----                           -----                                                                                                                           
                      PSVersion                      5.1.22000.832                                                                                                                   
                      PSEdition                      Desktop                                                                                                                         
                      PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                                                                         
                      BuildVersion                   10.0.22000.832                                                                                                                  
                      CLRVersion                     4.0.30319.42000                                                                                                                 
                      WSManStackVersion              3.0                                                                                                                             
                      PSRemotingProtocolVersion      2.3                                                                                                                             
                      SerializationVersion           1.1.0.1
                      

                      Windows:

                      Edition	Windows 11 Enterprise
                      Version	21H2
                      Installed on	‎10/‎19/‎2022
                      OS build	22000.856
                      Experience	Windows Feature Experience Pack 1000.22000.856.0
                      

                      Thanks.
                      I'll be setting up a new laptop tomorrow and I will test this out more carefully.

                      1 Reply Last reply Reply Quote 0
                      • JaredBuschJ
                        JaredBusch
                        last edited by

                        @Obsolesce on default install of Windows 10 21H2, it breaks the, but does not remove it.

                        37f73be6-1b86-49fe-a59e-53fa01db487f-image.png

                        85b4364d-40ff-47a5-837f-ebb626068590-image.png

                        2fdff805-a400-49b4-bd9d-238fc791ad03-image.png

                        00e1bb94-ad8a-4a1b-8920-c13030ddc24f-image.png

                        Installing Windows 11 now.

                        1 Reply Last reply Reply Quote 0
                        • JaredBuschJ
                          JaredBusch
                          last edited by

                          Windows 11 22H2 clean install (just made a new USB).

                          ae31c31b-d915-4fc7-a4e4-4007bdd126d6-image.png

                          207d5b38-a3ca-4edd-b68d-f836b601f2b3-image.png

                          b1df15f9-9fd0-4b5e-9f50-d77f88ddfeea-image.png

                          So the answer is it works in Windows 11, but not 10 with a simple Remove-Item.

                          @Obsolesce any recommendations for a way to do it in Windows 10? I have a good sized fleet of devices that cannot upgrade to 11 that will be used for a couple more years.

                          ObsolesceO 1 Reply Last reply Reply Quote 0
                          • ObsolesceO
                            Obsolesce @JaredBusch
                            last edited by Obsolesce

                            @JaredBusch I figured it out after creating a WIn10 VM (same issue in Win10 22H2 by the way)

                            afbaaef4-f373-43d3-9611-70b657f2f5df-image.png

                            Edition	Windows 10 Pro
                            Version	22H2
                            Installed on	‎10/‎22/‎2022
                            OS build	19045.2006
                            Experience	Windows Feature Experience Pack 120.2212.4180.0
                            

                            Get-ChildItem -Path ~\Documents -Hidden | ForEach-Object { (Get-Item -Path $PSItem.FullName -Force).Delete() }

                            ced45984-e6e3-4c35-ae57-fe9fb746091a-image.png

                            Maybe you can shorten it:

                            Get-ChildItem -Path ~\Documents -Hidden -Recurse | ForEach-Object { $PSItem.Delete() }

                            c30997e0-96a1-42b5-ad7c-6acf04c896fc-image.png

                            JaredBuschJ 1 Reply Last reply Reply Quote 2
                            • JaredBuschJ JaredBusch has marked this topic as solved on
                            • JaredBuschJ
                              JaredBusch @Obsolesce
                              last edited by

                              @Obsolesce said in How can I remove these items with powershell?:

                              Get-ChildItem -Path ~\Documents -Hidden -Recurse | ForEach-Object { $PSItem.Delete() }

                              Thanks a ton.

                              1 Reply Last reply Reply Quote 0
                              • JaredBuschJ
                                JaredBusch
                                last edited by JaredBusch

                                As an update the solution for Windows 11 now also works for Windows 10 if you are on Windows 10 22H2 and fully updated.

                                3ecd352e-4e80-4d97-bb2a-742ae38d326a-image.png

                                1 Reply Last reply Reply Quote 1
                                • 1 / 1
                                • First post
                                  Last post