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

PowerShell: Check Windows Computers for Specific KB’s

# Check for specific KBs $kbs='KB5010790','KB5010419' $computernames=@('WINDOWS001','WINDOWS002') $regexIP = [regex] "\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b" $names=foreach($computername in $computernames){ if($computername…

How To Recover SQLSERVER Service from Being Unable to Start

# startSqlService.ps1 # special provision to deal with SQL Server not starting up due to…

Quick PowerShell Cmdlet to Move Computer Object

$computername='SomeComputerName' $targetOU='OU=Computers,DC=kimconnect,DC=com' Move-ADObject -Identity (Get-ADComputer $computername).objectguid -TargetPath $targetOU
Other project: DragonCoin.com