Bulk zip files individually script works in ISE, not as .ps1

Welcome Forums General PowerShell Q&A Bulk zip files individually script works in ISE, not as .ps1

This topic contains 1 reply, has 2 voices, and was last updated by

 
Participant
1 year, 9 months ago.

  • Author
    Posts
  • #66955

    Participant
    Points: 0
    Rank: Member

    I run an online business that sells digital designs. Before uploading these designs to my website, they need to be compressed.

    Instead of right-clicking>Send To> Compressed Zipped Folderfor each file, I wrote a simple Powershell script to bulk compress all the .png images into individual folders. I just drop a few PNG's into the "designs" folder, and run it. The script runs perfectly when ran within the Powershell ISE console, but when I save it as a .ps1 and run it, it zips the file without any contents inside.

    Any suggestions?

    Here's the script:

    # Script to compress transparent PNG's into .zip files
    gci C:\users\ADMIN\desktop\designs -recurse *.png |

    ForEach-Object {
    $zip = $_.fullname -replace "\.png",".zip";
    new-item -type File $zip -force;
    ((new-object -com shell.application).namespace($zip)).copyhere($_.fullname)
    }

  • #66975

    Participant
    Points: 1
    Rank: Member

    Hi Daniel,

    I ran the script without any problems. Both inside ISE and directly from the ps1 file.

    Albert

The topic ‘Bulk zip files individually script works in ISE, not as .ps1’ is closed to new replies.