Write-Zip files
The other day I was trying to use the PowerShell Community Extensions (PSCX) Write-Zip cmdlet to archive my local scripts folder, but when I opened the compressed file I could see that all the folders, and subfolders were stored at the root level even though I didn't use the -FlattenPaths parameter. This is the command I used:
PS > dir d:\scripts -rec | Write-Zip -level 9 -IncludeEmptyDirectories -OutputPath D:\Scripts.zip
Why is that? Unfortunately, when binding from input objects, Write-Zip doesn't know how to preserve the paths in a reliable way. Files coming in could be coming from different parts of the filesystem and there is no way to represent all of the source files in a single relative hierarchy (which is how zips store things) because the files might be coming from different drives, from folders inside other folders, etc.
But there is a way around it:
PS > Write-Zip -level 9 -IncludeEmptyDirectories -Path d:\scripts -OutputPath D:\Scripts.zip
That way, Write-Zip knows that the source is from a single hierarchy and it can definitely represent that in the zip. In addition, it will recurse all subfolders too, if you specify a folder to -OutputPath.
I want to thank Oisin, a fellow MVP and one of the master minds behind the PSCX project, for helping me out with it. You should definitely try PSCX if you haven't so far!
List of cmdlets in PSCX v1.1
ConvertFrom-Base64 ConvertTo-Base64
ConvertTo-MacOs9LineEnding ConvertTo-UnixLineEnding
ConvertTo-WindowsLineEnding Convert-Xml
Disconnect-TerminalSession Export-Bitmap
Format-Byte Format-Hex
Format-Xml Get-ADObject
Get-Clipboard Get-DhcpServer
Get-DomainController Get-ExportedType
Get-FileVersionInfo Get-ForegroundWindow
Get-Hash Get-MountPoint
Get-PEHeader Get-Privilege
Get-PSSnapinHelp Get-Random
Get-ReparsePoint Get-ShortPath
Get-TabExpansion Get-TerminalSession
Import-Bitmap Join-String
New-Hardlink New-Junction
New-Shortcut New-Symlink
Out-Clipboard Ping-Host
Remove-MountPoint Remove-ReparsePoint
Resize-Bitmap Resolve-Assembly
Resolve-Host Select-Xml
Send-SmtpMail Set-Clipboard
Set-FileTime Set-ForegroundWindow
Set-Privilege Set-VolumeLabel
Split-String Start-Process
Start-TabExpansion Stop-TerminalSession
Test-Assembly Test-Xml
Write-BZip2 Write-Clipboard
Write-GZip Write-Tar