create new folder and extract files to the folder

i require help to create folder and extract selected file to the folder

 

please look into the script and please help to fix. and i’m trying create folder in the format like eg: report_09_10_2020

 

 

$7ZipPath = ‘“C:\Program Files\7-Zip\7z.exe”’

$FileBrowser = New-Object System.Windows.Forms.OpenFileDialog -Property @{

Filter = ‘Zip files (.zip)|.Zip|All files (.)|.

Title = ‘Select the Zip file file’

}

$FileSelected = $FileBrowser.ShowDialog()

if ($FileSelected -ne ‘OK’)

{

Write-Host “File not selected” -ForegroundColor Red

return

}

else

{

$ZipFile = $FileBrowser.Filename

Write-Host “file $ZipFile”

}

$ZipFilePassword = Read-Host “Please enter the Password” -AsSecureString
$reportdate = read-host “Please enter report date (dd_mm_yyyy)”

$Destination = “Path\Report_$reportdate”

$BSTR = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($ZipFilePassword)

$PlainTextPassword = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)

$Command = “& $7ZipPath e -‘o$Destination’ -y -tzip -p$PlainTextPassword ‘$ZipFile’”

 

Invoke-Expression -Command $Command

Can you provide more details about what’s not working?

A couple of thoughts:

Does 7Zip create the folder if it doesn’t exist? If not, you might want to check if the destination exists using Test-Path and if it doesn’t exist, make the folder using New-Item.

I think you also might need a space between the switches and the variable name but that might just be the way you’ve copied and pasted the code.