{"id":2958,"date":"2020-01-17T12:07:54","date_gmt":"2020-01-17T03:07:54","guid":{"rendered":"http:\/\/anada.cloudfree.jp\/?p=2958"},"modified":"2020-01-17T12:07:54","modified_gmt":"2020-01-17T03:07:54","slug":"powershell%e8%a6%9a%e6%9b%b8-%e3%83%95%e3%82%a1%e3%82%a4%e3%83%ab%e6%93%8d%e4%bd%9c%e3%81%84%e3%82%8d%e3%81%84%e3%82%8d","status":"publish","type":"post","link":"http:\/\/anada.cloudfree.jp\/?p=2958","title":{"rendered":"PowerShell\u899a\u66f8 \u30d5\u30a1\u30a4\u30eb\u64cd\u4f5c\u3044\u308d\u3044\u308d"},"content":{"rendered":"<p>\u6700\u8fd1\u3001VBS\u3088\u308aPowerShell\u306e\u307b\u3046\u3092\u3088\u304f\u4f7f\u3046\u3088\u3046\u306b\u306a\u3063\u305f\u3002<br \/>\n\u30a4\u30b1\u3066\u306a\u3044\u3068\u3053\u308d\u306f\u591a\u3005\u3042\u308b\u3082\u306e\u306e\u3001\u30c7\u30d0\u30c3\u30b0\u3082\u3057\u3084\u3059\u3044\u306e\u3067\u4fbf\u5229\u3060\u3002<\/p>\n<p>\u30d5\u30a1\u30a4\u30eb\u64cd\u4f5c\u306e\u30a2\u30ec\u30b3\u30ec\u3092\u3053\u306e\u6295\u7a3f\u306b\u3044\u308d\u3044\u308d\u66f8\u304d\u8db3\u3057\u3066\u3044\u3053\u3046\u3068\u601d\u3046\u3002<br \/>\n\uff08\u30a2\u30ec\u30b3\u30ec\u3063\u3066\u3001\u6f22\u5b57\u3060\u3068\u300c\u5f7c\u662f\u300d\u3063\u3066\u66f8\u304f\u306e\u306d\u3002\u77e5\u3089\u3093\u304b\u3063\u305f\u3002\uff09<\/p>\n<p><big><strong>\u3010\u30d5\u30a1\u30a4\u30eb\u691c\u7d22\u3011<\/strong><\/big><br \/>\n\u4f8b\u3048\u3070\u3001\u300cC\u30c9\u30e9\u30a4\u30d6\u300d\u76f4\u4e0b\u306e\u30d5\u30a1\u30a4\u30eb\u3092\u6f01\u308a\u305f\u3044\u3068\u304d\u306f\u3053\u3093\u306a\u611f\u3058\u3002<br \/>\nGet-ChildItem\u306e\u623b\u308a\u5024\u3092\u300c \u300d(\u534a\u89d2\u30b9\u30da\u30fc\u30b9)\u3067Split\u3057\u3066\u3084\u308c\u3070\u3001\u30d5\u30a1\u30a4\u30eb\u540d\u306e\u30ea\u30b9\u30c8\u3092\u53d6\u5f97\u3067\u304d\u308b\u3002<\/p>\n<pre>\r\n$dir = \"C:\\\";\r\n$files = Get-ChildItem $dir;\r\n$files_arr = $files -split \" \";\r\n<\/pre>\n<p><big><strong>\u3010\u30d5\u30a9\u30eb\u30c0\u691c\u7d22\u3011<\/strong><\/big><br \/>\n\u300cW\u300d\u3067\u59cb\u307e\u308b\u300cC\u30c9\u30e9\u30a4\u30d6\u300d\u76f4\u4e0b\u306e\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3092\u6f01\u308a\u305f\u3044\u3068\u304d\u306f\u3053\u3093\u306a\u611f\u3058\u3002<br \/>\nGet-ChildItem\u306e\u623b\u308a\u5024\u3092\u300c \u300d(\u534a\u89d2\u30b9\u30da\u30fc\u30b9)\u3067Split\u3057\u3066\u3084\u308c\u3070\u3001\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u540d\u306e\u30ea\u30b9\u30c8\u3092\u53d6\u5f97\u3067\u304d\u308b\u3002<br \/>\nWhere-Object \u3067\u3001\u300c$_.PSIsContainer\u300d\u3092\u6307\u5b9a\u3059\u308c\u3070\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3060\u3051\u3092\u53d6\u5f97\u3067\u304d\u308b\u3002<\/p>\n<pre>\r\n$dir = \"C:\\\";\r\n$subdir = Get-ChildItem $dir | Where-Object { $_.PSIsContainer } | Select-String \"^W\";\r\n$sub_arr = $subdir -split \" \";\r\n<\/pre>\n<p><big><strong>\u3010\u30d5\u30a9\u30eb\u30c0\u30fb\u30d5\u30a1\u30a4\u30eb\u6709\u7121\u78ba\u8a8d\u3011<\/strong><\/big><br \/>\n\u6307\u5b9a\u30d5\u30a9\u30eb\u30c0\u3001\u30d5\u30a1\u30a4\u30eb\u304c\u3042\u308b\u304b\u3069\u3046\u304b\u306f\u300cTest-Path\u300d\u3092\u4f7f\u3046\u3002<\/p>\n<pre>\r\nif (Test-Path ($dir)) {\r\n   # \u3042\u308b\u3068\u304d\r\n} else {\r\n   # \u306a\u3044\u3068\u304d\r\n}\r\n<\/pre>\n<p><big><strong>\u3010\u30d5\u30a9\u30eb\u30c0\u4f5c\u6210\u3011<\/strong><\/big><br \/>\n\u30d5\u30a9\u30eb\u30c0\u4f5c\u6210\u306f\u300cNew-Item\u300d\u3067\u3001\u30d1\u30b9\u3092\u6307\u5b9a\u3057\u3066\u3001\u300c-ItemType Directory\u300d\u306e\u30aa\u30d7\u30b7\u30e7\u30f3\u3092\u3064\u3051\u308b\u3002<br \/>\n\u300c-Force\u300d\u306f\u3059\u3067\u306b\u30d5\u30a9\u30eb\u30c0\u304c\u3042\u308b\u3068\u304d\u306f\u3001\u30a8\u30e9\u30fc\u306b\u306a\u3089\u306a\u3044\u3088\u3046\u306b\u3059\u308b\u3068\u304d\u306b\u3064\u3051\u308b\u3002<\/p>\n<pre>\r\nNew-Item $dir -ItemType Directory -Force;\r\n<\/pre>\n<p><big><strong>\u3010\u30d5\u30a1\u30a4\u30eb\u30b3\u30d4\u30fc\u3011<\/strong><\/big><br \/>\n\u30d5\u30a1\u30a4\u30eb\u30b3\u30d4\u30fc\u306f\u300cCopy-Item\u300d\u3067\u3001\u30b3\u30d4\u30fc\u5143\u306e\u30d1\u30b9\u3092\u6307\u5b9a\u3057\u3066\u3001\u300c-Destination\u300d\u3067\u30b3\u30d4\u30fc\u5148\u3092\u6307\u5b9a\u3059\u308b\u3002<br \/>\n\u300c-Force\u300d\u306f\u3059\u3067\u306b\u30b3\u30d4\u30fc\u5148\u306b\u30d5\u30a1\u30a4\u30eb\u304c\u3042\u3063\u3066\u3082\u3001\u30a8\u30e9\u30fc\u306b\u306a\u3089\u306a\u3044\u3088\u3046\u306b\u3059\u308b\u3068\u304d\u306b\u3064\u3051\u308b\u3002<\/p>\n<pre>\r\nCopy-Item $src_path -Destination $goto_path -Force;\r\n<\/pre>\n<p><big><strong>\u3010\u30d5\u30a1\u30a4\u30eb\u79fb\u52d5\u3011<\/strong><\/big><br \/>\n\u30d5\u30a1\u30a4\u30eb\u79fb\u52d5\u306f\u30b3\u30d4\u30fc\u3057\u3066\u304b\u3089\u524a\u9664\u3059\u308b\u306e\u304c\u3044\u3044\u3002<br \/>\n\u300cRemove-Item\u300d\u306e\u300c-Recurse\u300d\u306f\u524a\u9664\u5bfe\u8c61\u304c\u30d5\u30a9\u30eb\u30c0\u3067\u3042\u308c\u3070\u3001\u4e2d\u306e\u30d5\u30a1\u30a4\u30eb\u3092\u524a\u9664\u3057\u3066\u304b\u3089\u30d5\u30a9\u30eb\u30c0\u3082\u6d88\u3057\u3066\u304f\u308c\u308b\u3002<br \/>\n\u300c-Force\u300d\u3092\u3064\u3051\u308c\u3070\u3001\u96a0\u3057\u30d5\u30a1\u30a4\u30eb\u3068\u304b\u3082\u6d88\u3057\u3066\u304f\u308c\u308b\u305d\u3046\u3002<\/p>\n<pre>\r\nCopy-Item $src_path -Destination $goto_path -Force;\r\nRemove-Item -Path $src_path -Recurse -Force;\r\n<\/pre>\n<p><big><strong>\u3010\u30e9\u30a4\u30d6\u30e9\u30ea\u5229\u7528\u3011<\/strong><\/big><br \/>\n\u30e9\u30a4\u30d6\u30e9\u30ea\u306f\u3001\u30d1\u30b9\u3092\u6307\u5b9a\u3057\u3066\u8aad\u307f\u8fbc\u3093\u3067\u3084\u3089\u306a\u3044\u3068\u4f7f\u3048\u306a\u3044\u3002\u3053\u3093\u306a\u611f\u3058\u3002<\/p>\n<pre>\r\n[string]$dll       = \"C:\\....\\.....dll\";\r\n[void][reflection.assembly]::LoadFrom($dll);\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u6700\u8fd1\u3001VBS\u3088\u308aPowerShell\u306e\u307b\u3046\u3092\u3088\u304f\u4f7f\u3046\u3088\u3046\u306b\u306a\u3063\u305f\u3002 \u30a4\u30b1\u3066\u306a\u3044\u3068\u3053\u308d\u306f\u591a\u3005\u3042\u308b\u3082\u306e\u306e\u3001\u30c7\u30d0\u30c3\u30b0\u3082\u3057\u3084\u3059\u3044\u306e\u3067\u4fbf\u5229\u3060\u3002 \u30d5\u30a1\u30a4\u30eb\u64cd\u4f5c\u306e\u30a2\u30ec\u30b3\u30ec\u3092\u3053\u306e\u6295\u7a3f\u306b\u3044\u308d\u3044\u308d\u66f8\u304d\u8db3\u3057\u3066\u3044\u3053\u3046\u3068\u601d\u3046\u3002 \uff08\u30a2\u30ec\u30b3\u30ec\u3063\u3066\u3001\u6f22 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[209,205],"tags":[],"class_list":["post-2958","post","type-post","status-publish","format-standard","hentry","category-powershell","category-windows"],"_links":{"self":[{"href":"http:\/\/anada.cloudfree.jp\/index.php?rest_route=\/wp\/v2\/posts\/2958","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/anada.cloudfree.jp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/anada.cloudfree.jp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/anada.cloudfree.jp\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/anada.cloudfree.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2958"}],"version-history":[{"count":2,"href":"http:\/\/anada.cloudfree.jp\/index.php?rest_route=\/wp\/v2\/posts\/2958\/revisions"}],"predecessor-version":[{"id":2960,"href":"http:\/\/anada.cloudfree.jp\/index.php?rest_route=\/wp\/v2\/posts\/2958\/revisions\/2960"}],"wp:attachment":[{"href":"http:\/\/anada.cloudfree.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2958"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/anada.cloudfree.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2958"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/anada.cloudfree.jp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2958"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}