Overcome Access Denied when zipping Users dirs RRS feed

  • General discussion

  • Hi,

    I am trying to write a script that can archive (.zip) all the C:\Users\ folders, into named archives. I know that Powershell has a few options, but I cannot overcome two issues:

    1. The built-in compression module has a small (1.2? 2?) GB size limit
    2. I get access denied to many files, e.g. junction points, within the Users dirs, which seems to abort the process.

    I've tried using the "7Zip4Powershell" module, but it seems fairly inflexible and has the same # 2 issue.

    I am unsure how to proceed. One idea I had was to copy the entire Users dirs into a temp folder, (which does skip files it cannot read) and then zipping that, but if a Users dir is gigantic this seems inefficient.

    I also debated just writing a C# program and skipping Powershell entirely but I think that's my lack of knowledge speaking. This program is intended to be executed by an IT type person, to backup all user content when a machine is returned, so I think "portability" is important? Hence why I was trying to stick to Powershell.

    Your advice would be greatly appreciated.

    • Edited by PowerShellac Wednesday, October 23, 2019 3:44 PM
    • Changed type Bill_Stewart Tuesday, April 14, 2020 4:59 PM
    • Moved by Bill_Stewart Tuesday, April 14, 2020 4:59 PM Unanswerable drive-by question
    Wednesday, October 23, 2019 3:43 PM

All replies

  • C# cannot bypass limits as both PS and C# use the same APIs to do this.

    I recommend using full 7zip or another commercial package to do this.

    On a 32 bit system the file size will be limited.  64 bit systems will have no practical size limit.


    Wednesday, October 23, 2019 3:56 PM
  • Thanks JRV. If I want to run an automated script, would it make sense to install 7zip within the script itself? Right now I'm doing this:

    Function Install7Zip {
        $7zip = "7Zip4Powershell"
        if (Get-Module -ListAvailable -Name $7zip) {
            # Get-Module -ListAvailable
        } else {
            Install-Module -Name $7zip -Force -Scope CurrentUser
    Is this a valid approach?

    Do you have a suggestion for how to get past the permission denied issue, while compressing entire folders?

    Wednesday, October 23, 2019 4:41 PM
  • What is the purpose for which you are writing the script? Migration of user data? Aren't there already tools for that (e.g., USMT)?

    -- Bill Stewart [Bill_Stewart]

    Wednesday, October 23, 2019 4:43 PM
  • The code has noting to do with your error. The error is because you do not have permissions or the file or folder are in use.

    When I posted 7zip I meant the full 7zip product and not the module.  The module only needs to be installed once and should be installed globally.

    I recommend learning a bit more about Windows and the Windows file system.  You issues are all outside of scripting which makes understanding how to use a script very difficult.

    You will not be able to zip the current users profile because it has many files that are locked and protected.  You need to use special tools as Bill has hinted.  "Backup" programs can correctly backup a full profile. 

    There are also tools in Windows that will back up user data and skip all of the configuration components.  Configurations can be backed up with tools in the MDT whi9ch can be downloaded from MS.

    A good place to start to learn all of this is with the training for user administration. It is a course and set of books that you can get on Amazon.


    Wednesday, October 23, 2019 4:51 PM