﻿{"id":108,"date":"2020-08-14T18:24:45","date_gmt":"2020-08-14T10:24:45","guid":{"rendered":"https:\/\/dt9025a.xyz\/?p=108"},"modified":"2020-08-19T23:32:57","modified_gmt":"2020-08-19T15:32:57","slug":"powershell-%e6%96%87%e4%bb%b6%e9%81%8d%e5%8e%86","status":"publish","type":"post","link":"https:\/\/dt9025a.top\/?p=108","title":{"rendered":"PowerShell \u5173\u4e8e\u904d\u5386\u6587\u4ef6"},"content":{"rendered":"\n<p>\u7f18\u7531\uff1a\u8981\u6279\u91cf\u5904\u7406ncm\u6587\u4ef6\uff0ccmd\u7684for\u597d\u96be\u8bb0\uff0c\u4e0d\u5c0f\u5fc3\u6253\u5f00\u4e86ps<\/p>\n\n\n\n<p>\u9996\u5148\uff0c\u6211\u4eec\u8981\u6253\u5f00powershell\u3002\u5728\u952e\u76d8\u4e0a\u6309\u4e0bWindows+X\u7ec4\u5408\u952e\uff0c\u5c31\u53ef\u4ee5\u770b\u89c1Windows Powershell\u9009\u9879\u4e86\u3002\u70b9\u51fb\u5b83\u3002<\/p>\n\n\n\n<p>\u4f46\u6211\u4e0d\u662f\u8fd9\u6837\u5e72\u7684\uff0cWindows Terminal\u6bd4 ps \u7684\u539f\u751f\u754c\u9762\u6f02\u4eae\u591a\u4e86\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"873\" height=\"739\" src=\"https:\/\/dt9025a.top\/wp-content\/uploads\/2020\/08\/image-1.png\" alt=\"\" class=\"wp-image-110\" srcset=\"https:\/\/dt9025a.top\/wp-content\/uploads\/2020\/08\/image-1.png 873w, https:\/\/dt9025a.top\/wp-content\/uploads\/2020\/08\/image-1-300x254.png 300w, https:\/\/dt9025a.top\/wp-content\/uploads\/2020\/08\/image-1-768x650.png 768w\" sizes=\"auto, (max-width: 873px) 100vw, 873px\" \/><figcaption>ps\u539f\u751f<\/figcaption><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"572\" src=\"https:\/\/dt9025a.top\/wp-content\/uploads\/2020\/08\/image-1024x572.png\" alt=\"\" class=\"wp-image-109\" srcset=\"https:\/\/dt9025a.top\/wp-content\/uploads\/2020\/08\/image-1024x572.png 1024w, https:\/\/dt9025a.top\/wp-content\/uploads\/2020\/08\/image-300x168.png 300w, https:\/\/dt9025a.top\/wp-content\/uploads\/2020\/08\/image-768x429.png 768w, https:\/\/dt9025a.top\/wp-content\/uploads\/2020\/08\/image.png 1129w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption>Terminal<\/figcaption><\/figure>\n\n\n\n<p>\u9996\u5148\uff0c\u6211\u4eec\u8981\u83b7\u53d6\u6587\u4ef6\u5217\u8868\u3002\u7ecf\u8fc7bing\u4e00\u4e0b\u540e\uff0c\u53d1\u73b0\u9700\u8981\u7528\u5230\u540d\u4e3a <code>Get-ChildItem<\/code> \u7684cmdlet\u3002\u90a3\u4e48\uff0c\u6211\u4eec\u6765man\u4e00\u4e0b\u4ed6\uff0c\u770b\u770b\u4ed6\u600e\u4e48\u7528\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">PS C:\\Users\\DT9025A&gt; <code>man Get-ChildItem<\/code>\n\u540d\u79f0\n<code>Get-ChildItem<\/code>\n\u8bed\u6cd5\n<code>Get-ChildItem [[-Path] &lt;string&gt;]] [[-Filter] &lt;string&gt;]] [&lt;CommonParameters&gt;]\nGet-ChildItem [[-Filter] &lt;string&gt;] [&lt;CommonParameters&gt;]<\/code>\n\u522b\u540d\n<code>gci\nls\ndir<\/code><\/pre>\n\n\n\n<p>\u5c31\u5f88\u6e05\u695a\uff0c\u4e3a\u4e86\u6d4b\u9a8c\uff0c\u6211\u4eec\u5148\u7528 <code>Get-ChildItem [[-Path] &lt;string&gt;] [[-Filter] &lt;string&gt;]<\/code>\u6a21\u5f0f\u6765\u8bd5\u4e00\u4e0b\u80fd\u5426\u6b63\u5e38\u83b7\u53d6\u6587\u4ef6\u5217\u8868\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"powershell\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># \u83b7\u53d6\u6587\u4ef6\u96c6\u5408\nGet-ChildItem D:\\CloudMusic *.mp3<\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"572\" src=\"https:\/\/dt9025a.top\/wp-content\/uploads\/2020\/08\/image-3-1024x572.png\" alt=\"\" class=\"wp-image-112\" srcset=\"https:\/\/dt9025a.top\/wp-content\/uploads\/2020\/08\/image-3-1024x572.png 1024w, https:\/\/dt9025a.top\/wp-content\/uploads\/2020\/08\/image-3-300x168.png 300w, https:\/\/dt9025a.top\/wp-content\/uploads\/2020\/08\/image-3-768x429.png 768w, https:\/\/dt9025a.top\/wp-content\/uploads\/2020\/08\/image-3.png 1129w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption>\u597d\u8036\uff0c\u6210\u529f\u529b\uff01<\/figcaption><\/figure>\n\n\n\n<p>\u611f\u89c9\u5f88\u68d2\uff01\u90a3\u4e48\u63a5\u4e0b\u6765\u6211\u4eec\u5c31\u53ef\u4ee5\u8fdb\u884c\u904d\u5386\u6d4b\u8bd5\u4e86\uff01<\/p>\n\n\n\n<p>\u7ee7\u7eed\u4f7f\u7528\u4e07\u80fd\u7684bing\uff0c\u4e86\u89e3\u5230PowerShell\u4e2d\u6709foreach\u5173\u952e\u5b57\uff0c\u7528\u6cd5\u5c31\u50cfC#\u5185\u7684foreach\u4e00\u6837 <code>foreach([Var] in [Set])<\/code>\u3002<s> \uff08cmdlet\u548c\u522b\u540d\u6df7\u7528\uff0c\u522b\u5b66\u6211\uff09<\/s>\u8fd9\u6837\uff0c\u5c31\u6765\u6d4b\u8bd5\u4e00\u4e0b\u81ea\u5df1\u7684\u4e3e\u4e00\u53cd\u4e09\u529b\u5427\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"powershell\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># \u6d4b\u8bd5foreach\n# \u83b7\u53d6\u6587\u4ef6\u96c6\u5408\n$files = Get-ChildItem D:\\CloudMusic *.mp3\n# \u8ba1\u6570\u53d8\u91cf\n$count = 0\n# \u904d\u5386\u96c6\u5408\nforeach ($singleFile in $files) {\n    # \u8f93\u51fa\u8ba1\u6570\u548c\u6587\u4ef6\u540d\n    echo $count $singleFile.Name\n    $count++\n}<\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"572\" src=\"https:\/\/dt9025a.top\/wp-content\/uploads\/2020\/08\/image-4-1024x572.png\" alt=\"\" class=\"wp-image-113\" srcset=\"https:\/\/dt9025a.top\/wp-content\/uploads\/2020\/08\/image-4-1024x572.png 1024w, https:\/\/dt9025a.top\/wp-content\/uploads\/2020\/08\/image-4-300x168.png 300w, https:\/\/dt9025a.top\/wp-content\/uploads\/2020\/08\/image-4-768x429.png 768w, https:\/\/dt9025a.top\/wp-content\/uploads\/2020\/08\/image-4.png 1129w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>\u5f88\u68d2\uff0c\u8fd9\u6837foreach\u5c31\u53ef\u4ee5\u7528\u4e86\u3002\u770b\u8d77\u6765\u79bb\u6210\u529f\u5df2\u7ecf\u5f88\u8fd1\u4e86\u5462\u3002<\/p>\n\n\n\n<p>\u7ee7\u7eed\u4e07\u80fd\u7684bing\uff0c\u67e5\u5230\u4e86\u8fd0\u884c\u7a0b\u5e8f\u53ef\u4ee5\u7528 <code>Start-Process<\/code> \u8fdb\u884c\u3002PowerShell\u7ed9\u51fa\u7684man\u4fe1\u606f\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">PS C:\\Users\\DT9025A&gt; <code>man Start-Process<\/code>\n\u540d\u79f0\n<code>Start-Process<\/code>\n\u8bed\u6cd5\n<code>Start-Process [-FilePath] &lt;string&gt; [[-ArgumentList] &lt;string&gt;] [&lt;CommonParameters&gt;]\nStart-Process [-FilePath] &lt;string&gt; [[-ArgumentList] &lt;string[]&gt;] [&lt;CommonParameters&gt;]<\/code>\n\u522b\u540d\n<code>saps\nstart<\/code><\/pre>\n\n\n\n<p>\u4e8e\u662f\u7406\u6240\u5f53\u7136\u7684\u5199\u51fa\u4e86\u4e0b\u5217\u4ee3\u7801\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"powershell\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># \u6d4b\u8bd5\u8fd0\u884c\n# \u83b7\u53d6\u6587\u4ef6\u96c6\u5408\n$files = Get-ChildItem D:\\CloudMusic *.ncm\n# \u5b9a\u4e49\u53ef\u6267\u884c\u6587\u4ef6\u8def\u5f84\n$exeDir = \"D:\\...\\main.exe\"\n# \u904d\u5386\u96c6\u5408\nforeach ($singleFile in $files) {\n    # \u6267\u884c\u7a0b\u5e8f\n    Start-Process -FilePath $exeDir -ArgumentList $singleFile.FullName -NoNewWindow -Wait\n}<\/pre>\n\n\n\n<p>\u4f46\u662f\uff0c\u95ee\u9898\u4ed6\u51fa\u73b0\u4e86\uff01\u76ee\u6807\u7a0b\u5e8f\u63d0\u793a\u65e0\u6548\u7684\u8def\u5f84\uff01<\/p>\n\n\n\n<p>\u6b64\u65f6\uff0c\u5f80\u4e0a\u7ffb\u7ffb\uff0c\u53d1\u73b0\u6587\u4ef6\u540d\u4e2d\u95f4\u6709\u7a7a\u683c&#8230; \u8fd9\u6837\u7684\u8bdd\uff0c\u5c31\u9700\u8981\u5728\u7edd\u5bf9\u8def\u5f84\u524d\u540e\u52a0\u4e0a\u5f15\u53f7\u6765\u6307\u793a\u8fd9\u662f\u5355\u4e2a\u53c2\u6570\u4e86\u3002\u90a3\u4e48\uff0c\u5c31\u53bb\u67e5\u67e5\u5b57\u7b26\u4e32\u5982\u4f55\u62fc\u63a5\u5427\uff01<\/p>\n\n\n\n<p>\u7ed3\u679c\u9707\u64bc\u6211\u6574\u5e74\uff0c\u7adf\u7136\u53ef\u4ee5\u7528 \u201c+\u201d \u76f4\u63a5\u8fdb\u884c\u8fde\u63a5\uff0cPowerShell\u771f\u662f\u592a\u5389\u5bb3\u5566\uff01<\/p>\n\n\n\n<p>\u9664\u4e86 \u201c+\u201d \u64cd\u4f5c\u7b26\uff0c\u8fd8\u53ef\u4ee5\u4f7f\u7528 <code>-Join(string1, string2...)<\/code> \u8fdb\u884c\u8fde\u63a5\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"powershell\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># \u6d4b\u8bd5\u5b57\u7b26\u4e32\u8fde\u63a5\n# \u5b9a\u4e49\u4e24\u4e2a\u5b57\u7b26\u4e32\n$s = \"te\"\n$s2 = \"st\"\n# \u4f7f\u7528 + \u64cd\u4f5c\u7b26\n$s + $s2\n# \u4f7f\u7528 -Join(...)\n-Join($s, $s2)<\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"572\" src=\"https:\/\/dt9025a.top\/wp-content\/uploads\/2020\/08\/image-5-1024x572.png\" alt=\"\" class=\"wp-image-115\" srcset=\"https:\/\/dt9025a.top\/wp-content\/uploads\/2020\/08\/image-5-1024x572.png 1024w, https:\/\/dt9025a.top\/wp-content\/uploads\/2020\/08\/image-5-300x168.png 300w, https:\/\/dt9025a.top\/wp-content\/uploads\/2020\/08\/image-5-768x429.png 768w, https:\/\/dt9025a.top\/wp-content\/uploads\/2020\/08\/image-5.png 1129w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>\u611f\u89c9\u5f88\u68d2\uff01\u90a3\u4e48\uff0c\u5f15\u53f7\u600e\u4e48\u8868\u793a\u5462\uff1f<\/p>\n\n\n\n<p>\u7b54\uff1a&#8221;&#8221;&#8221;&#8221; \u5728\u5b57\u7b26\u4e32\u5185\u4e24\u4e2a\u53cc\u5f15\u53f7\u53ef\u4ee5\u8f6c\u4e49\u4e3a\u5355\u4e2a\u53cc\u5f15\u53f7\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># \u6d4b\u8bd5\u5f15\u53f7\n# \u5b9a\u4e49\u5b57\u7b26\u4e32\n$s = \"\"\"te\"\"\"\n# \u8f93\u51fa\u5b57\u7b26\u4e32\n$s<\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"572\" src=\"https:\/\/dt9025a.top\/wp-content\/uploads\/2020\/08\/image-7-1024x572.png\" alt=\"\" class=\"wp-image-117\" srcset=\"https:\/\/dt9025a.top\/wp-content\/uploads\/2020\/08\/image-7-1024x572.png 1024w, https:\/\/dt9025a.top\/wp-content\/uploads\/2020\/08\/image-7-300x168.png 300w, https:\/\/dt9025a.top\/wp-content\/uploads\/2020\/08\/image-7-768x429.png 768w, https:\/\/dt9025a.top\/wp-content\/uploads\/2020\/08\/image-7.png 1129w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>\u8ba9\u6211\u4eec\u628a\u8fd9\u4e9b\u5143\u7d20\u5408\u5230\u4e00\u8d77\uff01<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># \u6d4b\u8bd5\u8fd0\u884c\n# \u83b7\u53d6\u6587\u4ef6\u96c6\u5408\n$files = Get-ChildItem D:\\CloudMusic *.ncm\n# \u5b9a\u4e49\u53ef\u6267\u884c\u6587\u4ef6\u8def\u5f84\n$exeDir = \"D:\\...\\main.exe\"\n# \u904d\u5386\u96c6\u5408\nforeach ($singleFile in $files) {\n    # \u62fc\u63a5\u5408\u6cd5\u8def\u5f84\n    $fileDir = -Join(\"\"\"\", $singleFile.FullName, \"\"\"\")\n    # \u6267\u884c\u7a0b\u5e8f\n    Start-Process -FilePath $exeDir -ArgumentList $fileDir -NoNewWindow -Wait\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u7f18\u7531\uff1a\u8981\u6279\u91cf\u5904\u7406ncm\u6587\u4ef6\uff0ccmd\u7684for\u597d\u96be\u8bb0\uff0c\u4e0d\u5c0f\u5fc3\u6253\u5f00\u4e86ps \u9996\u5148\uff0c\u6211\u4eec\u8981\u6253\u5f00powershell\u3002\u5728\u952e&#8230; <\/p>\n<div class=\"read-more navbutton\"><a href=\"https:\/\/dt9025a.top\/?p=108\">\u9605\u8bfb\u66f4\u591a<i class=\"fa fa-angle-double-right\"><\/i><\/a><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"class_list":["post-108","post","type-post","status-publish","format-standard","hentry","category-powershell-cmd-and-so-on"],"_links":{"self":[{"href":"https:\/\/dt9025a.top\/index.php?rest_route=\/wp\/v2\/posts\/108","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dt9025a.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dt9025a.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dt9025a.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dt9025a.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=108"}],"version-history":[{"count":0,"href":"https:\/\/dt9025a.top\/index.php?rest_route=\/wp\/v2\/posts\/108\/revisions"}],"wp:attachment":[{"href":"https:\/\/dt9025a.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=108"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dt9025a.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=108"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dt9025a.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=108"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}