{"id":22184226,"url":"https://github.com/mq-b/powershelllearning","last_synced_at":"2025-08-23T14:06:20.472Z","repository":{"id":264335707,"uuid":"893077380","full_name":"Mq-b/PowerShellLearning","owner":"Mq-b","description":"PowerShell 脚本编写教程与示例","archived":false,"fork":false,"pushed_at":"2024-12-01T11:26:28.000Z","size":58,"stargazers_count":32,"open_issues_count":0,"forks_count":3,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-12-01T12:32:07.455Z","etag":null,"topics":["powershell","powershell-script"],"latest_commit_sha":null,"homepage":"","language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Mq-b.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-11-23T13:26:47.000Z","updated_at":"2024-12-01T11:26:32.000Z","dependencies_parsed_at":"2024-11-23T14:41:34.980Z","dependency_job_id":null,"html_url":"https://github.com/Mq-b/PowerShellLearning","commit_stats":null,"previous_names":["mq-b/powershelllearning"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mq-b%2FPowerShellLearning","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mq-b%2FPowerShellLearning/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mq-b%2FPowerShellLearning/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mq-b%2FPowerShellLearning/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Mq-b","download_url":"https://codeload.github.com/Mq-b/PowerShellLearning/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":227707766,"owners_count":17807513,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["powershell","powershell-script"],"created_at":"2024-12-02T10:12:08.508Z","updated_at":"2025-07-26T19:31:12.525Z","avatar_url":"https://github.com/Mq-b.png","language":"HTML","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PowerShellLearning\n\n\u003cdiv style=\"text-align: center;\"\u003e\n    \u003cimg src=\"./image/PowerShell_5.0_icon.png\" alt=\"PowerShell\" width=\"150\"/\u003e\n\u003c/div\u003e\n\n\u0026emsp;\u0026emsp;欢迎来到 **PowerShellLearning** 仓库！\n\n\u0026emsp;\u0026emsp;这个仓库记录了我在学习和教学 PowerShell 脚本过程中的笔记、示例代码和实用脚本。\n\n## 什么是 `PowerShell`?\n\nPowerShell 是一个由微软开发的任务自动化和配置管理工具。**它既是一个命令行 Shell，也是一种脚本语言**。\n\n- **命令行 Shell**：类似于 Windows 的 cmd（命令提示符），但功能更强大更现代。\n\n- **脚本语言**：可以编写脚本来自动执行复杂任务，支持面向对象编程。\n\n更多详细内容可参见微软 [PowerShell 文档](https://learn.microsoft.com/zh-cn/powershell/scripting/overview?view=powershell-7.4)。\n\n另外 PowerShell 还定义了许多命令别名，使得我们命令行中的许多操作类似于 Unix/Linux shell。这让用户更容易上手，特别是那些习惯于 Unix/Linux 的用户。你可以通过命令 **`Get-Alias`** 查看对应关系。\n\n### 常见别名示例\n\n| 别名  | 对应 PowerShell 命令   | 说明                          |\n|-------|-----------------------|-----------------------------|\n| [`ls`](https://learn.microsoft.com/zh-cn/powershell/module/microsoft.powershell.management/get-childitem)  | `Get-ChildItem`       | 列出目录中的文件和文件夹     |\n| [`dir`](https://learn.microsoft.com/zh-cn/powershell/module/microsoft.powershell.management/get-childitem) | `Get-ChildItem`       | 列出目录中的文件和文件夹     |\n| [`cp`](https://learn.microsoft.com/zh-cn/powershell/module/microsoft.powershell.management/copy-item)  | `Copy-Item`           | 复制文件或文件夹             |\n| [`mv`](https://learn.microsoft.com/zh-cn/powershell/module/microsoft.powershell.management/move-item)  | `Move-Item`           | 移动文件或文件夹             |\n| [`rm`](https://learn.microsoft.com/zh-cn/powershell/module/microsoft.powershell.management/remove-item)  | `Remove-Item`         | 删除文件或文件夹             |\n| [`cat`](https://learn.microsoft.com/zh-cn/powershell/module/microsoft.powershell.management/get-content) | `Get-Content`         | 显示文件内容                 |\n| [`type`](https://learn.microsoft.com/zh-cn/powershell/module/microsoft.powershell.management/get-content) | `Get-Content`         | 显示文件内容                 |\n| [`gc`](https://learn.microsoft.com/zh-cn/powershell/module/microsoft.powershell.management/get-content)  | `Get-Content`         | 显示文件内容                 |\n| [`echo`](https://learn.microsoft.com/zh-cn/powershell/module/microsoft.powershell.utility/write-output)  | `Write-Output`        | 输出文本                     |\n| [`cls`](https://learn.microsoft.com/zh-cn/powershell/module/microsoft.powershell.utility/clear-host)  | `Clear-Host`          | 清除控制台屏幕               |\n| [`pwd`](https://learn.microsoft.com/zh-cn/powershell/module/microsoft.powershell.management/get-location)  | `Get-Location`        | 显示当前目录                 |\n| [`cd`](https://learn.microsoft.com/zh-cn/powershell/module/microsoft.powershell.management/set-location)  | `Set-Location`        | 更改当前目录                 |\n| [`sl`](https://learn.microsoft.com/zh-cn/powershell/module/microsoft.powershell.management/set-location)  | `Set-Location`        | 更改当前目录                 |\n| [`mkdir`](https://learn.microsoft.com/zh-cn/powershell/module/microsoft.powershell.management/new-item)  | `New-Item`           | 创建新目录                   |\n| [`rmdir`](https://learn.microsoft.com/zh-cn/powershell/module/microsoft.powershell.management/remove-item) | `Remove-Item`        | 删除目录                     |\n| [`del`](https://learn.microsoft.com/zh-cn/powershell/module/microsoft.powershell.management/remove-item)  | `Remove-Item`         | 删除文件或文件夹             |\n\n### 使用 `Get-Help` 获取 PowerShell 文档\n\n在编写脚本时，我们经常需要查阅有关 PowerShell 命令和概念的详细信息。PowerShell 提供了强大的 [`Get-Help`](https://learn.microsoft.com/zh-cn/powershell/module/microsoft.powershell.core/get-help?view=powershell-5.1\u0026WT.mc_id=ps-gethelp) 命令，用于查询本地或在线文档。\n\n#### 基本用法\n\n`Get-Help` 的基本语法如下：\n\n```powershell\nGet-Help [[-Name] \u003cString\u003e]\n```\n\n例如，如果想了解 `Test-Path` 命令的作用和用法，可以使用以下命令：\n\n```PowerShell\nGet-Help Test-Path\n```\n\n#### 获取在线文档\n\n通过添加 **`-Online`** 参数，`Get-Help` 可以直接打开命令的微软在线文档：\n\n```PowerShell\nGet-Help Test-Path -Online\n```\n\n## 环境\n\n您无需拥有与我相同的环境，只需支持 PowerShell 即可（当然最好是开启了全局 `utf-8`）。以下是我的环境配置：\n\n- **操作系统**\n\n```PowerShell\n(Get-WmiObject -Class Win32_OperatingSystem).Caption \n# 结果: Microsoft Windows 11 家庭中文版\n```\n\n- **区域设置**\n\n```PowerShell\nGet-WinSystemLocale\n# 结果:\n# LCID             Name             DisplayName\n# ----             ----             -----------\n# 2052             zh-CN             Chinese (Simplified, PRC)\n```\n\n- **字符集设置**\n\n```Powershell\n[System.Text.Encoding]::Default\n# 结果:\n# BodyName          : utf-8\n# EncodingName      : Unicode (UTF-8)\n# HeaderName        : utf-8\n# WebName           : utf-8\n# WindowsCodePage   : 1200\n# IsBrowserDisplay  : True\n# IsBrowserSave     : True\n# IsMailNewsDisplay : True\n# IsMailNewsSave    : True\n# IsSingleByte      : False\n# EncoderFallback   : System.Text.EncoderReplacementFallback\n# DecoderFallback   : System.Text.DecoderReplacementFallback\n# IsReadOnly        : True\n# CodePage          : 65001\n```\n\n- **`PowerShell` 版本**\n\n```PowerShell\n$PSVersionTable.PSVersion\n# 结果:\n# Major  Minor  Build  Revision\n# -----  -----  -----  --------\n# 5      1      22621  4249\n```\n\n### `Linux` 中使用 `PowerShell`\n\n我在 Ubuntu22.04 中安装了 `PowerShell.7.4.6`。参见：\n\n- [在 Ubuntu 上安装 PowerShell](https://learn.microsoft.com/zh-cn/powershell/scripting/install/install-ubuntu?view=powershell-7.4)\n\n## 获取\n\n```shell\ngit clone https://github.com/Mq-b/PowerShellLearning.git\n```\n\n## 仓库目录结构\n\n- `src` 文件夹中存放着我们的 `.ps1` 脚本文件。\n\n- `OutPut` 文件夹中通常是脚本进行文件写入操作存放输出文件的路径。\n\n- `File` 文件夹通常是存放脚本进行读取的文件。\n\n- `md` 文件夹存放着有关 PowerShell 内容的一些有意义的文档。\n\n\u003c!-- 还需思考 --\u003e\n\n## 贡献\n\n欢迎你为这个仓库贡献内容！你可以提交Pull Request，分享你的学习笔记、脚本示例或改进建议。\n具体步骤：\n\n1. Fork 这个仓库。\n2. 在你的分支上进行修改。\n3. 提交 Pull Request，我们会尽快 review。\n\n## 许可证\n\n本仓库采用 [署名-非商业性使用 4.0 国际 (CC BY-NC 4.0)](https://creativecommons.org/licenses/by-nc/4.0/deed.zh-hans) 许可协议进行许可。\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmq-b%2Fpowershelllearning","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmq-b%2Fpowershelllearning","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmq-b%2Fpowershelllearning/lists"}