Compress-Archive with hidden items

Welcome Forums General PowerShell Q&A Compress-Archive with hidden items

Viewing 2 reply threads
  • Author
    • #243956
      Topics: 8
      Replies: 558
      Points: 2,136
      Helping Hand
      Rank: Community Hero

      I’m trying to zip a folder that contains some hidden files and folders. I noticed that Compress-Archive does not grab these so I thought I’d simply pass all the items.

      This is met with a nasty error. It looks like Get-Item is failing to query the hidden files.

      Testing confirmed Get-Item would also need the -Force parameter to query it. Is there a work around I’m not finding? Or should I just use 7zip or similar? I do not want to change the attributes just to zip them. If I zip them in Windows Explorer it zips them all just fine.
      I appreciate any input.

    • #244007
      Topics: 7
      Replies: 2458
      Points: 6,439
      Helping Hand
      Rank: Community MVP

      I could reproduce the error. You could workaround with using a Foreach-Object loop and the parameter -Update but that would produce another weird error. I’d probably rather use 7zip instead. 😉

    • #244661
      Topics: 11
      Replies: 127
      Points: 763
      Helping Hand
      Rank: Major Contributor

      This works using .NET but the hidden attribute isn’t preserved (if that doesn’t matter once zipped):

      There isn’t an overload for overwriting existing files but there are plenty of ways to handle that beforehand.

      • This reply was modified 1 month, 3 weeks ago by Aaron Hardy. Reason: open link in new tab
Viewing 2 reply threads
  • You must be logged in to reply to this topic.