-3

I want to move users home folder to share drive who has left the company but before that I want to ZIP it using powershell script. Could you please suggest me or write me quick powershell script which ZIPs the folder and move to share drive creating a same folder name with zip file also same name in destination folder. For instance if source folder is C:\test and destination is \\share\test\

Thanks in Advance,

Taisbevalle
  • 246
  • 1
  • 9
  • 19
Bishnu
  • 17
  • 6
  • 2
    "or write me quick powershell script" ...sweet :D – Jaqueline Vanek Sep 02 '16 at 14:23
  • 1
    And just in case somebody takes this up, which version of PS did you actually want this written for? – shawnt00 Sep 02 '16 at 14:35
  • No one here will write your code for you, however these links should be helpful in working it out for yourself. [ZIP](https://blogs.technet.microsoft.com/heyscriptingguy/2015/03/09/use-powershell-to-create-zip-archive-of-folder/) [Copy](https://technet.microsoft.com/en-us/library/hh849793.aspx) If you give that a shot and are still having trouble post back with what you've attempted and what errors you are getting and we will be happy to help you work through them. – Mike Garuccio Sep 02 '16 at 14:46
  • Function Zip { Param ( [string]$zipFile , [string[]]$toBeZipped ) $CurDir = Get-Location Set-Location "C:\Program Files\7-zip\" .\7z.exe A -tzip $zipFile $toBeZipped | Out-Null Set-Location $CurDir } $Now = Get-Date $Days = "60" $TargetFolder = "\\share\test\" $LastWrite = $Now.AddDays(-$Days) $Files = Get-Childitem $TargetFolder -Recurse | Where {$_.LastWriteTime -le "$LastWrite"} $Files Zip \\share\test\TEST.zip $Files #If(Test-Path \\share\test\TEST.zip) #{ # Remove-Item $files #} – Bishnu Sep 02 '16 at 16:15

1 Answers1

1

There's a few ways to zip a folder:
Creating a zipped/compressed folder in Windows using Powershell or the command line

Creating a new folder is simple:

New-Item c:\folder -type directory

https://technet.microsoft.com/en-us/library/ee176914.aspx

And moving a file is also very simple too:

Move-Item c:\source\file.zip c:\destination

https://technet.microsoft.com/en-us/library/ee176914.aspx

Community
  • 1
  • 1
henrycarteruk
  • 12,708
  • 2
  • 36
  • 40
  • Hi JamesFunction Zip { Param ( [string]$zipFile , [string[]]$toBeZipped ) $CurDir = Get-Location Set-Location "C:\Program Files\7-zip\" .\7z.exe A -tzip $zipFile $toBeZipped | Out-Null Set-Location $CurDir } $Now = Get-Date $Days = "60" $TargetFolder = "\\share\test\" $LastWrite = $Now.AddDays(-$Days) $Files = Get-Childitem $TargetFolder -Recurse | Where {$_.LastWriteTime -le "$LastWrite"} $Files Zip \\share\test\TEST.zip $Files #If(Test-Path \\share\test\TEST.zip) #{ # Remove-Item $files #} – Bishnu Sep 02 '16 at 16:09