This is one of my first powershell scripts and I can't make it work. I can't pass "c:\" as a destination folder.
My script:
$sourceFolder = "C:\Temp"
$winZipExe = "C:\Program Files\WinZip\WZUNZIP.EXE"
$destinationFolder = "c:\"
$passwordCommand
# Ask the user for a password
$password = Read-Host -Prompt "Please enter the password for the .zipx files"
$passwordCommand = "-s" + $password.ToString()
Get-ChildItem -Path $sourceFolder -Filter *.zipx | ForEach-Object {
$zipxFile = $_.FullName
$zipxFileName = $_.BaseName
$outputFolder = (Resolve-Path $destinationFolder) ; $destinationFolder
New-Item -ItemType Directory -Path $outputFolder -Force
& $winZipExe -e -d $passwordCommand $zipxFile #$outputFolder
}
My error:
c:\
New-Item : The path is not of a legal form.
At C:\Users\Nenad A. Dragic\Desktop\Unzip1.ps1:14 char:5
+ New-Item -ItemType Directory -Path $outputFolder -Force
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (C:\:String) [New-Item], ArgumentException
+ FullyQualifiedErrorId : CreateDirectoryArgumentError,Microsoft.PowerShell.Commands.NewItemCommand
I have tested with this:
$outputFolder = ""
Done a lot of different arguments from Google, Stackoverflow and chatGPT, but can't make it work.
My zipx files contains a folder with the files in it and I would like it to unzip to C:\
You probably don't have permissions to write directly to C Drive. Try changing
$destinationFolderto something depper. I.e.C:\"YOUR_USERNAME".