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

Increase memory allowance for WMI

Run: wbemtest.exe >> click Connect >> Namespace = root >> Connect >> click Enum Instances…

Add a Domain Group to Local Administrators Group

$checkGroup="Administrators" $addMember="KIMCONNECT\Desktop Admins" # Dynamic Credential $who = whoami if ($who.substring($who.length-2, 2) -eq "-admin"){$username=$who;} else…

How to Install Windows Dot Net 3.5 & 4.5

Run these commands to check dot net 3.5: PS C:\Windows\system32> import-module servermanagerPS C:\Windows\system32> get-windowsfeature web-asp-netDisplay…
Other project: DragonCoin.com