So, I'm attempting to read in a zip file from a directory, and unzip that to a tmp location. The problem is that powershell seems to be misinterpreting the quotes and not writing out the value of the $copyLocation variable. Instead, it is copying the files to [currentDirectory]\$copyLocation. I'm hoping you all can help. I'm new to Powershell, and this is only a piece of the script I have to write to take over our build automation. Thank you in advance.
By the way, hosts is an XmlElement which we are iterating over. So, we're deploying this zip file to a location on a number of hosts specified in an xml configuration file.
function copyWebappToDestination($copyWebappFrom,$to,$hosts){
foreach( $it in $hosts ){
Write-Host "Deploying webapp" $webapps.webappName "to" $it.hostIp "at" $it.to
setUpDirectories
foreach($file in $filelocation){
if($file.name.ToString() -eq "Web.Main.zip"){
$filename = $file.name.ToString()
$hostIp = $it.hostIp
$fileDest = $file.FullName
#unzip the files
& '7z' x ""$fileDest"" -o""$copyLocation"" -y -r
break
}
}
}
The weirdest part, is that I wrote out the command
& '7z' x "C:\MoveToProduction\SM\PROD\Web.Main.zip" -o"C:\MoveToProduction\SM\PROD\tmp" -y -r"
And ran that from a Powershell console, and it worked just fine. It just doesn't work from within the context of a script.
So, I gave up trying to get the call operator working. Basically, what I ended up settling on was the command:
Invoke-Expression -command "cmd /C '7z x `"$fileDest`" -o`"$copyLocation`" -y -r'"
So, I gave up trying to get the call operator working. Basically, what I ended up settling on was the command:
Invoke-Expression -command "cmd /C '7z x `"$fileDest`" -o`"$copyLocation`" -y -r'"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With