{"id":317,"date":"2026-04-12T21:59:38","date_gmt":"2026-04-12T13:59:38","guid":{"rendered":"https:\/\/www.resilence.cn\/?p=317"},"modified":"2026-04-12T21:59:38","modified_gmt":"2026-04-12T13:59:38","slug":"day-3-%e5%8f%98%e9%87%8f%e4%b8%8e%e6%95%b0%e6%8d%ae%e7%b1%bb%e5%9e%8b","status":"publish","type":"post","link":"https:\/\/www.resilence.cn\/?p=317","title":{"rendered":"Day-3-\u53d8\u91cf\u4e0e\u6570\u636e\u7c7b\u578b"},"content":{"rendered":"<h1>Day 3: \u53d8\u91cf\u4e0e\u6570\u636e\u7c7b\u578b<\/h1>\n<h2>\ud83c\udfaf \u5b66\u4e60\u76ee\u6807<\/h2>\n<ul>\n<li>\u7406\u89e3\u53d8\u91cf\u7684\u6982\u5ff5\u548c\u4f5c\u7528<\/li>\n<li>\u638c\u63e1 PowerShell \u7684\u57fa\u672c\u6570\u636e\u7c7b\u578b<\/li>\n<li>\u5b66\u4f1a\u53d8\u91cf\u7684\u521b\u5efa\u3001\u8d4b\u503c\u548c\u4f7f\u7528<\/li>\n<li>\u7406\u89e3\u53d8\u91cf\u7684\u4f5c\u7528\u57df<\/li>\n<li>\u638c\u63e1\u6570\u636e\u7c7b\u578b\u7684\u8f6c\u6362<\/li>\n<li>\u5b66\u4f1a\u4f7f\u7528\u5e38\u91cf\u548c\u53ea\u8bfb\u53d8\u91cf<\/li>\n<\/ul>\n<h2>\ud83d\udca1 \u6838\u5fc3\u6982\u5ff5<\/h2>\n<h3>1. \u4ec0\u4e48\u662f\u53d8\u91cf\uff1f<\/h3>\n<p>\u53d8\u91cf\u5c31\u50cf\u662f\u5b58\u50a8\u6570\u636e\u7684&quot;\u5bb9\u5668&quot;\u3002\u4f60\u53ef\u4ee5\u628a\u6570\u636e\u653e\u8fdb\u8fd9\u4e2a\u5bb9\u5668\uff0c\u7136\u540e\u5728\u9700\u8981\u7684\u65f6\u5019\u53d6\u51fa\u6765\u4f7f\u7528\u3002<\/p>\n<p><strong>\u751f\u6d3b\u4e2d\u7684\u6bd4\u55bb<\/strong>\uff1a<\/p>\n<ul>\n<li>\u53d8\u91cf = \u76d2\u5b50<\/li>\n<li>\u53d8\u91cf\u540d = \u76d2\u5b50\u4e0a\u7684\u6807\u7b7e<\/li>\n<li>\u53d8\u91cf\u503c = \u76d2\u5b50\u91cc\u7684\u4e1c\u897f<\/li>\n<\/ul>\n<p><strong>\u793a\u4f8b<\/strong>\uff1a<\/p>\n<pre><code class=\"language-powershell\"># \u521b\u5efa\u4e00\u4e2a\u76d2\u5b50\uff08\u53d8\u91cf\uff09\uff0c\u540d\u5b57\u53eb name\uff0c\u91cc\u9762\u88c5\u7740&quot;\u5f20\u4e09&quot;\n$name = &quot;\u5f20\u4e09&quot;\n\n# \u521b\u5efa\u4e00\u4e2a\u76d2\u5b50\uff0c\u540d\u5b57\u53eb age\uff0c\u91cc\u9762\u88c5\u7740\u6570\u5b57 30\n$age = 30\n<\/code><\/pre>\n<hr>\n<h3>2. \u53d8\u91cf\u7684\u547d\u540d\u89c4\u5219<\/h3>\n<h4>2.1 \u547d\u540d\u89c4\u8303<\/h4>\n<p><strong>\u53d8\u91cf\u540d\u5fc5\u987b\u4ee5 <code>$<\/code> \u7b26\u53f7\u5f00\u5934<\/strong>\uff1a<\/p>\n<pre><code class=\"language-powershell\"># \u2705 \u6b63\u786e\n$name\n$age\n$user_name\n$UserName\n\n# \u274c \u9519\u8bef\nname      # \u7f3a\u5c11 $ \u7b26\u53f7\n$2user    # \u4e0d\u80fd\u4ee5\u6570\u5b57\u5f00\u5934\n$user-name # \u4e0d\u80fd\u5305\u542b\u8fde\u5b57\u7b26\n<\/code><\/pre>\n<p><strong>\u547d\u540d\u5efa\u8bae<\/strong>\uff1a<\/p>\n<ul>\n<li>\u4f7f\u7528\u6709\u610f\u4e49\u7684\u540d\u79f0<\/li>\n<li>\u91c7\u7528\u9a7c\u5cf0\u547d\u540d\u6cd5\uff08Pascal Case \u6216 camelCase\uff09<\/li>\n<li>\u907f\u514d\u4f7f\u7528 PowerShell \u4fdd\u7559\u5b57<\/li>\n<\/ul>\n<p><strong>\u597d\u7684\u547d\u540d\u793a\u4f8b<\/strong>\uff1a<\/p>\n<pre><code class=\"language-powershell\">$firstName = &quot;\u5f20\u4e09&quot;\n$lastName = &quot;\u674e\u56db&quot;\n$userAge = 25\n$isAdmin = $true\n<\/code><\/pre>\n<hr>\n<h3>3. PowerShell \u7684\u6570\u636e\u7c7b\u578b<\/h3>\n<p>PowerShell \u662f\u4e00\u79cd<strong>\u5f31\u7c7b\u578b<\/strong>\u8bed\u8a00\uff0c\u4f46\u4f60\u4ecd\u7136\u9700\u8981\u4e86\u89e3\u4e0d\u540c\u7684\u6570\u636e\u7c7b\u578b\u3002<\/p>\n<h4>3.1 \u57fa\u672c\u6570\u636e\u7c7b\u578b<\/h4>\n<p><strong>\u5b57\u7b26\u4e32\uff08String\uff09<\/strong>\uff1a<\/p>\n<pre><code class=\"language-powershell\">$message = &quot;Hello World&quot;\n$emptyString = &quot;&quot;\n<\/code><\/pre>\n<p><strong>\u6574\u6570\uff08Integer\uff09<\/strong>\uff1a<\/p>\n<pre><code class=\"language-powershell\">$count = 100\n$negative = -50\n<\/code><\/pre>\n<p><strong>\u6d6e\u70b9\u6570\uff08Double\uff09<\/strong>\uff1a<\/p>\n<pre><code class=\"language-powershell\">$price = 19.99\n$pi = 3.14159\n<\/code><\/pre>\n<p><strong>\u5e03\u5c14\u503c\uff08Boolean\uff09<\/strong>\uff1a<\/p>\n<pre><code class=\"language-powershell\">$isValid = $true\n$isComplete = $false\n<\/code><\/pre>\n<p><strong>\u6570\u7ec4\uff08Array\uff09<\/strong>\uff1a<\/p>\n<pre><code class=\"language-powershell\">$numbers = 1, 2, 3, 4, 5\n$names = &quot;\u5f20\u4e09&quot;, &quot;\u674e\u56db&quot;, &quot;\u738b\u4e94&quot;\n<\/code><\/pre>\n<p><strong>\u54c8\u5e0c\u8868\uff08Hashtable\uff09<\/strong>\uff1a<\/p>\n<pre><code class=\"language-powershell\">$user = @{\n    Name = &quot;\u5f20\u4e09&quot;\n    Age = 30\n    City = &quot;\u5317\u4eac&quot;\n}\n<\/code><\/pre>\n<h4>3.2 \u7279\u6b8a\u503c<\/h4>\n<p><strong>$null<\/strong> &#8211; \u8868\u793a\u7a7a\u503c\uff1a<\/p>\n<pre><code class=\"language-powershell\">$empty = $null\n<\/code><\/pre>\n<p><strong>$true \u548c $false<\/strong> &#8211; \u5e03\u5c14\u503c\uff1a<\/p>\n<pre><code class=\"language-powershell\">$isTrue = $true\n$isFalse = $false\n<\/code><\/pre>\n<hr>\n<h3>4. \u53d8\u91cf\u7684\u8d4b\u503c\u548c\u4f7f\u7528<\/h3>\n<h4>4.1 \u8d4b\u503c\u64cd\u4f5c<\/h4>\n<p><strong>\u76f4\u63a5\u8d4b\u503c<\/strong>\uff1a<\/p>\n<pre><code class=\"language-powershell\">$name = &quot;\u5f20\u4e09&quot;\n$age = 30\n$height = 1.75\n<\/code><\/pre>\n<p><strong>\u4f7f\u7528\u8868\u8fbe\u5f0f\u8d4b\u503c<\/strong>\uff1a<\/p>\n<pre><code class=\"language-powershell\">$sum = 10 + 20\n$product = 5 * 6\n<\/code><\/pre>\n<p><strong>\u547d\u4ee4\u7ed3\u679c\u8d4b\u503c<\/strong>\uff1a<\/p>\n<pre><code class=\"language-powershell\">$currentDir = Get-Location\n$processes = Get-Process\n<\/code><\/pre>\n<h4>4.2 \u8bbf\u95ee\u53d8\u91cf\u503c<\/h4>\n<pre><code class=\"language-powershell\">$name = &quot;\u5f20\u4e09&quot;\nWrite-Output $name           # \u8f93\u51fa\uff1a\u5f20\u4e09\nWrite-Output &quot;\u6211\u7684\u540d\u5b57\u662f $name&quot;  # \u8f93\u51fa\uff1a\u6211\u7684\u540d\u5b57\u662f \u5f20\u4e09\n<\/code><\/pre>\n<p><strong>\u5728\u53cc\u5f15\u53f7\u5b57\u7b26\u4e32\u4e2d\u4f7f\u7528\u53d8\u91cf<\/strong>\uff1a<\/p>\n<pre><code class=\"language-powershell\">$name = &quot;\u5f20\u4e09&quot;\n$age = 30\nWrite-Output &quot;\u6211\u7684\u540d\u5b57\u662f $name\uff0c\u4eca\u5e74 $age \u5c81&quot;\n# \u8f93\u51fa\uff1a\u6211\u7684\u540d\u5b57\u662f \u5f20\u4e09\uff0c\u4eca\u5e74 30 \u5c81\n<\/code><\/pre>\n<hr>\n<h3>5. \u6570\u636e\u7c7b\u578b\u8f6c\u6362<\/h3>\n<h4>5.1 \u81ea\u52a8\u7c7b\u578b\u8f6c\u6362<\/h4>\n<p>PowerShell \u4f1a\u81ea\u52a8\u8fdb\u884c\u7c7b\u578b\u8f6c\u6362\uff1a<\/p>\n<pre><code class=\"language-powershell\"># \u6570\u5b57 + \u5b57\u7b26\u4e32 = \u5b57\u7b26\u4e32\n$result = 10 + &quot;20&quot;\nWrite-Output $result  # \u8f93\u51fa\uff1a1020\n\n# \u6570\u5b57 + \u6570\u5b57 = \u6570\u5b57\n$result = 10 + 20\nWrite-Output $result  # \u8f93\u51fa\uff1a30\n<\/code><\/pre>\n<h4>5.2 \u5f3a\u5236\u7c7b\u578b\u8f6c\u6362<\/h4>\n<p><strong>\u4f7f\u7528\u7c7b\u578b\u8f6c\u6362\u64cd\u4f5c\u7b26<\/strong>\uff1a<\/p>\n<pre><code class=\"language-powershell\"># \u5b57\u7b26\u4e32\u8f6c\u6574\u6570\n$stringNumber = &quot;100&quot;\n$number = [int]$stringNumber\nWrite-Output $number + 50  # \u8f93\u51fa\uff1a150\n\n# \u6570\u5b57\u8f6c\u5b57\u7b26\u4e32\n$number = 100\n$string = [string]$number\nWrite-Output &quot;\u6570\u5b57\u662f\uff1a$string&quot;  # \u8f93\u51fa\uff1a\u6570\u5b57\u662f\uff1a100\n<\/code><\/pre>\n<p><strong>\u5e38\u7528\u7c7b\u578b\u8f6c\u6362<\/strong>\uff1a<\/p>\n<pre><code class=\"language-powershell\">[int]       # \u6574\u6570\n[string]    # \u5b57\u7b26\u4e32\n[double]    # \u6d6e\u70b9\u6570\n[bool]      # \u5e03\u5c14\u503c\n[datetime]  # \u65e5\u671f\u65f6\u95f4\n<\/code><\/pre>\n<p><strong>\u793a\u4f8b<\/strong>\uff1a<\/p>\n<pre><code class=\"language-powershell\"># \u5b57\u7b26\u4e32\u8f6c\u6574\u6570\n$text = &quot;123&quot;\n$num = [int]$text\nWrite-Output $num + 10  # \u8f93\u51fa\uff1a133\n\n# \u5b57\u7b26\u4e32\u8f6c\u65e5\u671f\n$dateString = &quot;2026-03-31&quot;\n$date = [datetime]$dateString\nWrite-Output $date  # \u8f93\u51fa\uff1a2026\u5e743\u670831\u65e5 0:00:00\n\n# \u6570\u5b57\u8f6c\u5e03\u5c14\n$zero = 0\n$one = 1\n$boolZero = [bool]$zero   # $false\n$boolOne = [bool]$one     # $true\n<\/code><\/pre>\n<hr>\n<h3>6. \u53d8\u91cf\u7684\u4f5c\u7528\u57df<\/h3>\n<p>\u4f5c\u7528\u57df\u51b3\u5b9a\u4e86\u53d8\u91cf\u5728\u54ea\u91cc\u53ef\u4ee5\u88ab\u8bbf\u95ee\u3002<\/p>\n<h4>6.1 \u4f5c\u7528\u57df\u7c7b\u578b<\/h4>\n<p><strong>\u5168\u5c40\u4f5c\u7528\u57df<\/strong>\uff1a<\/p>\n<pre><code class=\"language-powershell\">$global:name = &quot;\u5f20\u4e09&quot;\n# \u5728\u811a\u672c\u7684\u4efb\u4f55\u5730\u65b9\u90fd\u53ef\u4ee5\u8bbf\u95ee\n<\/code><\/pre>\n<p><strong>\u811a\u672c\u4f5c\u7528\u57df<\/strong>\uff1a<\/p>\n<pre><code class=\"language-powershell\">$script:name = &quot;\u674e\u56db&quot;\n# \u53ea\u5728\u5f53\u524d\u811a\u672c\u4e2d\u6709\u6548\n<\/code><\/pre>\n<p><strong>\u5c40\u90e8\u4f5c\u7528\u57df<\/strong>\uff1a<\/p>\n<pre><code class=\"language-powershell\">function Test {\n    $local:name = &quot;\u738b\u4e94&quot;\n    # \u53ea\u5728\u51fd\u6570\u5185\u90e8\u6709\u6548\n}\n<\/code><\/pre>\n<h4>6.2 \u4f5c\u7528\u57df\u4fee\u9970\u7b26<\/h4>\n<pre><code class=\"language-powershell\"># \u521b\u5efa\u5168\u5c40\u53d8\u91cf\n$Global:myVar = &quot;\u5168\u5c40\u53d8\u91cf&quot;\n\n# \u521b\u5efa\u811a\u672c\u53d8\u91cf\n$Script:myVar = &quot;\u811a\u672c\u53d8\u91cf&quot;\n\n# \u521b\u5efa\u79c1\u6709\u53d8\u91cf\n$Private:myVar = &quot;\u79c1\u6709\u53d8\u91cf&quot;\n<\/code><\/pre>\n<hr>\n<h3>7. \u5e38\u91cf\u548c\u53ea\u8bfb\u53d8\u91cf<\/h3>\n<h4>7.1 \u521b\u5efa\u53ea\u8bfb\u53d8\u91cf<\/h4>\n<p><strong>\u4f7f\u7528 Set-Variable \u521b\u5efa\u53ea\u8bfb\u53d8\u91cf<\/strong>\uff1a<\/p>\n<pre><code class=\"language-powershell\">Set-Variable -Name &quot;readOnly&quot; -Value &quot;\u4e0d\u80fd\u4fee\u6539&quot; -Option ReadOnly\n$readOnly = &quot;\u65b0\u503c&quot;  # \u8fd9\u4f1a\u62a5\u9519\uff1a\u65e0\u6cd5\u8986\u76d6\u53d8\u91cf readOnly\uff0c\u56e0\u4e3a\u5b83\u662f\u53ea\u8bfb\u53d8\u91cf\u6216\u4e3a\u5e38\u91cf\n<\/code><\/pre>\n<p><strong>\u521b\u5efa\u5e38\u91cf\uff08Constant\uff09<\/strong>\uff1a<\/p>\n<pre><code class=\"language-powershell\">Set-Variable -Name &quot;PI&quot; -Value 3.14159 -Option Constant\n# $PI = 3.14159  # \u8fd9\u4f1a\u62a5\u9519\uff0c\u56e0\u4e3a\u662f\u5e38\u91cf\n<\/code><\/pre>\n<p><strong>\u26a0\ufe0f \u91cd\u8981\u533a\u522b<\/strong>\uff1a<\/p>\n<ul>\n<li><strong>ReadOnly\uff08\u53ea\u8bfb\uff09<\/strong>\uff1a\u53d8\u91cf\u4e0d\u80fd\u88ab\u4fee\u6539\uff0c\u4f46\u53ef\u4ee5\u88ab\u5220\u9664<\/li>\n<li><strong>Constant\uff08\u5e38\u91cf\uff09<\/strong>\uff1a\u53d8\u91cf\u4e0d\u80fd\u88ab\u4fee\u6539\uff0c\u4e5f\u4e0d\u80fd\u88ab\u5220\u9664<\/li>\n<\/ul>\n<p><strong>\u9519\u8bef\u7684\u793a\u4f8b<\/strong>\uff1a<\/p>\n<pre><code class=\"language-powershell\"># \u274c \u8fd9\u6837\u521b\u5efa\u7684\u4e0d\u662f\u53ea\u8bfb\u53d8\u91cf\n$readOnly = &quot;\u4e0d\u80fd\u4fee\u6539&quot;\n$readOnly = &quot;\u65b0\u503c&quot;  # \u8fd9\u4e0d\u4f1a\u62a5\u9519\uff01\u53d8\u91cf\u88ab\u6210\u529f\u4fee\u6539\u4e86\n<\/code><\/pre>\n<h4>7.2 \u4f7f\u7528\u5e38\u91cf<\/h4>\n<pre><code class=\"language-powershell\"># \u5b9a\u4e49\u5e38\u7528\u5e38\u91cf\nSet-Variable -Name &quot;MaxAttempts&quot; -Value 3 -Option Constant\nSet-Variable -Name &quot;DefaultTimeout&quot; -Value 30 -Option Constant\n\n# \u4f7f\u7528\u5e38\u91cf\nWrite-Output &quot;\u6700\u5927\u5c1d\u8bd5\u6b21\u6570\uff1a$MaxAttempts&quot;\nWrite-Output &quot;\u9ed8\u8ba4\u8d85\u65f6\u65f6\u95f4\uff1a$DefaultTimeout \u79d2&quot;\n<\/code><\/pre>\n<hr>\n<h3>8. \u6570\u7ec4\u64cd\u4f5c<\/h3>\n<h4>8.1 \u521b\u5efa\u6570\u7ec4<\/h4>\n<pre><code class=\"language-powershell\"># \u65b9\u5f0f1\uff1a\u9017\u53f7\u5206\u9694\n$numbers = 1, 2, 3, 4, 5\n\n# \u65b9\u5f0f2\uff1a\u8303\u56f4\u8fd0\u7b97\u7b26\n$numbers = 1..10\n\n# \u65b9\u5f0f3\uff1a\u7a7a\u6570\u7ec4\n$emptyArray = @()\n<\/code><\/pre>\n<h4>8.2 \u8bbf\u95ee\u6570\u7ec4\u5143\u7d20<\/h4>\n<pre><code class=\"language-powershell\">$fruits = &quot;\u82f9\u679c&quot;, &quot;\u9999\u8549&quot;, &quot;\u6a59\u5b50&quot;\nWrite-Output $fruits[0]  # \u8f93\u51fa\uff1a\u82f9\u679c\nWrite-Output $fruits[1]  # \u8f93\u51fa\uff1a\u9999\u8549\nWrite-Output $fruits[-1] # \u8f93\u51fa\uff1a\u6a59\u5b50\uff08\u6700\u540e\u4e00\u4e2a\uff09\n<\/code><\/pre>\n<h4>8.3 \u6570\u7ec4\u64cd\u4f5c<\/h4>\n<pre><code class=\"language-powershell\"># \u83b7\u53d6\u6570\u7ec4\u957f\u5ea6\n$numbers = 1, 2, 3, 4, 5\nWrite-Output $numbers.Length  # \u8f93\u51fa\uff1a5\n\n# \u6dfb\u52a0\u5143\u7d20\n$numbers += 6\n\n# \u904d\u5386\u6570\u7ec4\nforeach ($num in $numbers) {\n    Write-Output $num\n}\n\n# \u68c0\u67e5\u5143\u7d20\u662f\u5426\u5b58\u5728\nif (3 -in $numbers) {\n    Write-Output &quot;\u6570\u7ec4\u4e2d\u5305\u542b 3&quot;\n}\n<\/code><\/pre>\n<hr>\n<h3>9. \u54c8\u5e0c\u8868\u64cd\u4f5c<\/h3>\n<h4>9.1 \u521b\u5efa\u54c8\u5e0c\u8868<\/h4>\n<pre><code class=\"language-powershell\"># \u65b9\u5f0f1\uff1a\u521b\u5efa\u65f6\u5b9a\u4e49\n$user = @{\n    Name = &quot;\u5f20\u4e09&quot;\n    Age = 30\n    City = &quot;\u5317\u4eac&quot;\n}\n\n# \u65b9\u5f0f2\uff1a\u9010\u6b65\u6dfb\u52a0\n$user = @{}\n$user[&quot;Name&quot;] = &quot;\u5f20\u4e09&quot;\n$user[&quot;Age&quot;] = 30\n$user[&quot;City&quot;] = &quot;\u5317\u4eac&quot;\n<\/code><\/pre>\n<h4>9.2 \u8bbf\u95ee\u54c8\u5e0c\u8868<\/h4>\n<pre><code class=\"language-powershell\">$user = @{\n    Name = &quot;\u5f20\u4e09&quot;\n    Age = 30\n    City = &quot;\u5317\u4eac&quot;\n}\n\n# \u8bbf\u95ee\u5355\u4e2a\u503c\nWrite-Output $user[&quot;Name&quot;]  # \u8f93\u51fa\uff1a\u5f20\u4e09\nWrite-Output $user.Name     # \u8f93\u51fa\uff1a\u5f20\u4e09\n\n# \u8bbf\u95ee\u6240\u6709\u952e\nWrite-Output $user.Keys  # \u8f93\u51fa\uff1aName, Age, City\n\n# \u8bbf\u95ee\u6240\u6709\u503c\nWrite-Output $user.Values  # \u8f93\u51fa\uff1a\u5f20\u4e09, 30, \u5317\u4eac\n<\/code><\/pre>\n<hr>\n<h2>\ud83c\udfae \u5b9e\u6218\u793a\u4f8b<\/h2>\n<h3>\u793a\u4f8b 1: \u7528\u6237\u4fe1\u606f\u7ba1\u7406<\/h3>\n<pre><code class=\"language-powershell\"># \u521b\u5efa\u7528\u6237\u4fe1\u606f\u54c8\u5e0c\u8868\n$user = @{\n    Name = &quot;\u5f20\u4e09&quot;\n    Age = 30\n    Email = &quot;zhangsan@example.com&quot;\n    Department = &quot;\u6280\u672f\u90e8&quot;\n}\n\n# \u663e\u793a\u7528\u6237\u4fe1\u606f\nWrite-Output &quot;\u7528\u6237\u4fe1\u606f\uff1a&quot;\nWrite-Output &quot;\u59d3\u540d\uff1a$($user.Name)&quot;\nWrite-Output &quot;\u5e74\u9f84\uff1a$($user.Age)&quot;\nWrite-Output &quot;\u90ae\u7bb1\uff1a$($user.Email)&quot;\nWrite-Output &quot;\u90e8\u95e8\uff1a$($user.Department)&quot;\n\n# \u66f4\u65b0\u7528\u6237\u4fe1\u606f\n$user.Age = 31\nWrite-Output &quot;\u66f4\u65b0\u540e\u7684\u5e74\u9f84\uff1a$($user.Age)&quot;\n<\/code><\/pre>\n<h3>\u793a\u4f8b 2: \u5546\u54c1\u4ef7\u683c\u8ba1\u7b97<\/h3>\n<pre><code class=\"language-powershell\"># \u5546\u54c1\u4ef7\u683c\u548c\u6570\u91cf\n$prices = 19.9, 29.9, 39.9\n$quantities = 2, 1, 3\n\n# \u8ba1\u7b97\u603b\u4ef7\n$total = 0\nfor ($i = 0; $i -lt $prices.Length; $i++) {\n    $itemTotal = $prices[$i] * $quantities[$i]\n    $total += $itemTotal\n}\n\nWrite-Output &quot;\u8ba2\u5355\u603b\u4ef7\uff1a$total \u5143&quot;\n<\/code><\/pre>\n<h3>\u793a\u4f8b 3: \u6570\u636e\u7c7b\u578b\u8f6c\u6362<\/h3>\n<pre><code class=\"language-powershell\"># \u4ece\u7528\u6237\u8f93\u5165\u83b7\u53d6\u5e74\u9f84\n$userInput = &quot;25&quot;\n\n# \u8f6c\u6362\u4e3a\u6574\u6570\n$age = [int]$userInput\n\n# \u9a8c\u8bc1\u8f6c\u6362\u7ed3\u679c\nif ($age -gt 0) {\n    Write-Output &quot;\u5e74\u9f84\uff1a$age&quot;\n    # \u8ba1\u7b97\u51fa\u751f\u5e74\u4efd\n    $currentYear = (Get-Date).Year\n    $birthYear = $currentYear - $age\n    Write-Output &quot;\u51fa\u751f\u5e74\u4efd\uff1a$birthYear&quot;\n} else {\n    Write-Output &quot;\u8bf7\u8f93\u5165\u6709\u6548\u7684\u5e74\u9f84&quot;\n}\n<\/code><\/pre>\n<h3>\u793a\u4f8b 4: \u6570\u7ec4\u7b5b\u9009<\/h3>\n<pre><code class=\"language-powershell\"># \u6570\u5b57\u5217\u8868\n$numbers = 15, 8, 23, 42, 7, 19, 33, 5\n\n# \u7b5b\u9009\u5927\u4e8e 20 \u7684\u6570\u5b57\n$largeNumbers = $numbers | Where-Object { $_ -gt 20 }\n\nWrite-Output &quot;\u5927\u4e8e 20 \u7684\u6570\u5b57\uff1a&quot;\n$largeNumbers | ForEach-Object { Write-Output $_ }\n\n# \u7b5b\u9009\u5076\u6570\n$evenNumbers = $numbers | Where-Object { $_ % 2 -eq 0 }\nWrite-Output &quot;\u5076\u6570\uff1a&quot;\n$evenNumbers | ForEach-Object { Write-Output $_ }\n<\/code><\/pre>\n<hr>\n<h2>\u26a0\ufe0f \u91cd\u8981\u6ce8\u610f\u4e8b\u9879<\/h2>\n<h3>1. \u53d8\u91cf\u547d\u540d\u6700\u4f73\u5b9e\u8df5<\/h3>\n<pre><code class=\"language-powershell\"># \u2705 \u597d\u7684\u547d\u540d\n$userName = &quot;\u5f20\u4e09&quot;\n$fileCount = 10\n$isValid = $true\n\n# \u274c \u907f\u514d\u7684\u547d\u540d\n$x = &quot;\u5f20\u4e09&quot;\n$n = &quot;\u5f20\u4e09&quot;\n$flag = $true\n<\/code><\/pre>\n<h3>2. \u7c7b\u578b\u8f6c\u6362\u9677\u9631<\/h3>\n<pre><code class=\"language-powershell\"># \u5b57\u7b26\u4e32\u62fc\u63a5 vs \u6570\u5b57\u52a0\u6cd5\n$a = &quot;10&quot;\n$b = &quot;20&quot;\nWrite-Output ($a + $b)  # \u8f93\u51fa\uff1a1020\uff08\u5b57\u7b26\u4e32\u62fc\u63a5\uff09\n\n$a = 10\n$b = 20\nWrite-Output ($a + $b)  # \u8f93\u51fa\uff1a30\uff08\u6570\u5b57\u76f8\u52a0\uff09\n<\/code><\/pre>\n<h3>3. \u7a7a\u503c\u5904\u7406<\/h3>\n<pre><code class=\"language-powershell\">$value = $null\n\n# \u68c0\u67e5\u53d8\u91cf\u662f\u5426\u4e3a\u7a7a\nif ($null -eq $value) {\n    Write-Output &quot;\u53d8\u91cf\u4e3a\u7a7a&quot;\n}\n\n# \u4f7f\u7528\u7a7a\u503c\u5408\u5e76\u8fd0\u7b97\u7b26\n$result = $value -ne $null ? $value : &quot;\u9ed8\u8ba4\u503c&quot;\nWrite-Output $result\n<\/code><\/pre>\n<h3>4. \u6570\u7ec4\u548c\u54c8\u5e0c\u8868\u7684\u533a\u522b<\/h3>\n<pre><code class=\"language-powershell\"># \u6570\u7ec4\uff1a\u7d22\u5f15\u8bbf\u95ee\n$array = 1, 2, 3\nWrite-Output $array[0]\n\n# \u54c8\u5e0c\u8868\uff1a\u952e\u8bbf\u95ee\n$hash = @{Key = &quot;Value&quot;}\nWrite-Output $hash[&quot;Key&quot;]\n<\/code><\/pre>\n<hr>\n<h2>\u270d\ufe0f \u7ec3\u4e60\u4efb\u52a1<\/h2>\n<h3>\u57fa\u7840\u7ec3\u4e60<\/h3>\n<ol>\n<li>\n<p><strong>\u53d8\u91cf\u521b\u5efa<\/strong><\/p>\n<ul>\n<li>\u521b\u5efa\u53d8\u91cf\u5b58\u50a8\u4f60\u7684\u59d3\u540d\u3001\u5e74\u9f84\u3001\u57ce\u5e02<\/li>\n<li>\u521b\u5efa\u53d8\u91cf\u5b58\u50a8\u4e00\u4e2a\u6570\u5b57\u5217\u8868<\/li>\n<li>\u521b\u5efa\u53d8\u91cf\u5b58\u50a8\u4e00\u4e2a\u7528\u6237\u4fe1\u606f\u54c8\u5e0c\u8868<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u7c7b\u578b\u8f6c\u6362<\/strong><\/p>\n<ul>\n<li>\u5c06\u5b57\u7b26\u4e32 &quot;123&quot; \u8f6c\u6362\u4e3a\u6574\u6570\u5e76\u52a0\u4e0a 50<\/li>\n<li>\u5c06\u6570\u5b57 3.14159 \u8f6c\u6362\u4e3a\u6574\u6570<\/li>\n<li>\u5c06\u6570\u5b57 0 \u8f6c\u6362\u4e3a\u5e03\u5c14\u503c\u5e76\u67e5\u770b\u7ed3\u679c<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u6570\u7ec4\u64cd\u4f5c<\/strong><\/p>\n<ul>\n<li>\u521b\u5efa\u4e00\u4e2a\u5305\u542b 5 \u4e2a\u6570\u5b57\u7684\u6570\u7ec4<\/li>\n<li>\u8ba1\u7b97\u6570\u7ec4\u4e2d\u6240\u6709\u6570\u5b57\u7684\u548c<\/li>\n<li>\u627e\u51fa\u6570\u7ec4\u4e2d\u6700\u5927\u7684\u6570\u5b57<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<h3>\u8fdb\u9636\u7ec3\u4e60<\/h3>\n<ol start=\"4\">\n<li>\n<p><strong>\u54c8\u5e0c\u8868\u64cd\u4f5c<\/strong><\/p>\n<ul>\n<li>\u521b\u5efa\u4e00\u4e2a\u5b66\u751f\u4fe1\u606f\u54c8\u5e0c\u8868\uff08\u59d3\u540d\u3001\u5e74\u9f84\u3001\u73ed\u7ea7\u3001\u6210\u7ee9\uff09<\/li>\n<li>\u6dfb\u52a0\u4e00\u4e2a\u65b0\u7684\u5b57\u6bb5&quot;\u662f\u5426\u53ca\u683c&quot;<\/li>\n<li>\u6839\u636e\u6210\u7ee9\u5224\u65ad\u662f\u5426\u53ca\u683c\uff0860\u5206\u4ee5\u4e0a\uff09<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u6570\u636e\u7b5b\u9009<\/strong><\/p>\n<ul>\n<li>\u521b\u5efa\u4e00\u4e2a\u6570\u5b57\u6570\u7ec4 [12, 45, 67, 23, 89, 34, 56]<\/li>\n<li>\u7b5b\u9009\u51fa\u6240\u6709\u5927\u4e8e 40 \u7684\u6570\u5b57<\/li>\n<li>\u7b5b\u9009\u51fa\u6240\u6709\u5076\u6570<\/li>\n<li>\u7b5b\u9009\u51fa\u6240\u6709\u80fd\u88ab 3 \u6574\u9664\u7684\u6570\u5b57<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<h3>\u5b9e\u6218\u6311\u6218<\/h3>\n<ol start=\"6\">\n<li>\n<p><strong>\u8d2d\u7269\u8f66\u7cfb\u7edf<\/strong><\/p>\n<ul>\n<li>\u521b\u5efa\u4e00\u4e2a\u5546\u54c1\u4fe1\u606f\u6570\u7ec4\uff08\u5546\u54c1\u540d\u3001\u4ef7\u683c\u3001\u6570\u91cf\uff09<\/li>\n<li>\u8ba1\u7b97\u6bcf\u79cd\u5546\u54c1\u7684\u5c0f\u8ba1<\/li>\n<li>\u8ba1\u7b97\u8ba2\u5355\u603b\u4ef7<\/li>\n<li>\u5982\u679c\u603b\u4ef7\u8d85\u8fc7 100\uff0c\u663e\u793a&quot;\u5305\u90ae&quot;\uff0c\u5426\u5219\u663e\u793a&quot;\u8fd0\u8d39 10 \u5143&quot;<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u5b66\u751f\u6210\u7ee9\u7ba1\u7406<\/strong><\/p>\n<ul>\n<li>\u521b\u5efa\u4e00\u4e2a\u5b66\u751f\u6210\u7ee9\u54c8\u5e0c\u8868<\/li>\n<li>\u6dfb\u52a0\u59d3\u540d\u3001\u8bed\u6587\u3001\u6570\u5b66\u3001\u82f1\u8bed\u6210\u7ee9<\/li>\n<li>\u8ba1\u7b97\u603b\u5206\u548c\u5e73\u5747\u5206<\/li>\n<li>\u5224\u65ad\u662f\u5426\u4f18\u79c0\uff08\u5e73\u5747\u5206\u226590\uff09\u3001\u826f\u597d\uff0880\u2264\u5e73\u5747\u5206&lt;90\uff09\u3001\u53ca\u683c\uff0860\u2264\u5e73\u5747\u5206&lt;80\uff09<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<hr>\n<h2>\ud83d\udca1 \u5e38\u89c1\u95ee\u9898 FAQ<\/h2>\n<p><strong>Q1: PowerShell \u7684\u53d8\u91cf\u540d\u533a\u5206\u5927\u5c0f\u5199\u5417\uff1f<\/strong><\/p>\n<ul>\n<li>A1: PowerShell \u4e0d\u533a\u5206\u5927\u5c0f\u5199\uff0c<code>$Name<\/code> \u548c <code>$name<\/code> \u662f\u540c\u4e00\u4e2a\u53d8\u91cf\u3002\u4f46\u5efa\u8bae\u4fdd\u6301\u4e00\u81f4\u6027\uff0c\u4f7f\u7528\u9a7c\u5cf0\u547d\u540d\u6cd5\u3002<\/li>\n<\/ul>\n<p><strong>Q2: \u4ec0\u4e48\u65f6\u5019\u4f7f\u7528\u5355\u5f15\u53f7\uff0c\u4ec0\u4e48\u65f6\u5019\u4f7f\u7528\u53cc\u5f15\u53f7\uff1f<\/strong><\/p>\n<ul>\n<li>A2: \u5355\u5f15\u53f7\u8868\u793a\u5b57\u9762\u5b57\u7b26\u4e32\uff08\u4e0d\u89e3\u6790\u53d8\u91cf\uff09\uff0c\u53cc\u5f15\u53f7\u8868\u793a\u53ef\u6269\u5c55\u5b57\u7b26\u4e32\uff08\u89e3\u6790\u53d8\u91cf\uff09\u3002<\/li>\n<\/ul>\n<p><strong>Q3: \u5982\u4f55\u5220\u9664\u4e00\u4e2a\u53d8\u91cf\uff1f<\/strong><\/p>\n<ul>\n<li>A3: \u4f7f\u7528 <code>Remove-Variable<\/code> \u547d\u4ee4\uff1a\n<pre><code class=\"language-powershell\">Remove-Variable -Name &quot;myVar&quot;\n<\/code><\/pre>\n<\/li>\n<\/ul>\n<p><strong>Q4: \u6570\u7ec4\u548c\u54c8\u5e0c\u8868\u6709\u4ec0\u4e48\u533a\u522b\uff1f<\/strong><\/p>\n<ul>\n<li>A4: \u6570\u7ec4\u4f7f\u7528\u6570\u5b57\u7d22\u5f15\uff080, 1, 2&#8230;\uff09\uff0c\u54c8\u5e0c\u8868\u4f7f\u7528\u952e\u540d\uff08Name, Age, Email&#8230;\uff09\u3002<\/li>\n<\/ul>\n<p><strong>Q5: \u5982\u4f55\u68c0\u67e5\u53d8\u91cf\u7684\u7c7b\u578b\uff1f<\/strong><\/p>\n<ul>\n<li>A5: \u4f7f\u7528 <code>.GetType()<\/code> \u65b9\u6cd5\uff1a\n<pre><code class=\"language-powershell\">$value = 123\n$value.GetType().Name  # \u8f93\u51fa\uff1aInt32\n<\/code><\/pre>\n<\/li>\n<\/ul>\n<hr>\n<h2>\ud83d\udcda \u62d3\u5c55\u9605\u8bfb<\/h2>\n<ul>\n<li><a href=\"https:\/\/docs.microsoft.com\/zh-cn\/powershell\/scripting\/variables\/\">PowerShell \u53d8\u91cf\u5b98\u65b9\u6587\u6863<\/a><\/li>\n<li><a href=\"https:\/\/docs.microsoft.com\/zh-cn\/powershell\/scripting\/walking-lang\/understanding-variables\/\">PowerShell \u6570\u636e\u7c7b\u578b<\/a><\/li>\n<li><a href=\"https:\/\/docs.microsoft.com\/zh-cn\/powershell\/scripting\/walking-lang\/working-arrays\/\">PowerShell \u6570\u7ec4\u548c\u54c8\u5e0c\u8868<\/a><\/li>\n<\/ul>\n<hr>\n<p><strong>\ud83c\udf93 \u4eca\u65e5\u603b\u7ed3<\/strong><\/p>\n<p>\u53d8\u91cf\u548c\u6570\u636e\u7c7b\u578b\u662f PowerShell \u7f16\u7a0b\u7684\u57fa\u7840\u3002\u901a\u8fc7\u638c\u63e1\u53d8\u91cf\u7684\u521b\u5efa\u3001\u8d4b\u503c\u3001\u4f5c\u7528\u57df\uff0c\u4ee5\u53ca\u5404\u79cd\u6570\u636e\u7c7b\u578b\u7684\u8f6c\u6362\uff0c\u4f60\u53ef\u4ee5\u5f00\u59cb\u7f16\u5199\u5b9e\u7528\u7684 PowerShell \u811a\u672c\u3002\u8bb0\u4f4f\uff1aPowerShell \u662f\u5f31\u7c7b\u578b\u8bed\u8a00\uff0c\u4f46\u4e86\u89e3\u6570\u636e\u7c7b\u578b\u5bf9\u4e8e\u7f16\u5199\u5065\u58ee\u7684\u811a\u672c\u4ecd\u7136\u5f88\u91cd\u8981\u3002<\/p>\n<p><strong>\u23ed\ufe0f \u660e\u5929\u9884\u544a<\/strong>: Day 4 &#8211; \u8fd0\u7b97\u7b26\u4e0e\u8868\u8fbe\u5f0f\uff0c\u6211\u4eec\u5c06\u6df1\u5165\u5b66\u4e60 PowerShell \u7684\u5404\u79cd\u8fd0\u7b97\u7b26\u548c\u8868\u8fbe\u5f0f\u3002<\/p>\n<hr>\n<p><em>\u5b66\u4e60\u65f6\u95f4: 2026-03-31<\/em><br \/>\n<em>\u8bfe\u7a0b\u8fdb\u5ea6: Day 3 \/ 30<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Day 3: \u53d8\u91cf\u4e0e\u6570\u636e\u7c7b\u578b \ud83c\udfaf \u5b66\u4e60\u76ee\u6807 \u7406\u89e3\u53d8\u91cf\u7684\u6982\u5ff5\u548c\u4f5c\u7528 \u638c\u63e1 PowerShell \u7684\u57fa\u672c\u6570\u636e\u7c7b\u578b  &#8230; <a title=\"Day-3-\u53d8\u91cf\u4e0e\u6570\u636e\u7c7b\u578b\" class=\"read-more\" href=\"https:\/\/www.resilence.cn\/?p=317\" aria-label=\"\u7ee7\u7eed\u9605\u8bfbDay-3-\u53d8\u91cf\u4e0e\u6570\u636e\u7c7b\u578b\">\u9605\u8bfb\u66f4\u591a<\/a><\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-317","post","type-post","status-publish","format-standard","hentry","category-powershell"],"_links":{"self":[{"href":"https:\/\/www.resilence.cn\/index.php?rest_route=\/wp\/v2\/posts\/317","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.resilence.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.resilence.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.resilence.cn\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.resilence.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=317"}],"version-history":[{"count":1,"href":"https:\/\/www.resilence.cn\/index.php?rest_route=\/wp\/v2\/posts\/317\/revisions"}],"predecessor-version":[{"id":318,"href":"https:\/\/www.resilence.cn\/index.php?rest_route=\/wp\/v2\/posts\/317\/revisions\/318"}],"wp:attachment":[{"href":"https:\/\/www.resilence.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=317"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.resilence.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=317"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.resilence.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=317"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}