Is there a script example that would show how to include empty directories into the final zip file?
Thanks
Technology Tips and News
Is there a script example that would show how to include empty directories into the final zip file?
Thanks
PSCX has Write-Zip, which I believe handles folder structure:
I haven't used this module personally, so I'm not sure if this will meet your needs.
Prewritten scripts can be found here:
http://gallery.technet.microsoft.com/scriptcenter
Otherwise start playing around with the ZipFile class:
https://msdn.microsoft.com/en-us/library/system.io.compression.zipfile%28v=vs.110%29.aspx
I downloaded it from http://pscx.codeplex.com and ran installation. What do I next to have it working because I tried help write-zip and nothing came back.
Thanks
But I dont want to use any third party software. My question is about PS.
There is no native support for ZIPs in PowerShell. You must write your own from scratch or use a prewritten script.
I downloaded it from http://pscx.codeplex.com and ran installation. What do I next to have it working because I tried help write-zip and nothing came back.
Thanks
If you mean this crap:
two of three links dont work.
Those links are a bit old.
Use these:
https://msdn.microsoft.com/en-US/library/ms229284(v=vs.80).aspx
https://msdn.microsoft.com/en-US/library/ms229335(v=vs.80).aspx
You have to do much of this for yourself. Thisis a technical forum and assumes a certain amount of technical knowledge of Windows an computing,
This requires Net FrameWork 4.5
add-type -AssemblyName System.IO.Compression.FileSystem $folder='c:\test' $archive='c:\temp2\test.zip' [System.IO.Compression.ZipFile]::CreateFromDirectory($folder,$archive,'Optimal',$true)
I downloaded it from http://pscx.codeplex.com and ran installation. What do I next to have it working because I tried help write-zip and nothing came back.
Thanks
Here is what I got so far:
Write-Output "Packaging a Package" #get output directory $outDir=$args[0] $shell = new-object -com shell.application $aZipPath = "${outDir}Installs\aZip.zip" #the second part sets the content type of the file to zip set-content $aZipPath ("PK" + [char]5 + [char]6 + ("$([char]0)" * 18)) $ZipFile = $shell.NameSpace($aZipPath) Get-ChildItem "${outDir}_PublishedWebsites\a_Package\Archive"| foreach({ $copyfile = $_; $ZipFile.CopyHere($copyfile.fullname); #Due to some limitations with CopyHere method, we need to sleep until the file has finished copying. #If not, we will get an error and some files will not be copied. while (!($ZipFile.Items() | Where-Object { $_.Path -Match $copyfile.Name})) { Start-Sleep -m 500}; }); Write-Output "Complete"Kind of works.... Can't zip empty directories.
The shell was never intended to be used this way. It does not work reliably and will never work reliably.
The following works under all circumstances:
add-type -AssemblyName System.IO.Compression.FileSystem $folder='c:\test' $archive='c:\temp2\test.zip' [System.IO.Compression.ZipFile]::CreateFromDirectory($folder,$archive,'Optimal',$true)
I am getting:
Add-Type : Cannot add type. The assembly 'System.IO.Compression.FileSystem' could not be found.
I am not a c# developer, sorry.
Are you running PowerShell V1 on XP?
No, I am running it on Windows 7. This is my command line:
PS C:\Program Files (x86)\Microsoft Visual Studio 11.0> powershell -noexit -ExecutionPolicy ByPass "& ""d:\Package.ps1"""
I am getting:
Add-Type : Cannot add type. The assembly 'System.IO.Compression.FileSystem' could not be found.
I am not a c# developer, sorry.
This has already been mentioned, but I'm going to point it out again.
This requires a minimum of .Net 4.5.
Here are all versions being installed:
C:\Program Files (x86)\Microsoft Visual Studio 11.0>wmic /namespace:\\root\cimv path win32_product where "name like '%%.NET%%'" get versionOpen a PowerShell console and type this line only:
Add-Type -AssemblyName System.IO.Compression.FileSystem
What happens?
Windows PowerShell
Copyright (C) 2009 Microsoft Corporation. All rights reserved.
PS H:\> Add-Type -AssemblyName System.IO.Compression.FileSystem
Add-Type : Cannot add type. The assembly 'System.IO.Compression.FileSystem' could not be found.
At line:1 char:9
+ Add-Type <<<< -AssemblyName System.IO.Compression.FileSystem
+ CategoryInfo : ObjectNotFound: (System.IO.Compression.FileSystem:String) [Add-Type], Exception
+ FullyQualifiedErrorId : ASSEMBLY_NOT_FOUND,Microsoft.PowerShell.Commands.AddTypeCommand
Add-Type : Cannot add type. One or more required assemblies are missing.
At line:1 char:9
+ Add-Type <<<< -AssemblyName System.IO.Compression.FileSystem
+ CategoryInfo : InvalidData: (:) [Add-Type], InvalidOperationException
+ FullyQualifiedErrorId : ASSEMBLY_LOAD_ERRORS,Microsoft.PowerShell.Commands.AddTypeCommand
PS H:\>
Am I doing it correctly at all?
Do yourself a huge favor and upgrade to WMF4. v4 is much better th
No, I am running it on Windows 7. This is my command line:
PS C:\Program Files (x86)\Microsoft Visual Studio 11.0> powershell -noexit -ExecutionPolicy ByPass "& ""d:\Package.ps1"""
What versio of PowerShell?
You have Net 4.5. Perhaps you are missing service packs..
It won't work with PowerShell V2.
This - "Copyright (C) 2009 Microsoft Corporation. All rights reserved." says you are running an old version of PowerShell. You need to upgrade.Windows PowerShell
Copyright (C) 2009 Microsoft Corporation. All rights reserved.
PS H:\> Add-Type -AssemblyName System.IO.Compression.FileSystem
Add-Type : Cannot add type. The assembly 'System.IO.Compression.FileSystem' could not be found.
At line:1 char:9
+ Add-Type <<<< -AssemblyName System.IO.Compression.FileSystem
+ CategoryInfo : ObjectNotFound: (System.IO.Compression.FileSystem:String) [Add-Type], Exception
+ FullyQualifiedErrorId : ASSEMBLY_NOT_FOUND,Microsoft.PowerShell.Commands.AddTypeCommand
Add-Type : Cannot add type. One or more required assemblies are missing.
At line:1 char:9
+ Add-Type <<<< -AssemblyName System.IO.Compression.FileSystem
+ CategoryInfo : InvalidData: (:) [Add-Type], InvalidOperationException
+ FullyQualifiedErrorId : ASSEMBLY_LOAD_ERRORS,Microsoft.PowerShell.Commands.AddTypeCommand
PS H:\>Am I doing it correctly at all?
It won't work with PowerShell V2.
PowerShell V3 and later allow loading almost any version of any assembly with no conflict although you cannot load two type of different versions without adjusting for this. V2 only allows V2 and compatible earlier assemblies. I do not remember what was changed to make this happen.
4.5 compression is very useful and easy to use. V5 will have full compression support with real CmdLets.