Posted On July 13, 2021

PowerShell: Download and Expand Zip File – Legacy Compatible

kimconnect 0 comments
blog.KimConnect.com >> Windows >> PowerShell: Download and Expand Zip File – Legacy Compatible
        function downloadFile{
            param(
                $url,
                $tempFolder="C:\Temp"
            )
            try{
                $fileName=split-path $url -leaf
                $tempFile = "$tempFolder\$fileName"
                try{[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12}catch{}
                New-Item -ItemType Directory -Force -Path $tempFolder
                $webclient = New-Object System.Net.WebClient
                $WebClient.DownloadFile($url,$tempFile)
                return $true
            }catch{
                write-warning $_
                return $false
            }
        }

        function expandZipfile($file,$destination){      
            $destination=if($destinatione){$destination}else{split-path $file -parent}
            try{
                Add-Type -AssemblyName System.IO.Compression.FileSystem
                [System.IO.Compression.ZipFile]::ExtractToDirectory($file, $destination)
            }catch{
                write-warning $_
            }
        }

            $downloaded=downloadFile "https://blog.kimconnect.com/wp-content/uploads/2019/08/emcopy.zip"
            if($downloaded){
                $destinationFolder="C:\Windows\System32"
                expandZipfile $destinationFile -Destination $destinationFolder
            }

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Post

How to Install RSA Radius Server

Configure firewall to NAT these ports for RSA:22 TCP49 TCP80 TCP161 UDP443 TCP1645 UDP1646 UDP1812…

Audit Logon Successes & Failures on All Domain Controllers

Issue: In a realistic situation, InfoSec would notify DBAdmins and SysAdmins of failed logon alerts…

Windows 2016 Cumulative Roll-up Install

Use this method to apply cumulative roll-ups that would not successfully apply via Automatic Updates:…