---
title_en: "Write Your First PowerShell Command with AI"
title_cn: "用 AI 写出你的第一条 PowerShell 命令"
series: "AI-Powered Office: From Beginner to Expert"
article_code: "B17"
level: "L1"
category: "AI Office"
subcategory: "Automation"
tags: "PowerShell,Command Line,AI,ChatGPT,L1"
status: "草稿"
bilingual_switch: "双语"
author: "程晓"
translator: "易安"
---


> 📎 **配套资产 / Companion assets**：本篇所有示例的可下载文件在仓库 `配套资产/B17_第一条命令/`——5 条入门命令脚本 + 安全红线演示脚本（中英各一份），每个子目录都带中文 README 与 English README。
> English: downloadable files for every example in this article live in `配套资产/B17_第一条命令/` — five starter-command scripts + a security red-line demo (each in CN & EN), each with a bilingual README.
# [Automation]Write Your First PowerShell Command with AI

> **Summary**: Use Copilot / ChatGPT to help you write your very first PowerShell command, run it safely, and export a file list — so the black window never scares you again.

> ⚠️ **Don't touch the keyboard just yet** — this article is written for anyone who "breaks into a cold sweat at the sight of a black window." In the next 15 minutes we won't memorize any syntax. Instead, we'll let that black window do one real job for you: turn every file in a folder into a list you can open in Excel.

---

## 1. The Pain Point: Sound Familiar?

Your boss asks you to organize a list (file name, size, last-modified time) of a few hundred files in some folder on the server. You open the folder and can only copy them by hand — and by the 20th entry you want to smash the keyboard.

A coworker says, "That's a one-liner." You nervously open a black window like they said, and then:

- What is this black window even called? CMD? PowerShell? Which one did I actually open?
- I don't dare press Enter on the command they gave me — **what if it deletes the company's files?**
- I type it, hit Enter, and a wall of red error text appears that I can't understand a single word of, so I close it fast.
- Commands I find online are full of parameters — `-Recurse`, `|`, `$` — they look like gibberish.

If any of those hit home, this article is for you. Our idea is simple: **let AI be your translator + sparring partner** — you speak plain language, AI produces the command and explains it word by word, and you learn "how to tell whether this command is safe" before you press Enter yourself. **AI draws the blueprint, you verify it, you do the construction.**

---

## 2. What You'll Walk Away With (Goal)

After following along you'll have three things:

1. **The courage to open the black window**: you'll know what PowerShell is, how to open it, how to tell at a glance whether you're actually in PowerShell, and when you should absolutely NOT use "Run as administrator."
2. **One command that actually does real work**: it sorts the files in a folder by size and exports them to `文件清单.csv`, which opens in Excel with a double-click.
3. **A self-check method for "can I actually run the command AI gave me?"** (check the verb, check the parameters, check the path), plus a prompt you can throw the error back at AI with when something goes wrong.

**Let's define a few words first, so nothing trips you up later:**

- **PowerShell** = an automation tool built into Windows that you drive by "typing commands." Things that take you thirty mouse clicks can be done in one line of text.
- **"The black window"** = the black-background, white-text window that appears when you open PowerShell (or the "Terminal"). Its proper name is the **command-line window / terminal**. It's not mysterious — it's just a window you type into and can't click.
- **Command (cmdlet, pronounced "command-let")** = one instruction in PowerShell. They look remarkably uniform, always in a "**Verb-Noun**" two-part shape — for example `Get-ChildItem` (Get = get, ChildItem = child item, together it means "list the things in this folder for me").
- **Parameter** = the extra wording that follows a command and clarifies "what to act on, and how," usually starting with a single dash — for example `-Path "D:\报销单"` tells it "act on this path."
- **The pipe `|`** (that vertical bar above the Enter key, typed with Shift + `\`) = **feed the result of the previous command straight into the next one for further processing**, like a conveyor belt on an assembly line.

---

## 3. When This Helps & What You Need First

### 3.1 When This Helps

- You need to produce a list of a bunch of files, build an asset ledger, or reconcile files during a handover;
- You want to know which files on your computer eat up the most space;
- Most importantly: **you want to get past the "afraid to open the black window" hurdle**, laying the groundwork for later batch-processing Excel / Word with scripts.

This article runs on one example throughout: **export the files in the folder `D:\工作\2026年报销单` into a list**. Just swap the path for your own.

### 3.2 Prerequisites (Read This First — It'll Save You Half an Hour of Missteps)

**① PowerShell prerequisites (good news: nothing to install)**

- PowerShell comes **built into Windows 10 / Windows 11**, and the features this article uses **need no download, no install, and no payment**.
- This article also **needs no administrator rights** — we only do harmless operations like "read file names."

**② AI assistant prerequisites**

- Pick one of two tools: **Microsoft Copilot** (web version at `https://copilot.microsoft.com`, just sign in with a Microsoft account; you can also use the Copilot app built into Windows 11) or **ChatGPT** (`https://chatgpt.com`).
- The **free tier of either is enough for this article** — no paid plan required.
- **You need an internet connection.**
- ⚠️ One fact that must be stated clearly: the web/app versions of Copilot and ChatGPT **only give you text — they won't run commands on your computer for you**. So the flow is always: AI produces the command → **you understand it** → you copy it into PowerShell and press Enter. Don't expect AI to do that last step for you — and that is precisely your safety valve.

**③ Version assumptions (the interface may differ slightly)**

- This article targets **Windows 11 + the built-in Windows PowerShell 5.1**; **Windows 10 works exactly the same**, only the menu names for opening it differ (explained separately in Step 1 below).
- If you've installed **PowerShell 7** (a newer version Microsoft offers separately, with the program name `pwsh`), every command in this article runs fine too; I'll flag the few differences (mainly the CSV encoding one, see FAQ Q3).
- Not sure which version you have? Step 1 will teach you a command to find out.

### 3.3 Three Safety Red Lines (Please Read This Section Before Going Further)

When beginners crash and burn with the command line, it's almost always on these three. **Memorize them — they matter far more than memorizing commands.**

1. **Never press Enter on a command you don't understand.** Whether a coworker sent it, you copied it from the web, or AI gave it to you. If you don't get it, have AI explain it word by word first (there's a ready-made prompt in Step 4).
2. **AI makes mistakes — it can even invent commands and parameters that don't exist.** This is called "hallucination" — and it makes them up convincingly. So every command AI gives you must pass your own security check (the "three-check method" in Step 5).
3. **Don't use "Run as administrator" unless you actually need to.** Under a normal account, the system blocks many dangerous operations — that's your insurance. Under an administrator account, one wrong command can punch a real hole. This article **never needs** administrator rights.

> 🚫 **Blacklist**: if a command from AI or a web post contains any of the following, **stop immediately** and ask "what will this change on my machine?" before doing anything: `Remove-Item` (delete), `Format-Volume` (format), `Set-ExecutionPolicy` (change the script-execution policy), `Invoke-Expression` / `iex` / `irm ... | iex` (download a chunk of code from the web and run it directly). These aren't forbidden forever — but **as a beginner you shouldn't use them until you understand them.**

---

## 4. Walkthrough: From Opening the Black Window to Running Your First Command

Seven steps in total. The first three are warm-up (guaranteeing you're 100% safe); Step 4 is where AI starts helping.

### 4.1 Step 1: Open the Black Window and Confirm You Opened the Right One

**How to open it (pick any one):**

- **Way A (most reliable, works on both Win10/Win11)**: click the Start menu, type `powershell`, and in the search results click **"Windows PowerShell."**
- **Way B**: press `Win + R`, type `powershell`, and press Enter.
- **Way C**: **right-click** the Start button (or press `Win + X`) — in Windows 11 click **"Terminal,"** in Windows 10 click **"Windows PowerShell."**

Once open you'll see a line like this; it's called the **prompt**:

```text
PS C:\Users\your-username>
```

Broken down, it's actually reporting three things to you:

| What you see | What it means |
|--------------|---------------|
| `PS` | You're in **P**ower**S**hell (this is the key sign! If there's no `PS` at the start, you most likely opened CMD — see Pitfall 4) |
| `C:\Users\your-username` | The **folder you're currently in** (commands act here by default) |
| `>` | "Please type" — the cursor sits after it |

**Confirm two more things:**

- Look at the window's **title bar**: if it says "**Administrator**: Windows PowerShell," you opened an administrator window. **This article doesn't need that** — close it and open a normal one.
- To find your version, type the line below and press Enter (this only reads information — perfectly safe):

```powershell
$PSVersionTable
```

After pressing Enter, look at the `PSVersion` line: if it shows `5.1.xxxxx` you're on the built-in Windows PowerShell 5.1; if it shows `7.x.x` you're on PowerShell 7.

> 💡 The `$` in front of `$PSVersionTable` means it's a **variable** (a little box holding information), not a command. So it doesn't have the "Verb-Noun" shape — that's normal.

**Screenshot tip**: ① the Start-menu search results for `powershell` (mark the "Windows PowerShell" item); ② the freshly opened window, with the `PS` and current path in the prompt circled in red; ③ the `$PSVersionTable` output, with the `PSVersion` line marked.

**Key point**: as long as the prompt starts with `PS` and the title bar doesn't say "Administrator," you're standing in the safest possible spot.

### 4.2 Step 2: Run Three "Absolutely Can't-Go-Wrong" Commands to Warm Up

Don't touch AI yet. These three commands are pure read-only — they **change nothing on your computer**, so there's no way to break anything. Type them one at a time, pressing Enter after each.

```powershell
Get-Date
```

👉 The screen prints the current date and time. Translation: Get = get, Date = date.

```powershell
Get-Location
```

👉 Prints the folder path you're currently in (the same string as in the prompt). Translation: get my current location.

```powershell
Get-ChildItem
```

👉 **Lists** the files and subfolders in the current folder, in four columns: `Mode` (type; entries starting with `d` are folders), `LastWriteTime` (last-modified time), `Length` (file size, in **bytes**), and `Name` (name).

**Spot the pattern?** All three commands start with `Get-`. That's PowerShell's friendliest design:

> **A command's verb tells you exactly what it will do. Commands starting with `Get-` = look only, don't touch, read information, safe.**

**Screenshot tip**: a full screenshot of the window after running all three commands in a row, so readers can compare their output to yours.

**Key point**: you've already run three real commands. The black window didn't bite, did it? Now let's put it to real work.

### 4.3 Step 3: First Get the "Folder Path" Exactly Right

90% of beginner errors are typo'd paths. Don't type it by hand — copy it using a built-in Windows feature:

1. In File Explorer, find the folder you want to organize (example: `2026年报销单`);
2. **Hold `Shift` and right-click** the folder → click **"Copy as path"** (in Windows 11 this is usually right there in the right-click menu, with the shortcut `Ctrl + Shift + C`);
3. Your clipboard now holds the **full path wrapped in double quotes**, for example `"D:\工作\2026年报销单"`.

**Screenshot tip**: the Shift + right-click menu, with "Copy as path" circled.

**Key point**: this copy comes with the double quotes already attached, which neatly solves the classic "path with spaces throws an error" problem (see Pitfall 3). When you paste it into a command, don't delete the quotes.

### 4.4 Step 4: Tell AI What You Need (Prompt Text)

Open `https://copilot.microsoft.com` (or `https://chatgpt.com`), copy the block below **in full** and send it — but swap the path for the one you copied in the previous step:

```text
I'm a complete PowerShell beginner, using the Windows PowerShell 5.1 that comes built into Windows 11,
and I don't want to run as administrator.

My need: in the folder "D:\工作\2026年报销单", list every file,
with three columns — "file name, size, last-modified time" — sorted from largest to smallest by file size.

Please answer me strictly in this format:
1) The complete command, written on a single line, that I can copy and run directly;
2) Break the command down word by word, explaining what each word and each parameter does;
3) Answer clearly: will this command modify, move, or delete my original files?
4) Answer clearly: does it need to run as administrator?
5) If there's a safer or simpler way to write this command, tell me that too.

Requirements: only use commands that run on built-in Windows PowerShell 5.1, not ones needing extra installed modules,
and not Linux/macOS syntax. Explain in plain everyday language — I don't understand the jargon.
```

**Screenshot tip**: the AI chat box with this prompt pasted in, ready to send.

**Key point (why this prompt is written this way):**

- It states the **environment** (Win11 + PowerShell 5.1 + no administrator) → stops it giving you Linux commands or ones needing installs;
- It states the **format requirement** (single line, word-by-word explanation) → so you can understand it, instead of receiving a blob of jargon;
- Items 3 and 4 **deliberately make it declare safety itself** — that becomes your basis for checking later;
- The final line "I don't understand the jargon" → it automatically switches into plain-language mode.

AI will most likely give you this command (wording may differ; the core should match):

```powershell
Get-ChildItem -Path "D:\工作\2026年报销单" -File | Sort-Object Length -Descending | Select-Object Name, Length, LastWriteTime
```

It looks long, but it's really **three operations strung together by the conveyor belt `|`**:

| Segment | Command | What it does (in plain language) |
|---------|---------|----------------------------------|
| ① | `Get-ChildItem -Path "..." -File` | List the things in this folder; `-File` means **only files, not subfolders** |
| ② | `Sort-Object Length -Descending` | Sort the previous result by `Length` (size), `-Descending` = **largest first** |
| ③ | `Select-Object Name, Length, LastWriteTime` | From all that info, **pick just these three columns** for me |

All three segments are "get / sort / pick" — not a single word about delete, modify, or write. That's exactly what we want.

### 4.5 Step 5: The Security Check "Three-Check Method" — Why You Can Press Enter with Confidence on a Command AI Gave You

**This step is the most valuable part of the whole article.** No matter who gave you the command, run it through three gates before pressing Enter — takes 10 seconds:

**Check 1: Look at the verb (judge the danger level)**

Pull out the **verb** from every "Verb-Noun" in the command, and match it against this table:

| Verb | Meaning | Danger level |
|------|---------|--------------|
| `Get-` | get, look | 🟢 read-only, safe |
| `Select-` / `Sort-` / `Where-` / `Measure-` | pick, sort, filter, calculate | 🟢 only processes data in memory, touches no files |
| `Export-` / `Out-File` / `New-` | export, create new | 🟡 **writes a new file** — watch out for clobbering an existing file of the same name |
| `Set-` / `Rename-` / `Move-` | modify, rename, move | 🟠 makes changes — understand it before running |
| `Remove-` / `Clear-` / `Stop-` / `Format-Volume` | delete, clear, stop, format a disk | 🔴 **stop.** As a beginner, don't run these until you understand them |
| `Format-Table` / `Format-List` and friends | merely **format the output display** (read-only) — nothing to do with formatting a disk; safe to use | 🟢 common |

The command above has verbs `Get- / Sort- / Select-` — all green → safe to run.

> 💡 Want to know every verb PowerShell recognizes? Run `Get-Verb` — it lists all the official standard verbs (pure read, safe).

**Check 2: Check the parameters (guard against AI making them up)**

The mistake AI loves most is **getting a parameter name wrong** — for example writing `-Recurse` (recurse into subfolders) as `-Recursive` (which **doesn't exist** in PowerShell). Two ways to verify:

- **Let PowerShell tell you itself** — run this, and it opens the official Microsoft documentation page with the full parameter list (needs internet):

```powershell
Get-Help Get-ChildItem -Online
```

> Note: if you run `Get-Help Get-ChildItem -Examples` directly, Windows PowerShell 5.1 may say "help files not found," because the system doesn't ship the complete help docs by default. So for beginners, just use `-Online` to read the web version — easiest.

- **Let AI self-check** — send the command back as-is and have it confirm each parameter exists (prompt in Section 5, "Security-Check Prompt").

**Check 3: Verify the path (guard against acting in the wrong place)**

- The path **must be wrapped in double quotes**;
- Is the path really the folder you want to process? Pay special attention: **don't run the command against a system directory like `C:\Windows`**;
- The desktop path has a trap: if your desktop is taken over by OneDrive sync, the real path may be `C:\Users\you\OneDrive\Desktop` rather than `C:\Users\you\Desktop`. So again, "Copy as path" from Step 3 is the safest bet.

All three gates passed → **copy the command, paste it into the PowerShell window with `Ctrl + V` (right-click paste also works), make sure it's a single line with no line breaks, and press Enter.**

**Screenshot tip**: the output after running the command — a three-column table sorted by size (Name / Length / LastWriteTime).

**Key point**: the unit of the `Length` column is **bytes**. `1048576` bytes = 1 MB. To see MB directly, see Section 9.

### 4.6 Step 6: Add One More Conveyor Segment — Export the Result to an Excel-Openable CSV

Seeing it is nice, but saving it is better. Append **one more pipe segment** to the end of the original command and hand it to `Export-Csv`:

First run this line to store the "real desktop path" in a variable (this step dodges the OneDrive trap above):

```powershell
$Desktop = [Environment]::GetFolderPath("Desktop")
```

> Plain language: `$Desktop` is a little box; the string on the right asks Windows "where on this machine is the desktop, really," and drops the answer in the box. After pressing Enter, **it's normal for nothing to appear on screen** — it just stored the value, didn't print it. Want to see what's inside? Type `$Desktop` and press Enter.

Then run the real one-liner (**this is a complete single line — don't break it**):

```powershell
Get-ChildItem -Path "D:\工作\2026年报销单" -File | Sort-Object Length -Descending | Select-Object Name, Length, LastWriteTime | Export-Csv -Path "$Desktop\文件清单.csv" -NoTypeInformation -Encoding UTF8
```

Explaining the newly added parts:

| Part | Plain language |
|------|----------------|
| `Export-Csv` | Saves the data on the conveyor into a **CSV file** (CSV = a comma-separated table file that Excel can open with a double-click) |
| `-Path "$Desktop\文件清单.csv"` | Save to the desktop, file name `文件清单.csv` |
| `-NoTypeInformation` | **Don't shove a pile of technical junk into the first row of the file.** Without this parameter, the CSV exported by 5.1 puts a useless `#TYPE ...` line at the top, which is just annoying |
| `-Encoding UTF8` | Save in UTF-8, so **Chinese file names won't turn into garbled text** (PowerShell 7 users, see FAQ Q3 — you need to change one word here) |

When it's done, go to your desktop and there's a new `文件清单.csv` — double-click to open it in Excel. **Your list is done, and you hand-copied not a single character.**

**Screenshot tip**: ① the new `文件清单.csv` icon on the desktop; ② the three-column table content after opening it in Excel.

**Key point**: `Export-Csv` is at the 🟡 level (it writes a file). It **won't touch your source files**, but if a `文件清单.csv` already exists on the desktop, **it gets overwritten with no warning**. To be safe, give the file a dated name like `文件清单_0815.csv`.

### 4.7 Step 7: What If There's an Error — Throw the Red Text Back at AI, Verbatim

Red text isn't a disaster, it's a clue. **Don't close the window** — do this:

1. Use the mouse to **select all** the red error text, and press `Ctrl + C` to copy (in the PowerShell window, selecting is enough to copy, or right-click → Copy);
2. Go back to the AI chat and use the prompt below (a copy-ready version is in Section 5):

```text
I ran this command in Windows PowerShell 5.1:
<paste the exact command you actually ran here>

The error is as follows:
<paste the full red error text here, don't change a single character>

Please answer me four things:
1) In plain language, what does this error mean?
2) Exactly which part of the command is wrong?
3) Give me the corrected full command, written on a single line;
4) After the change, is this command still read-only? Will it touch my files?
```

**Key point**: don't change, abbreviate, or paraphrase a single character of the error text. AI locates the problem using that original English (or Chinese) text — once you rephrase it, it can only guess. When you get the corrected new command, **run it through the three-check method from Step 5 again before running it.**

**Done!** You just ran your first PowerShell command ever — completely on your own — and delivered a file list along the way.

---

## 5. The Prompts (One-Click Copy Version)

All three prompts are collected here for easy copying.

**① Ask AI for the command (corresponds to 4.4)**

```text
I'm a complete PowerShell beginner, using the Windows PowerShell 5.1 that comes built into Windows 11,
and I don't want to run as administrator.

My need: in the folder "D:\工作\2026年报销单", list every file,
with three columns — "file name, size, last-modified time" — sorted from largest to smallest by file size.

Please answer me strictly in this format:
1) The complete command, written on a single line, that I can copy and run directly;
2) Break the command down word by word, explaining what each word and each parameter does;
3) Answer clearly: will this command modify, move, or delete my original files?
4) Answer clearly: does it need to run as administrator?
5) If there's a safer or simpler way to write this command, tell me that too.

Requirements: only use commands that run on built-in Windows PowerShell 5.1, not ones needing extra installed modules,
and not Linux/macOS syntax. Explain in plain everyday language — I don't understand the jargon.
```

> Usage: replace the bracketed path and need with your own (e.g., "list the files in E:\Photos sorted newest-to-oldest by modified time"), and send the rest as-is.

**② Ask AI to security-check the command (corresponds to 4.5, strongly recommended every time)**

```text
Do only one thing: review the PowerShell command below, don't change my requirements for me.
Command: <paste the command here>

Answer point by point:
1) What will it read, what will it write, what will it delete?
2) Are there any misspelled parameters, or parameters that simply don't exist in Windows PowerShell 5.1?
   Confirm each parameter one by one.
3) Will it overwrite an existing file?
4) Does it need administrator rights?
5) Is there a safer way to write it (for example, pre-testing with -WhatIf)?
```

**③ Ask AI to fix the error (corresponds to 4.7)**

```text
I ran this command in Windows PowerShell 5.1:
<paste the exact command you actually ran here>

The error is as follows:
<paste the full red error text here, don't change a single character>

Please answer me four things:
1) In plain language, what does this error mean?
2) Exactly which part of the command is wrong?
3) Give me the corrected full command, written on a single line;
4) After the change, is this command still read-only? Will it touch my files?
```

---

## 6. Why It Works: Why This Approach Is Safest for Beginners

What beginners fear about the command line isn't the typing — it's "**I don't know what will happen when I press Enter.**" PowerShell happens to be designed to make that friendly: every command is "**Verb-Noun**," and the verb exposes the intent directly — `Get-` means look, `Remove-` means delete. So the scary question "is it safe?" gets downgraded to a table you can look up in 10 seconds.

AI fills in the other half: it translates your plain-language need into a **syntactically correct command**, and can talk you through it word by word. But AI hallucinates and makes up parameters, so it can only be "the one who draws the blueprint" — **verifying the blueprint and doing the construction must be you**. That's what the three-check method (check the verb / check the parameters / check the path) exists for.

In one sentence: **AI makes sure you understand the command, the verb table makes sure you judge the risk, and the Enter key stays in your hand.** With those three in place, the black window goes from "I dare not touch it" to "that's all there is to it."

---

## 7. Pitfalls: 5 Real Mistakes to Avoid

1. **Going straight for "Run as administrator" on your first try.** Many tutorials start with "right-click → Run as administrator," and beginners follow along — which is like ripping out the airbag before you even start driving. Operations the system would block under a normal account actually execute under an administrator account. → **Fix**: check the title bar; if it says "Administrator: Windows PowerShell," close it and open a normal window. This article and every "read-only viewing" operation **need no administrator rights**. When you genuinely need elevation (changing system settings, installing a service), the command itself will tell you "access denied" — deal with it then.

2. **AI made up a parameter that doesn't exist, and you thought your computer was broken.** The classic case is writing `-Recurse` (include subfolders) as `-Recursive`. After pressing Enter, PowerShell will tell you in red, "**A parameter cannot be found that matches parameter name 'Recursive'**." It might also hand you Linux syntax (like `ls -l`) — which errors out in PowerShell too. → **Fix**: this kind of error **isn't your fault — AI made it up**. Don't panic, don't reinstall Windows. Use `Get-Help Get-ChildItem -Online` to open the official docs and check the parameter name, or just use the security-check prompt in Section 5② and have AI confirm each one itself.

3. **The path wasn't in double quotes, or the path doesn't even exist.** A path with spaces (`D:\工作 备份\报销单`) but no quotes makes PowerShell treat it as two parameters and error out; another case is the desktop taken over by OneDrive, where `C:\Users\you\Desktop` no longer exists and you get "**Cannot find path ... because it does not exist**." → **Fix**: always grab the path with "Shift + right-click → Copy as path" (quotes included); when exporting to the desktop, ask the system for the real desktop path with `$Desktop = [Environment]::GetFolderPath("Desktop")` instead of hard-coding it.

4. **Mixing up PowerShell and CMD.** They both look like black windows, but they're **two different things**: CMD is the older command prompt and doesn't recognize `Get-ChildItem`. Run this article's commands in CMD and you'll get "**'Get-ChildItem' is not recognized as an internal or external command**." → **Fix**: glance at the prompt first — **only PowerShell starts with `PS`** (`PS C:\Users\you>`); if there's no `PS` and it's just `C:\Users\you>`, that's CMD — close it and reopen per 4.1. (By the way: typing `dir` or `ls` in PowerShell also lists files, because they're **aliases** for `Get-ChildItem` — nicknames for the same command. But for formal commands, use the full name `Get-ChildItem`; AI and the docs both know it.)

5. **Three kinds of junk that come along when you copy-paste: line breaks, full-width quotes, and extra spaces.** Copying a command AI gave you from a web page often drags the line breaks along too; PowerShell runs each line as you paste it, so the command gets split in half and you get "**unexpected token ... in expression or statement**." There's also the sneakier culprit: the quotes turn into **Chinese full-width quotes** (`" "`); they're nearly invisible to the eye, but PowerShell doesn't recognize them at all. → **Fix**: ① explicitly ask for "written on a single line" in the prompt; ② after pasting, **first check that the window shows only one line** before pressing Enter; ③ quotes must be the English half-width `"` — if you're unsure, delete both quotes and retype them in English input mode; ④ if the command is too long to display on one line, you may break it, but **only after a pipe `|`** (PowerShell accepts this kind of line continuation) — break it anywhere else and it errors.

---

## 8. FAQ / Troubleshooting

**Q1: The command runs forever with no response, or seems frozen — how do I stop it?**
Press `Ctrl + C` to force-terminate the current command and return to the prompt. If you accidentally told it to scan the whole `C:\` drive (too many files), it'll churn for a long time; just `Ctrl + C` to stop it — nothing gets damaged.

**Q2: The screen is too cluttered and I want to clear it?**
Type `cls` or `Clear-Host` and press Enter. It only clears the display — deletes nothing.

**Q3: I open the exported CSV in Excel and the Chinese is garbled?**
That's an encoding issue; handle it by version:

- **Windows PowerShell 5.1** (this article's default): use `-Encoding UTF8`, which exports UTF-8 with a BOM marker that Excel recognizes, so Chinese displays fine;
- **PowerShell 7**: its `-Encoding utf8` **has no BOM**, so Excel may not read the Chinese. Change the parameter to `-Encoding utf8BOM`.

Not sure which version you are? Go back to 4.1 and run `$PSVersionTable` to check `PSVersion`.

**Q4: I get "cannot be loaded because running scripts is disabled on this system" — what do I do?**
This error only appears when you **run a `.ps1` script file** — it's Windows's default "execution policy" protection. This article has you **type single commands by hand**, which is completely unaffected, so you'll never hit it in normal operation.
⚠️ Important reminder: if AI or a web post tells you to run something like `Set-ExecutionPolicy Bypass` to "fix" it right away, **don't do it yet** — that loosens your system's security settings. When you should change it, and to what scope most safely, will be covered in the next article, B18, on scripts.

**Q5: Do I need to install PowerShell 7?**
Not at all for this article — the built-in 5.1 is enough. Consider the newer version later, once you write more complex scripts.

**Q6: Can Copilot run the command for me directly?**
No. The web/app versions of Copilot and ChatGPT **only output text** — you must press that final Enter yourself. That's not a flaw — it forces you to look at the command once, which is one extra layer of insurance.

**Q7: The `Length` number is huge — what unit is that?**
Bytes. Conversion: `1024` bytes = 1 KB, `1048576` bytes = 1 MB. To display MB directly, see Section 9.

**Q8: I want to count files in subfolders too — how do I change it?**
Add `-Recurse` after `Get-ChildItem` (note: it's `-Recurse`, **not** `-Recursive`):

```powershell
Get-ChildItem -Path "D:\工作\2026年报销单" -File -Recurse | Select-Object Name, Length, LastWriteTime
```

It'll run a bit slower on deeply nested folders — be patient, or stop it with `Ctrl + C`.

---

## 9. Recap & Next Steps

**One-line recap**: use a prompt to have AI produce the command and explain it word by word, run it through your own "check the verb / check the parameters / check the path" three-check method, then press Enter — and your first PowerShell command runs, with a file list exported along the way.

**Three more little exercises (all still read-only, run them worry-free):**

1. **Show size directly in MB** (this uses a "calculated column" — don't worry if you don't get it, just copy it to feel it out):

```powershell
Get-ChildItem -Path "D:\工作\2026年报销单" -File | Select-Object Name, @{Name="大小MB"; Expression={[math]::Round($_.Length/1MB, 2)}}, LastWriteTime
```

2. **See which 5 processes eat the most CPU** (`Get-Process` = get the process list, read-only):

```powershell
Get-Process | Sort-Object CPU -Descending | Select-Object -First 5 -Property Name, CPU
```

3. **Remember one "safety catch"**: later, when you learn commands that actually act — `Remove-Item` (delete), `Rename-Item` (rename) — many commands support a `-WhatIf` parameter. Add it, and PowerShell **only tells you "here's what I would do" but doesn't actually do it** — a free rehearsal.
   (Note: `-WhatIf` is only recognized by commands that support it — it's not a universal key; `Get-` read-only commands don't need it. **You don't run this in this article — just remember the word.**)

**Where to go next:**

- Next article **B18 (L2)**: let AI write a script to batch-process Excel / Word — turn today's one command into a `.ps1` script you can save and reuse (and we'll fully cover "execution policy");
- **B19 (L3)**: AI generates modular scripts with error handling, so your script fails gracefully instead of crashing hard;
- To keep speeding up on the spreadsheet side, revisit **B1 (L1) AI Helps You Finish a Reimbursement Sheet in 10 Minutes**;
- Struggling with prompts? Take **A3 Prompt Engineering for Office (Beginner)** to catch up — the three prompts in this article were built using that method.

---

## 10. CTA (Optional)

- Button text: **"Get the PowerShell Beginner Safety Command Sheet (with the three-check method checklist)"**
- Link placeholder: `https://vba.net/ai-office/b17` (to be replaced with the real URL by the editor at launch)
- Bonus: watch for the next article in the series, **B18 · Let AI Write Scripts to Batch-Process Excel/Word**, and upgrade one command into a script you can run again and again.

---

_This article is part of the "AI-Powered Office: From Beginner to Expert" series, B17 (T5 Automation Script / L1). Author: Cheng Xiao. Translator: Yi An. Status: Draft._
