Skip to content

PowerShell ile dosya download (tr TR)

Emre Ozan Memis edited this page Oct 15, 2020 · 1 revision

Windows Server core kullananların çok sık kulandığı zaman zaman gui kullanıcılarının da hayatını kolaylaştıran PowerShell komutları ile http, https, ftp üzerindeki dosyaları indirip yükleme işlemini gerçekleştirebilirsiniz. Bu noktada tek ihtiyacınız olan dosyanızın bulunduğu internet linkini bilmeniz gerekeceltir. Ben genelde kendim için olduşturduğum komut kütüphanemde PowerShell komutları ile hazırladığım komutlarımla hızlı ve pratik bir şekilde dosyların indirme işlemini gerçekleştiriyorum.

 

Örneğin bir linkden dosya indirmek için aşağıdaki PowerShell scriptini kullanabilirsiniz.

 

PowerShell

powershell

$WebClient = New-Object System.Net.WebClient
$WebClient.DownloadFile("http://<download linkinizi yazınız>","C:\dosya isminiz.formatı")
$WebClient = New-Object System.Net.WebClient 
$WebClient.DownloadFile("http://<download linkinizi yazınız>","C:\dosya isminiz.formatı")

 

Örnek uygulama çıktısı için WAC (windows admin center) download edeceğim.

 

PowerShell

powershell

PS C:\Users\Administrator> $WebClient = New-Object System.Net.WebClient
PS C:\Users\Administrator> $WebClient.DownloadFile("http://aka.ms/WACDownload","C:\wac.msi")

PS C:\> dir


    Directory: C:\


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----       15.09.2018     10:19                PerfLogs
d-r---       22.07.2019     19:26                Program Files
d-----       20.06.2019     09:24                Program Files (x86)
d-r---       12.06.2019     07:38                Users
d-----       29.07.2019     09:52                Windows
-a----       12.08.2019     17:31       63909888 wac.msi


PS C:\>
PS C:\Users\Administrator> $WebClient = New-Object System.Net.WebClient 
PS C:\Users\Administrator> $WebClient.DownloadFile("http://aka.ms/WACDownload","C:\wac.msi") 
 
PS C:\> dir 
 
 
    Directory: C:\ 
 
 
Mode                LastWriteTime         Length Name 
----                -------------         ------ ---- 
d-----       15.09.2018     10:19                PerfLogs 
d-r---       22.07.2019     19:26                Program Files 
d-----       20.06.2019     09:24                Program Files (x86) 
d-r---       12.06.2019     07:38                Users 
d-----       29.07.2019     09:52                Windows 
-a----       12.08.2019     17:31       63909888 wac.msi 
 
 
PS C:\>

 

Script dışında bunu PowerShell komutu ile yapalım.

 

PowerShell

powershell

Invoke-WebRequest -Uri "<download linkini giriniz>" -OutFile "C:\dosya adiniz.formati"
Invoke-WebRequest -Uri "<download linkini giriniz>" -OutFile "C:\dosya adiniz.formati"
 Uygulamasını aşağıda görebilirsiniz bu örnekte de Microsoft üzerinden MS SQL 2017 download edeceğim.
JavaScript

js

PS C:\> Invoke-WebRequest -Uri "https://go.microsoft.com/fwlink/?linkid=853017" -OutFile "C:\sql2017.exe"

 Writing web request
    Writing request stream... (Number of bytes written: 1701728)




PS C:\> Invoke-WebRequest -Uri "https://go.microsoft.com/fwlink/?linkid=853017" -OutFile "C:\sql2017.exe" 
 
 Writing web request 
    Writing request stream... (Number of bytes written: 1701728) 
 
 
 
 
 
PowerShell

powershell

PS C:\> Invoke-WebRequest -Uri "https://go.microsoft.com/fwlink/?linkid=853017" -OutFile "C:\sql2017.exe"
PS C:\> dir


    Directory: C:\


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----       15.09.2018     10:19                PerfLogs
d-r---       22.07.2019     19:26                Program Files
d-----       20.06.2019     09:24                Program Files (x86)
d-r---       12.06.2019     07:38                Users
d-----       29.07.2019     09:52                Windows
-a----       12.08.2019     18:46        5325976 sql2017.exe
-a----       12.08.2019     17:31       63909888 wac.msi


PS C:\>
PS C:\> Invoke-WebRequest -Uri "https://go.microsoft.com/fwlink/?linkid=853017" -OutFile "C:\sql2017.exe" 
PS C:\> dir 
 
 
    Directory: C:\ 
 
 
Mode                LastWriteTime         Length Name 
----                -------------         ------ ---- 
d-----       15.09.2018     10:19                PerfLogs 
d-r---       22.07.2019     19:26                Program Files 
d-----       20.06.2019     09:24                Program Files (x86) 
d-r---       12.06.2019     07:38                Users 
d-----       29.07.2019     09:52                Windows 
-a----       12.08.2019     18:46        5325976 sql2017.exe 
-a----       12.08.2019     17:31       63909888 wac.msi 
 
 
PS C:\>
 Çalışmalarınız sırasında bir web sayfasının kaynak koduna ihtiyacınız olabilir bunun için powershell ile dosyayı txt olarak indirip görüntüleyebilirsiniz.
PowerShell

powershell

Invoke-WebRequest "web adresi" | Select-Object -ExpandProperty Content | Out-File "C:\dosya ismi.txt"
Invoke-WebRequest "web adresi" | Select-Object -ExpandProperty Content | Out-File "C:\dosya ismi.txt"
PowerShell

powershell

PS C:\> Invoke-WebRequest "http://emreozanmemis.com" | Select-Object -ExpandProperty Content | Out-File "C:\emreozanmemis.txt"
PS C:\> Invoke-WebRequest "http://emreozanmemis.com" | Select-Object -ExpandProperty Content | Out-File "C:\emreozanmemis.txt"
PowerShell

powershell

PS C:\> Invoke-WebRequest "http://emreozanmemis.com" | Select-Object -ExpandProperty Content | Out-File "C:\emreozanmemis.txt"
PS C:\> dir


    Directory: C:\


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----       15.09.2018     10:19                PerfLogs
d-r---       22.07.2019     19:26                Program Files
d-----       20.06.2019     09:24                Program Files (x86)
d-r---       12.06.2019     07:38                Users
d-----       29.07.2019     09:52                Windows
-a----       12.08.2019     18:48          96270 emreozanmemis.txt
-a----       12.08.2019     18:46        5325976 sql2017.exe
-a----       12.08.2019     17:31       63909888 wac.msi
PS C:\> Invoke-WebRequest "http://emreozanmemis.com" | Select-Object -ExpandProperty Content | Out-File "C:\emreozanmemis.txt" 
PS C:\> dir 
 
 
    Directory: C:\ 
 
 
Mode                LastWriteTime         Length Name 
----                -------------         ------ ---- 
d-----       15.09.2018     10:19                PerfLogs 
d-r---       22.07.2019     19:26                Program Files 
d-----       20.06.2019     09:24                Program Files (x86) 
d-r---       12.06.2019     07:38                Users 
d-----       29.07.2019     09:52                Windows 
-a----       12.08.2019     18:48          96270 emreozanmemis.txt 
-a----       12.08.2019     18:46        5325976 sql2017.exe 
-a----       12.08.2019     17:31       63909888 wac.msi
 İndirmeden de dosyayı PowerShell üzerind egörüntüleyebilirsiniz.
PowerShell

powershell

Invoke-WebRequest "http://www.emreozanmemis.com" -OutFile "file" -PassThru | Select-Object -ExpandProperty Content
Invoke-WebRequest "http://www.emreozanmemis.com" -OutFile "file" -PassThru | Select-Object -ExpandProperty Content
 
PowerShell

powershell

PS C:\> Invoke-WebRequest "http://www.emreozanmemis.com" -OutFile "file" -PassThru | Select-Object -ExpandProperty Content
    <!doctype html>
<html lang="tr" prefix="og: http://ogp.me/ns#">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link rel="profile" href="http://gmpg.org/xfn/11">
        <title>- Blog by Emre Ozan Memis</title>
        <style type="text/css">
                        body .primary-background,
            body button:hover,
            body button:focus,
            body input[type="button"]:hover,
            body input[type="reset"]:hover,
            body input[type="reset"]:focus,
            body input[type="submit"]:hover,
            body input[type="submit"]:focus,
            body .widget .social-widget-menu ul li,
            body .comments-area .comment-list .reply,
            body .slide-categories a:hover,
            body .slide-categories a:focus,
            body .widget .social-widget-menu ul li:hover a:before,
            body .widget .social-widget-menu ul li:focus a:before,
            body .ham,
            body .ham:before,
            body .ham:after,
            body .btn-load-more {
                background: #33363b;
            }

                        body .secondary-background,
            body .wp-block-quote,
            body button,
            body input[type="button"],
            body input[type="reset"],
            body input[type="submit"],
            body .widget.widget_minimal_grid_tab_posts_widget ul.nav-tabs li.active a,
            body .widget.widget_minimal_grid_tab_posts_widget ul.nav-tabs > li > a:focus,
            body .widget.widget_minimal_grid_tab_posts_widget ul.nav-tabs > li > a:hover,
            body .author-info .author-social > a:hover,
            body .author-info .author-social > a:focus,
            body .widget .social-widget-menu ul li a:before,
            body .widget .social-widget-menu ul li:hover,
            body .widget .social-widget-menu ul li:focus,
            body .moretag,
            body .moretag,
            body .thememattic-search-icon:before,
.
.
.
.
PS C:\> Invoke-WebRequest "http://www.emreozanmemis.com" -OutFile "file" -PassThru | Select-Object -ExpandProperty Content 
    <!doctype html> 
<html lang="tr" prefix="og: http://ogp.me/ns#"> 
    <head> 
        <meta charset="UTF-8"> 
        <meta name="viewport" content="width=device-width, initial-scale=1"> 
        <link rel="profile" href="http://gmpg.org/xfn/11"> 
        <title>- Blog by Emre Ozan Memis</title> 
        <style type="text/css"> 
                        body .primary-background, 
            body button:hover, 
            body button:focus, 
            body input[type="button"]:hover, 
            body input[type="reset"]:hover, 
            body input[type="reset"]:focus, 
            body input[type="submit"]:hover, 
            body input[type="submit"]:focus, 
            body .widget .social-widget-menu ul li, 
            body .comments-area .comment-list .reply, 
            body .slide-categories a:hover, 
            body .slide-categories a:focus, 
            body .widget .social-widget-menu ul li:hover a:before, 
            body .widget .social-widget-menu ul li:focus a:before, 
            body .ham, 
            body .ham:before, 
            body .ham:after, 
            body .btn-load-more { 
                background: #33363b; 
            } 
 
                        body .secondary-background, 
            body .wp-block-quote, 
            body button, 
            body input[type="button"], 
            body input[type="reset"], 
            body input[type="submit"], 
            body .widget.widget_minimal_grid_tab_posts_widget ul.nav-tabs li.active a, 
            body .widget.widget_minimal_grid_tab_posts_widget ul.nav-tabs > li > a:focus, 
            body .widget.widget_minimal_grid_tab_posts_widget ul.nav-tabs > li > a:hover, 
            body .author-info .author-social > a:hover, 
            body .author-info .author-social > a:focus, 
            body .widget .social-widget-menu ul li a:before, 
            body .widget .social-widget-menu ul li:hover, 
            body .widget .social-widget-menu ul li:focus, 
            body .moretag, 
            body .moretag, 
            body .thememattic-search-icon:before, 
. 
. 
. 
.
 
Powershell ile web üzerinde de işlerinizi hızlı ve pratik çözmek için basit örnekleri paylaşmaya devam edeceğim. Umarım yardımcı olmuştur.
Clone this wiki locally