惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Microsoft Azure Blog
Microsoft Azure Blog
The Register - Security
The Register - Security
S
Securelist
Simon Willison's Weblog
Simon Willison's Weblog
T
The Exploit Database - CXSecurity.com
V
Vulnerabilities – Threatpost
NISL@THU
NISL@THU
P
Privacy & Cybersecurity Law Blog
V2EX - 技术
V2EX - 技术
O
OpenAI News
N
News and Events Feed by Topic
AI
AI
P
Proofpoint News Feed
Schneier on Security
Schneier on Security
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Cloudbric
Cloudbric
Help Net Security
Help Net Security
C
Cyber Attacks, Cyber Crime and Cyber Security
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Security Latest
Security Latest
Application and Cybersecurity Blog
Application and Cybersecurity Blog
L
LINUX DO - 热门话题
Cyberwarzone
Cyberwarzone
Scott Helme
Scott Helme
The Hacker News
The Hacker News
Hacker News - Newest:
Hacker News - Newest: "LLM"
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Google DeepMind News
Google DeepMind News
H
Hacker News: Front Page
C
Cisco Blogs
Webroot Blog
Webroot Blog
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Hacker News: Ask HN
Hacker News: Ask HN
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
The Last Watchdog
The Last Watchdog
PCI Perspectives
PCI Perspectives
AWS News Blog
AWS News Blog
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Know Your Adversary
Know Your Adversary
Latest news
Latest news
Forbes - Security
Forbes - Security
I
Intezer
Project Zero
Project Zero
C
CERT Recently Published Vulnerability Notes
T
Tenable Blog
TaoSecurity Blog
TaoSecurity Blog
S
Security @ Cisco Blogs
N
News | PayPal Newsroom
H
Heimdal Security Blog
W
WeLiveSecurity

博客园 - 520_1351

Powerautomate-控制Edge-浏览器-报错-Failed to assume control of Microsoft Edge (communication with Power Automate web extension failed) 关于-密码学算法中-类似-编程函数pow(3, 13, 7)的计算-快速幂算法结合模运算(Exponentiation by Squaring with Modular Reduction) 关于AWS-EC2-串口登录的-IAM权限-Policy-策略 关于 AWS Lambda 中的默认的时区-日期-时间-注意点 关于使用 javascript 脚本语言中的 location.reload() 刷新当前页面 关于Bash - Shell脚本中的索引数组(Indexed Array) 关于Linux系统中-使用passwd对用户密码的锁定与解锁 关于 Redhat - 9 - 补丁升级后-旧版本内核相关的软件包卸载 关于 Redhat - 9 下 postfix 的安装配置 与 mail 命令发送邮件 关于 Amazon Linux 2023 (AL2023) 默认情况下确实没有 /var/log/secure 文件的解决方法 关于-HTML-内容-元素定位- CSS Selector 与 XPath 的说明及区别 关于Microsoft Power Automate-操作-Microsoft Access 数据库-【运行Access查询】 关于 Javascript 中 console.log("xxxx")-及console-对象其他常用的方法 关于Provider=Microsoft.ACE.OLEDB.12.0 与 Provider=Microsoft.ACE.OLEDB.16.0 的区别 通过Powershell-脚本-将指定的日期-转换成年周-格式-周数宽度为2 关于Windows-操作系统中-对带日期-或-数字-的文件目录-按名称排序的规则 关于Microsoft Power Automate-元素的定位-自定义写法去定位时-:nth-child 与 :eq 的区别 关于标准CSS伪类-以及在-Power Automate-等自动化工具中的使用 关于使用-Python-Selenium-模块-加载浏览器的扩展-的方法及注意事项-及只能加载一个扩展的解决方法 关于-根据-ISO8601-国际标准-计算一年中的周数-每年最少52周-每多53周 Redhat-9-中编译-EFS-客户端工具-即过程中-报错提示-warning: aws-lc-fips-sys@0.13.9: Building with: CMake-解决方法 关于Microsoft Power Automate-调用-Outlook-发送邮件-报错- A program is trying to access emal address information stored in Outlook 关于HTML中<font><b><i><s>等字体标签对-物理字体-逻辑字体的介绍及说明
关于powershell中的-哈希表-Hashtable-类型-说明-类似于python中的字典
520_1351 · 2025-11-25 · via 博客园 - 520_1351

字典类型是当前各类语言中使用的最为广泛的组合数据类型,在PowerShell中被命名为哈希表类型-Hashtable

在Powershell中,哈希表也称为字典或关联阵列,是用于存储一个或多个键值对的紧凑数据结构。 

定义方式如下:

$dict = @{
    'key1' = 'value1'
    'key2' = 'value2'
    'key3' = 'value3'
    'Author'='QQ-5201351'
}

这里几个说明如下:

1、每个键值对,上面是通过换行符分隔的,如果需要写成一行,需要使用分号;进行分隔

2、默认情况下,上面的,哈希表-Hashtable,是无序的,也即 通过 foreach 去遍历 就可以发现,不是按我们定义的顺序输出的

3、可以在上面的 @ 符号前面加上 [ordered] 变成有序的 哈希表-Hashtable, 即 $dict = [ordered]@{...} 可以变成有序的,即遍历时,可以按我们定义的顺序取出来

4、多行分隔的模式,可以在某一键值对,前面加上 # 号注释,这样,哈希表中就没有那一个键值对了

5、可以通过 $Dict.Add('key4', 15000) 的方式为字典添加一个键值对,会添加到末尾

6、不能出现两个一样的key,否则会报错:+ FullyQualifiedErrorId : DuplicateKeyInHashLiteral (如果是python,可以重复,一般都是取最后定义的那个key的值)

如果我们需要遍历,完整的代码如下:

$dict = [ordered]@{
    'key1' = 'value1'
    'key2' = 'value2'
    'key3' = 'value3'
    'Author'='QQ-5201351'
}


foreach ($key in $dict.Keys) {
    Write-Output "$key -> $($dict[$key])"
}

程序运行结果如下:

key1 -> value1
key2 -> value2
key3 -> value3
Author -> QQ-5201351

尊重别人的劳动成果 转载请务必注明出处:https://www.cnblogs.com/5201351/p/19269960