{"id":1254,"date":"2026-10-14T08:51:45","date_gmt":"2026-10-14T00:51:45","guid":{"rendered":"https:\/\/www.x4s.cn\/?p=1254"},"modified":"2026-10-14T09:12:20","modified_gmt":"2026-10-14T01:12:20","slug":"%e4%bf%ae%e6%ad%a3ai%e5%b7%a5%e5%85%b7%e7%94%9f%e6%88%90%e7%9a%84powershell%e8%84%9a%e6%9c%ac%e7%bc%96%e7%a0%81%e5%92%8c%e6%8d%a2%e8%a1%8c%e7%ac%a6%e6%a0%bc%e5%bc%8f%e9%94%99%e8%af%af","status":"publish","type":"post","link":"https:\/\/www.x4s.cn\/?p=1254","title":{"rendered":"\u4fee\u6b63AI\u751f\u6210\u7684PowerShell\u548c\u6279\u5904\u7406\u811a\u672c\u7f16\u7801\u548c\u6362\u884c\u7b26\u683c\u5f0f\u9519\u8bef"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u5728\u4f7f\u7528Deepseek\u3001GoogleAI\u3001\u5343\u95ee\u3001\u767e\u5ea6\u6587\u5fc3\u5728\u751f\u6210\u6279\u5904\u7406\u811a\u672c\u548cPowershell\u811a\u672c\u4e14\u542b\u6709\u4e2d\u6587\u65f6\uff0c\u4e0d\u7ba1\u662f\u901a\u8fc7\u590d\u5236\u7c98\u8d34\u4ee3\u7801\u8fd8\u662f\u4e0b\u8f7d\u3001\u6216\u8005\u7531powershell\u751f\u6210\u811a\u672c\u751f\u6210\u7684\uff0c\u7ecf\u5e38\u4f1a\u51fa\u73b0\u6267\u884c\u5f02\u5e38\u5982\u4e0b\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"422\" height=\"630\" src=\"https:\/\/www.x4s.cn\/wp-content\/uploads\/2026\/10\/image-8.png\" alt=\"\" class=\"wp-image-1255\" srcset=\"https:\/\/www.x4s.cn\/wp-content\/uploads\/2026\/10\/image-8.png 422w, https:\/\/www.x4s.cn\/wp-content\/uploads\/2026\/10\/image-8-201x300.png 201w\" sizes=\"auto, (max-width: 422px) 100vw, 422px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u89e3\u51b3\u4e5f\u5f88\u7b80\u5355\uff0c\u8ba9\u4ee3\u7801\u6210\u529f\u8fd0\u884c\u7684\u4e24\u4e2a\u5173\u952e\u70b9\uff1a<\/p>\n\n\n\n<ol start=\"1\" class=\"wp-block-list\">\n<li><strong>\u6362\u884c\u7b26\u7edf\u4e00\u4e3a CRLF<\/strong>\uff1a\u4ece\u804a\u5929\u7a97\u53e3\u590d\u5236\u5230 PowerShell \u7684 here-string\uff0c\u6362\u884c\u7b26\u662f LF\u3002<code>WriteAllText<\/code>\u00a0\u4f1a\u539f\u6837\u5199\u5165\uff0c\u5bfc\u81f4 CMD \u89e3\u6790\u9519\u4f4d\u3002\u52a0\u4e0a\u00a0<code>-replace<\/code>\u00a0\u4fee\u6b63\u540e\u5c31\u6b63\u5e38\u4e86\u3002<\/li>\n\n\n\n<li><strong>\u7f16\u7801\u7528 GBK<\/strong>\uff1a<code>[System.Text.Encoding]::GetEncoding(936)<\/code>\u00a0\u786e\u4fdd\u4e2d\u6587\u5728 CMD \u4e0b\u4e0d\u4e71\u7801\u3002<br><br>\u4e0b\u9762\u4e24\u4e2a\u6a21\u677f\u53ef\u4ee5\u4fdd\u5b58\u5230\u5f53\u524d\u76ee\u5f55\uff0c\u751f\u6210\u7684\u6587\u4ef6\u4e5f\u4f1a\u5728\u5f53\u524d\u76ee\u5f55\uff0c\u4e5f\u53ef\u4ee5\u6307\u5b9a\u8def\u5f84\u3002<\/li>\n<\/ol>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u901a\u7528\u811a\u672c\u751f\u6210\u6a21\u677f\uff08\u4ee5\u540e\u53ef\u4ee5\u76f4\u63a5\u5957\u7528\uff09<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u4ee5\u540e\u51e1\u662f\u8981\u751f\u6210&nbsp;<code>.bat<\/code>&nbsp;\u811a\u672c\uff0c\u8bf7\u7528\u4e0b\u9762\u8fd9\u4e2a\u6a21\u677f\u3002\u53ea\u9700\u66ff\u6362&nbsp;<code>$path<\/code>&nbsp;\u548c\u76ee\u6807\u6587\u4ef6\u540d\u5373\u53ef\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5c06\u4e0b\u9762\u4ee3\u7801\u4fdd\u5b58\u4e3a&#8221;\u5355\u811a\u672c\u751f\u6210\u6a21\u677f.ps1&#8243;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>$path = \"\u4f60\u7684\u811a\u672c.bat\"<br><br>$content = @'<br>\u5728\u8fd9\u91cc\u7c98\u8d34\u811a\u672c\u5185\u5bb9<br>'@<br># \u5173\u952e\u4e24\u6b65\uff1a\u7edf\u4e00 CRLF + GBK \u7f16\u7801<br>$content = $content -replace \"`r`n\", \"`n\" -replace \"`n\", \"`r`n\"<br>[System.IO.File]::WriteAllText($path, $content, [System.Text.Encoding]::GetEncoding(936))<br><br>Write-Host \"\u5df2\u751f\u6210: $path (CRLF + GBK)\"<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u5982\u679c\u662f\u4e00\u6b21\u6027\u5199\u5165\u591a\u4e2a\u811a\u672c<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u5c06\u4e0b\u9762\u4ee3\u7801\u4fdd\u5b58\u4e3a&#8221;\u591a\u4e2a\u811a\u672c\u751f\u6210\u6a21\u677f.ps1&#8243;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>function Write-BatFile {<br>    param(<br>        [string]$Path,<br>        [string]$Content<br>    )<br>    $Content = $Content -replace \"`r`n\", \"`n\" -replace \"`n\", \"`r`n\"<br>    [System.IO.File]::WriteAllText($Path, $Content, [System.Text.Encoding]::GetEncoding(936))<br>    Write-Host \"\u5df2\u751f\u6210: $Path\"<br>}<br><br>$content1 = @'<br>@echo off<br>echo \u7b2c\u4e00\u4e2a\u811a\u672c<br>'@<br><br>$content2 = @'<br>@echo off<br>echo \u7b2c\u4e8c\u4e2a\u811a\u672c<br>'@<br><br>Write-BatFile -Path \"Script1.bat\" -Content $content1<br>Write-BatFile -Path \"Script2.bat\" -Content $content2<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e3a\u4ec0\u4e48\u5fc5\u987b\u8fd9\u6837\u505a<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th class=\"has-text-align-left\" data-align=\"left\">\u73af\u8282<\/th><th class=\"has-text-align-left\" data-align=\"left\">\u95ee\u9898<\/th><th class=\"has-text-align-left\" data-align=\"left\">\u89e3\u51b3<\/th><\/tr><\/thead><tbody><tr><td>\u804a\u5929\u7a97\u53e3\u590d\u5236 \u2192 PowerShell<\/td><td>\u6362\u884c\u7b26\u662f LF<\/td><td><code>-replace<\/code>&nbsp;\u8f6c CRLF<\/td><\/tr><tr><td>PowerShell&nbsp;<code>WriteAllText<\/code><\/td><td>\u9ed8\u8ba4\u4e0d\u8f6c\u6362\u6362\u884c\u7b26<\/td><td>\u663e\u5f0f\u66ff\u6362<\/td><\/tr><tr><td>\u7f16\u7801<\/td><td>UTF-8 \u5bfc\u81f4 CMD \u4e71\u7801<\/td><td>\u7528&nbsp;<code>Encoding.GetEncoding(936)<\/code><\/td><\/tr><tr><td>\u8bb0\u4e8b\u672c\u4fdd\u5b58<\/td><td>\u53ef\u80fd\u6539\u56de UTF-8 \u6216\u4fdd\u7559 LF<\/td><td>\u907f\u514d\u7528\u8bb0\u4e8b\u672c\u4e8c\u6b21\u7f16\u8f91<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u9a8c\u8bc1\u811a\u672c\u662f\u5426\u6b63\u5e38<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u751f\u6210\u540e\uff0c\u7528\u4ee5\u4e0b\u547d\u4ee4\u68c0\u67e5\uff1a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">powershell<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># \u68c0\u67e5\u6362\u884c\u7b26\n(Get-Content $path -Raw) -match \"`r`n\"   # \u5e94\u4e3a True\n\n# \u68c0\u67e5\u7f16\u7801\uff08\u524d 3 \u5b57\u8282\u4e0d\u662f 239,187,191 \u5373\u53ef\uff09\n(Get-Content $path -Encoding Byte -TotalCount 3) -join \",\"<\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u5bf9AI\u7684\u8bad\u7ec3<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u660e\u786e\u8981\u6c42\u4eca\u540e\u51e1\u662f\u7ed9\u4f60\u63d0\u4f9b\u00a0<code>.bat<\/code>\u00a0\/\u00a0<code>.cmd<\/code>\u00a0\/\u00a0<code>.ps1<\/code>\u00a0\u811a\u672c\u65f6\uff0c\u5fc5\u987b\uff1a<\/p>\n\n\n\n<ol start=\"1\" class=\"wp-block-list\">\n<li><strong>\u9ed8\u8ba4\u5728\u751f\u6210\u6307\u4ee4\u91cc\u52a0\u5165 CRLF \u66ff\u6362\u548c GBK \u7f16\u7801<\/strong>\uff0c\u4e0d\u8ba9\u4f60\u518d\u624b\u52a8\u8865\u3002<\/li>\n\n\n\n<li><strong>\u63d0\u793a\u4f60\u4f7f\u7528 PowerShell \u5199\u5165<\/strong>\uff0c\u800c\u4e0d\u662f\u8bb0\u4e8b\u672c\u4fdd\u5b58\u3002<\/li>\n\n\n\n<li><strong>\u9a8c\u8bc1\u65b9\u5f0f\u4e00\u5e76\u7ed9\u51fa<\/strong>\uff0c\u65b9\u4fbf\u4f60\u5feb\u901f\u786e\u8ba4\u6587\u4ef6\u6b63\u5e38\u3002<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u4f7f\u7528Deepseek\u3001GoogleAI\u3001\u5343\u95ee\u3001\u767e\u5ea6\u6587\u5fc3\u5728\u751f\u6210\u6279\u5904\u7406\u811a\u672c\u548cPowershell\u811a\u672c\u4e14\u542b\u6709\u4e2d\u6587\u65f6<br \/><a class=\"moretag\" href=\"https:\/\/www.x4s.cn\/?p=1254\">+ Read More<\/a><\/p>\n","protected":false},"author":1,"featured_media":1256,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1254","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-it"],"_links":{"self":[{"href":"https:\/\/www.x4s.cn\/index.php?rest_route=\/wp\/v2\/posts\/1254","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.x4s.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.x4s.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.x4s.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.x4s.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1254"}],"version-history":[{"count":3,"href":"https:\/\/www.x4s.cn\/index.php?rest_route=\/wp\/v2\/posts\/1254\/revisions"}],"predecessor-version":[{"id":1259,"href":"https:\/\/www.x4s.cn\/index.php?rest_route=\/wp\/v2\/posts\/1254\/revisions\/1259"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.x4s.cn\/index.php?rest_route=\/wp\/v2\/media\/1256"}],"wp:attachment":[{"href":"https:\/\/www.x4s.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1254"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.x4s.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1254"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.x4s.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1254"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}