question

agfreesafety3-6849 avatar image
0 Votes"
agfreesafety3-6849 asked IanXue-MSFT answered

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

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-server-powershell
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

IanXue-MSFT avatar image
0 Votes"
IanXue-MSFT answered

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.


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.