notes/article/powershell.md

74 lines
1.7 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# PowerShell Development
## 两个版本
PowerShell 有两个版本,一是自 Windows 7 之后内置在系统中的,二是开源、跨平台的 PowerShell早期版本叫 PowerShell Core。
```powershell
# [14:14:11] ~ ➔ $PSVersionTable
Name Value
---- -----
PSVersion 5.1.19041.5129
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.19041.5129
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
```
```powershell
# [17:19:20] ~ ➔ $PSVersionTable
Name Value
---- -----
PSVersion 7.4.6
PSEdition Core
GitCommitId 7.4.6
OS Microsoft Windows 10.0.19045
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
```
## 数据结构
### 字符串
强调函数参数为字符串时,可用 `[String]`,调用字符串类的静态方法,可用 `[String]::Format`
### 数组
这里用的是 ArrayList用双引号调用静态方法。
```powershell
$list = [System.Collections.ArrayList]::new()
```
使用 `Add` 方法添加元素,返回元素在 `ArrayList` 中的下标。
### 哈希表
```powershell
$hashtable = @{
Color = "Red"
}
```
使用 `Add` 方法增加 kv 值:
```powershell
$hashtable.Add($key, $value)
```
## 常用方法
## 数据库
推荐使用基于 dotnet 开发的 `LiteDB` 数据库。