Please assist. I would like to create a Powershell script that would unzip file extension *.zip. The file name contains PB or HB along with date and month [For example: PBSTMT20141126.zip and HBSTMT20141126.zip. Upon unzipping the files they should go in a folder that corresponds with name and date (See example 1). If folders don’t exist the script would create the folder ‘Year’ and subfolder ‘Month’. Next, create a log file to \\server\share\CHRMC\PB or HB\ZipArchives named ‘UNZIP_PByear,month’ and ‘UNZIP_HByear,month’ writing all files that have extracted from .zip.
Example 1:
PBSTMT20141126.zip located in $src \\server\share\CHRMC\PB\Archives would need to unzip to \\server\share\CHRMC\PB\2014\11
[If folder(s) 2014\11 are not created they would need to be created]
• Create a log file writing files being extracted from zip
And
HBSTMT20141126.zip located in $src \\server\share\CHRMC\HB\Archives would need to unzip to
\\server\share\CHRMC\HB\2014\11
[If folder(s) 2014\11 are not created they would need to be created]
• Create a log file writing files being extracted from zip
I have this code which unzips a file yet I don't know how to break down in detail for example above:
# Replace with source ZIP file
$zipfilename="C:\StatementsTest\CHRMC\HB\Archives\HBSTMT20141120.ZIP";
# Replace with target folder
$destination=”C:\StatementsTest\CHRMC\HB\2014\11";
# Test if the zip file exists
if(test-path($zipfilename))
{
$shellApplication = new-object -com shell.application
$zipPackage = $shellApplication.NameSpace($zipfilename)
$destinationFolder = $shellApplication.NameSpace($destination)
$destinationFolder.CopyHere($zipPackage.Items())
}
else
{
echo "The source ZIP file does not exist";
}