I Need a Little Help Running Compress-Archive with Read-Host

agfreesafety3 41 Reputation points
2021-03-25T03:02:59.953+00:00

Hello I'm new to Powershell. I will be running the script from the machine where I'd like the compressed file to be placed, in the path specified. I want to compress the folder from the UNC path (from the first Read-Host), and place a copy of the resulting .zip file into the specified directory on the computer (from the second Read-Host).

I would like some help adding the necessary components to this bit of Powershell code (assuming what I have here works).

I know that I could just run something like:

Compress-Archive \tommc-pc\c$\users\tommc -DestinationPath c:\windows\temp\tommc_windows_home.zip

...But I'd like to make it more user friendly, so the user would enter the UNC path for the source path and folder that's to be compressed, as well as a prompt for the full Destination path and filename of the .zip file on the machine I'm running the script from.

Might you be so kind as to provide some guidance on how I could accomplish this?

Windows for business | Windows Server | User experience | PowerShell
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Anonymous
    2021-03-25T06:40:45.757+00:00

    Hi,

    You can store the paths in some variables

    $source = Read-Host -Prompt 'Enter the source path'  
    $destination = Read-Host -Prompt 'Enter the destination path'  
    Compress-Archive -Path $source -DestinationPath $destination  
    

    Best Regards,
    Ian Xue

    ============================================

    If the Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.