{"id":112,"date":"2017-06-30T10:34:39","date_gmt":"2017-06-30T01:34:39","guid":{"rendered":"https:\/\/jidouka.work\/?p=112"},"modified":"2017-07-04T13:54:29","modified_gmt":"2017-07-04T04:54:29","slug":"%e7%94%bb%e5%83%8f%e3%83%80%e3%82%a6%e3%83%b3%e3%83%ad%e3%83%bc%e3%83%80%e3%83%bc%e3%82%92%e4%bd%9c%e3%82%8bpowershell","status":"publish","type":"post","link":"https:\/\/jidouka.work\/?p=112","title":{"rendered":"\u753b\u50cf\u30c0\u30a6\u30f3\u30ed\u30fc\u30c0\u30fc\u3092\u4f5c\u308b[PowerShell]"},"content":{"rendered":"<p>Windows\u306b\u4ed8\u5c5e\u3057\u3066\u3044\u308bPowerShell\u3067\u306fHTML\u30da\u30fc\u30b8\u306e\u4e2d\u8eab\u306e\u8981\u7d20\u3092\u7c21\u5358\u306b\u53d6\u308a\u51fa\u305b\u308b\u6a5f\u80fd\u304c\u8c4a\u5bcc\u3067\u3059\u3002<br \/>\n\u305d\u306e\u6a5f\u80fd\u3092\u5229\u7528\u3057\u3066\u30da\u30fc\u30b8\u306b\u542b\u307e\u308c\u308b\u30ea\u30f3\u30af\u5148\u306e\u753b\u50cf\u3092\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3059\u308b\u30b9\u30af\u30ea\u30d7\u30c8\u3092\u4f5c\u3063\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n<h2>PowerShell\u3067\u5f15\u6570\u3092\u53d7\u3051\u53d6\u308b<\/h2>\n<p>PowerShell\u3067\u5f15\u6570\u3092\u53d7\u3051\u53d6\u308b\u306b\u306f&#8221;Param(arg1, arg2, &#8230;)&#8221;\u3092\u4f7f\u7528\u3057\u307e\u3059\u3002<br \/>\n\u4eca\u56de\u306fURL\u30921\u3064\u3060\u3051\u53d7\u3051\u53d6\u308b\u3068\u3044\u3046\u3053\u3068\u3067\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u3057\u307e\u3057\u305f\u3002<\/p>\n<p>Param( $url )<\/p>\n<h2>\u6307\u5b9a\u3057\u305fHTML\u30da\u30fc\u30b8\u3092\u53d6\u5f97<\/h2>\n<p>PowerShell\u3067HTML\u30da\u30fc\u30b8\u3092\u53d6\u5f97\u3059\u308b\u305f\u3081\u306b\u306f&#8221;Invoke-WebRequest&#8221;\u3092\u4f7f\u7528\u3057\u307e\u3059\u3002<br \/>\n\u4eca\u56de\u306f\u5f15\u6570$url\u3067URL\u3092\u53d7\u3051\u53d6\u3063\u3066\u3044\u308b\u305f\u3081\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u6307\u5b9a\u3057\u307e\u3059\u3002<br \/>\n$page\u306b\u306f\u53d6\u5f97\u3057\u305f\u30da\u30fc\u30b8\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u304c\u5165\u308a\u307e\u3059\u3002<\/p>\n<p>$page = Invoke-WebRequest $url<\/p>\n<h2>\u30da\u30fc\u30b8\u306b\u542b\u307e\u308c\u308b\u30ea\u30f3\u30af\u3092\u8abf\u3079\u308b<\/h2>\n<p>\u53d6\u5f97\u3057\u305f\u30da\u30fc\u30b8\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306b\u306f\u30ea\u30f3\u30af\u304c\u542b\u307e\u308c\u3066\u3044\u308b\u305f\u3081\u3001\u30ea\u30f3\u30af\u305d\u308c\u305e\u308c\u306b\u5bfe\u3057\u3066\u30ea\u30f3\u30af\u304c\u753b\u50cf\u3078\u306e\u30ea\u30f3\u30af\u304b\u3069\u3046\u304b\u3092\u8abf\u3079\u307e\u3059\u3002<br \/>\nforeach($\u5909\u6570 in $\u914d\u5217) \u3092\u5229\u7528\u3059\u308b\u3068\u8907\u6570\u3042\u308b\u5909\u6570\u4e00\u500b\u4e00\u500b\u3092\u53d6\u308a\u51fa\u3057\u3066\u51e6\u7406\u3092\u884c\u3048\u307e\u3059\u3002<\/p>\n<p>foreach($linkElement in $page.Links.href)<\/p>\n<p>\u5168\u3066\u306e\u30ea\u30f3\u30af\u3092\u53d6\u308a\u51fa\u3057\u3066\u51e6\u7406\u3092\u884c\u3063\u305f\u3089\u30eb\u30fc\u30d7\u3092\u629c\u3051\u307e\u3059\u3002<\/p>\n<h2>\u30ea\u30f3\u30af\u304b\u3089\u30d5\u30a1\u30a4\u30eb\u540d\u3092\u53d6\u308a\u51fa\u3059<\/h2>\n<p>\u30ea\u30f3\u30af\u304b\u3089\u30d5\u30a1\u30a4\u30eb\u540d\u3092\u53d6\u308a\u51fa\u3059\u305f\u3081\u306b\u306f\u3001\u30d1\u30b9\u306e\u6587\u5b57\u5217\u306e\u3046\u3061\u6700\u5f8c\u306e\u8981\u7d20\u3092\u53d6\u308a\u51fa\u3059\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<br \/>\n\u305d\u306e\u305f\u3081\u306b\u306fSplit-Path\u3092\u4f7f\u7528\u3057\u307e\u3059\u3002<br \/>\nSplit-Path\u306b\u306f\u30aa\u30d7\u30b7\u30e7\u30f3\u304c\u8272\u3005\u3042\u308a\u307e\u3059\u304c\u3001\u4eca\u56de\u306f\u6700\u5f8c\u306e\u8981\u7d20(Leaf)\u3092\u53d6\u308a\u51fa\u3057\u307e\u3059\u3002<\/p>\n<p>$fileName = Split-Path $linkElement -Leaf<\/p>\n<p>Split-Path\u306e\u8a73\u3057\u3044\u8aac\u660e\u306fMSDN\u306b\u3042\u308a\u307e\u3059\u3002<\/p>\n<p>Split-Path<br \/>\n<a href=\"https:\/\/msdn.microsoft.com\/en-us\/powershell\/reference\/5.1\/microsoft.powershell.management\/split-path\">https:\/\/msdn.microsoft.com\/en-us\/powershell\/reference\/5.1\/microsoft.powershell.management\/split-path<\/a><\/p>\n<h2>\u30d5\u30a1\u30a4\u30eb\u540d\u304b\u3089\u62e1\u5f35\u5b50\u3092\u53d6\u5f97<\/h2>\n<p>\u30d5\u30a1\u30a4\u30eb\u540d\u304b\u3089\u62e1\u5f35\u5b50\u3092\u53d6\u5f97\u3059\u308b\u305f\u3081\u306b\u306fSystem.IO\u540d\u524d\u7a7a\u9593\u306ePath\u30af\u30e9\u30b9\u3092\u5229\u7528\u3057\u307e\u3059\u3002<\/p>\n<p>Path \u30af\u30e9\u30b9 (System.IO)<br \/>\n<a href=\"https:\/\/msdn.microsoft.com\/ja-jp\/library\/system.io.path(v=vs.110).aspx\">https:\/\/msdn.microsoft.com\/ja-jp\/library\/system.io.path(v=vs.110).aspx<\/a><\/p>\n<p>[IO.Path]::GetExtension($string)<\/p>\n<p>\u3053\u306ePath\u30af\u30e9\u30b9\u306b\u306f\u62e1\u5f35\u5b50\u3092\u53d6\u5f97\u3059\u308b\u4ee5\u5916\u306b\u3082\u69d8\u3005\u306a\u64cd\u4f5c\u3092\u30d1\u30b9\u306e\u6587\u5b57\u5217\u306b\u5bfe\u3057\u3066\u884c\u3046\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<h2>\u62e1\u5f35\u5b50\u304c\u753b\u50cf\u306e\u62e1\u5f35\u5b50\u3067\u3042\u308b\u304b\u5224\u5b9a<\/h2>\n<p>\u666e\u901a\u306bif\u6587\u3067\u884c\u3063\u3066\u307e\u3059\u3002PowerShell\u306f\u8272\u3005\u3068\u6a5f\u80fd\u304c\u3042\u308b\u305f\u3081\u3001\u6587\u5b57\u5217\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u81ea\u4f53\u306b\u753b\u50cf\u306e\u62e1\u5f35\u5b50\u3067\u3042\u308b\u304b\u3069\u3046\u304b\u5224\u5b9a\u3059\u308b\u6a5f\u80fd\u304c\u3042\u308b\u304b\u3068\u8003\u3048\u305f\u306e\u3067\u3059\u304c\u3001\u4eca\u306e\u6240\u898b\u3064\u304b\u3063\u3066\u307e\u305b\u3093\u3002\u305d\u306e\u305f\u3081\u753b\u50cf\u306e\u62e1\u5f35\u5b50\u3054\u3068\u306bor\u3067\u7e4b\u3052\u308b\u3053\u3068\u306b\u3057\u307e\u3057\u305f\u3002<\/p>\n<p>if ( $extension -eq &#8220;.jpg&#8221; -or $extension -eq &#8220;.png&#8221;)<\/p>\n<h2>\u753b\u50cf\u306e\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9<\/h2>\n<p>\u307e\u305fInvoke-WebRequest\u3067\u753b\u50cf\u306eURL\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002<\/p>\n<p>Invoke-WebRequest $linkElement -OutFile $fileName<\/p>\n<p>\u305f\u3060\u3057\u4eca\u56de\u306f\u30d5\u30a1\u30a4\u30eb\u3068\u3057\u3066\u51fa\u529b\u3059\u308b\u5fc5\u8981\u304c\u3042\u308b\u305f\u3081 -OutFile\u30aa\u30d7\u30b7\u30e7\u30f3\u3092\u4f7f\u7528\u3057\u3001\u5f15\u6570\u3068\u3057\u3066\u30d5\u30a1\u30a4\u30eb\u540d\u3092\u6307\u5b9a\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<h2>PowerShell\u30b9\u30af\u30ea\u30d7\u30c8\u3092\u4fdd\u5b58\u3057\u3066\u5b9f\u884c<\/h2>\n<p>PowerShell\u30b9\u30af\u30ea\u30d7\u30c8\u306f\u30d5\u30a1\u30a4\u30eb\u540d\u306b.ps1\u62e1\u5f35\u5b50\u304c\u3064\u304d\u307e\u3059\u3002<\/p>\n<p>\u8a66\u3057\u306bURL\u3092\u6307\u5b9a\u3057\u3066\u753b\u50cf\u3092\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3057\u3066\u307f\u307e\u3059\u3002<br \/>\n\u5b9f\u884c\u3059\u308b\u305f\u3081\u306b\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u5148\u982d\u306b.\\\u3092\u3064\u3051\u307e\u3059\u3002<\/p>\n<p>.\\download_images.ps1 https:\/\/jidouka.work\/?p=29<\/p>\n<p><a href=\"https:\/\/jidouka.work\/wp-content\/uploads\/2017\/06\/8ad606da3a8495e7970f91b1eb094739.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-115\" src=\"https:\/\/jidouka.work\/wp-content\/uploads\/2017\/06\/8ad606da3a8495e7970f91b1eb094739-300x21.jpg\" alt=\"\" width=\"300\" height=\"21\" srcset=\"https:\/\/jidouka.work\/wp-content\/uploads\/2017\/06\/8ad606da3a8495e7970f91b1eb094739-300x21.jpg 300w, https:\/\/jidouka.work\/wp-content\/uploads\/2017\/06\/8ad606da3a8495e7970f91b1eb094739-768x52.jpg 768w, https:\/\/jidouka.work\/wp-content\/uploads\/2017\/06\/8ad606da3a8495e7970f91b1eb094739-1024x70.jpg 1024w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>\u7d50\u679c\u3001\u753b\u50cf\u30d5\u30a1\u30a4\u30eb\u304c\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3055\u308c\u3066\u4fdd\u5b58\u3055\u308c\u307e\u3057\u305f\u3002<\/p>\n<p><a href=\"https:\/\/jidouka.work\/wp-content\/uploads\/2017\/06\/c8e9f566cc219fb1bd983ff828bbaf65.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/jidouka.work\/wp-content\/uploads\/2017\/06\/c8e9f566cc219fb1bd983ff828bbaf65-300x77.jpg\" alt=\"\" width=\"300\" height=\"77\" class=\"alignnone size-medium wp-image-118\" srcset=\"https:\/\/jidouka.work\/wp-content\/uploads\/2017\/06\/c8e9f566cc219fb1bd983ff828bbaf65-300x77.jpg 300w, https:\/\/jidouka.work\/wp-content\/uploads\/2017\/06\/c8e9f566cc219fb1bd983ff828bbaf65-768x196.jpg 768w, https:\/\/jidouka.work\/wp-content\/uploads\/2017\/06\/c8e9f566cc219fb1bd983ff828bbaf65-1024x262.jpg 1024w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>\u4eca\u56de\u306e\u30b3\u30fc\u30c9\u3067\u3059\u3002<\/p>\n<figure class=\"jd-code\"><button type=\"button\" class=\"jd-code-copy\">\u30b3\u30d4\u30fc<\/button><pre><code class=\"language-powershell\">Param( $url )\r\n\r\n#\u5f15\u6570\u306e\u30a2\u30c9\u30ec\u30b9\u306eWeb\u30da\u30fc\u30b8\u3092\u53d6\u5f97\r\n$page = Invoke-WebRequest $url\r\n\r\n#Link\u5148\u306e\u753b\u50cf\u3092\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\r\nforeach($linkElement in $page.Links.href) {\r\n\r\n    # \u30d1\u30b9\u306e\u6700\u5f8c\u306e\u6587\u5b57\u5217\u3092\u30d5\u30a1\u30a4\u30eb\u540d\u3068\u3057\u3066\u53d6\u5f97\r\n    $fileName = Split-Path $linkElement -Leaf\r\n\r\n    #\u30d5\u30a1\u30a4\u30eb\u540d\u304b\u3089\u62e1\u5f35\u5b50\u3092\u53d6\u5f97\r\n    $extension = [IO.Path]::GetExtension($filename)\r\n\r\n    #\u62e1\u5f35\u5b50\u304c&quot;.jpg&quot;\u3082\u3057\u304f\u306f&quot;.png&quot;\u306e\u5834\u5408\r\n    if ( $extension -eq &quot;.jpg&quot; -or $extension -eq &quot;.png&quot;) {\r\n\r\n        #\u30ea\u30f3\u30af\u5148\u306e\u30d5\u30a1\u30a4\u30eb\u3092\u53d6\u5f97\u3057\u3066\u30d5\u30a1\u30a4\u30eb\u540d\u3067\u4fdd\u5b58\r\n        Invoke-WebRequest $linkElement -OutFile $fileName\r\n    }\r\n}<\/code><\/pre><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>Windows\u306b\u4ed8\u5c5e\u3057\u3066\u3044\u308bPowerShell\u3067\u306fHTML\u30da\u30fc\u30b8\u306e\u4e2d\u8eab\u306e\u8981\u7d20\u3092\u7c21\u5358\u306b\u53d6\u308a\u51fa\u305b\u308b\u6a5f\u80fd &#8230; <\/p>\n","protected":false},"author":1,"featured_media":118,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8,7],"tags":[],"class_list":["post-112","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-powershell","category-windows"],"_links":{"self":[{"href":"https:\/\/jidouka.work\/index.php?rest_route=\/wp\/v2\/posts\/112","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jidouka.work\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jidouka.work\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jidouka.work\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jidouka.work\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=112"}],"version-history":[{"count":4,"href":"https:\/\/jidouka.work\/index.php?rest_route=\/wp\/v2\/posts\/112\/revisions"}],"predecessor-version":[{"id":145,"href":"https:\/\/jidouka.work\/index.php?rest_route=\/wp\/v2\/posts\/112\/revisions\/145"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/jidouka.work\/index.php?rest_route=\/wp\/v2\/media\/118"}],"wp:attachment":[{"href":"https:\/\/jidouka.work\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=112"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jidouka.work\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=112"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jidouka.work\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=112"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}