Lazy loaded image
智汇技术
Lazy loaded imagePowerShell 7 实战
字数 963阅读时长 3 分钟
2024-12-8
2026-3-22
type
Post
status
Published
date
Dec 8, 2024
slug
powershell7-experience
summary
PowerShell7 安装、美化、使用记录
tags
工具
电脑
category
智汇技术
icon
password

PowerShell 7 安装

查看版本

打开 powershell,然后执行 $psversiontable 或者 host 命令,可以看到 powershell 的版本信息
notion image
系统是新装的 win11 24H2,默认带的 Windows PowerShell 版本是 5.1,需要升级到 PowerShell 7.X。
Microsoft 官网给的 Windows PowerShell 5.1 与 PowerShell 7.X 之间的差异:

安装 PowerShell 7.4

使用 winget 命令安装 PowerShell 7.4

搜索最新版本 PowerShell

notion image

安装

notion image
🥲 winget 本质上也是下载 msi 包,然后安装
安装以后,可以在搜索 PowerShell 7,打开
notion image
😢 后续美化一下

更新

PowerShell 7 设置成默认 Shell

notion image
 
notion image

查看 PowerShell 7 配置文件

C:\Users\10161\Documents\PowerShell\Microsoft.PowerShell_profile.ps1

PowerShell 7 美化

安装 oh-my-posh

Microsoft Store 直接搜索安装
notion image

安装字体(防止只使用主题后乱码)

使用 Meslo LGM NF 字体
notion image
下载以后,解压,然后安装字体
notion image

使用 oh-my-posh

将下面这行代码添加到 PowerShell7 的配置文件中
重启之后可以看到 PowerShell 主题已经变了
notion image

配置 oh-my-posh themes 环境变量

查看 oh-my-posh themes 路径
notion image
配置环境变量
notion image
配置完成以后可以通过如下命令查看 oh-my-posh 支持的 themes

更换主题

我选中了 jandedobbeleer 这个主题,修改 PowerShell 配置文件
可以看到,是增加了 —config 这个配置
重启以后配置
notion image
好看了很多,但是太黑了,并且没有透明度;透明度调整成 60%
notion image
顺眼多了,后续继续再做其他调整

安装 GIT

安装(需要先安装 git)

修改配置文件

在 PowerShell 配置文件中添加如下代码
 
保存之后执行 . $PROFILE 使配置生效

问题修复

上述配置生效之后,使用 git 命令,显示如下
notion image
问题定位:posh-git 需要结合 git 使用,因此必须先安装 git

配置 git alias

方法一

修改 PowerShell 配置文件,在文件中添加如下内容
📢
由于上述有些简写已经被 Powershell 默认的昵称给占用了,因此需要在上述的配置文件中(最前面)添加如下内容:

方法二(推荐)

安装 git-aliases
在 PowerShell 配置文件中添加
 
 

常用命令记录

获取程序位置

linux 有个 where 命令,可以查询程序的位置,PowerShell 也有类似的命令 Get-Command
notion image
 

certutil 命令

Certutil的主要功能包括转储和显示证书颁发机构(CA)的信息、配置证书服务、备份和还原CA组件,以及验证证书、密钥对和证书链。作为一款系统工具,Certutil以其强大的功能成为了许多技术人员和黑客的首选。

计算文件Hash

哈希算法: MD2 MD4 MD5 SHA1 SHA256 SHA384 SHA512
eg:
notion image
 
 
 
 
 

当前 PowerShell7 配置文件内容:

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
上一篇
Maven 导报异常处理
下一篇
win11 操作记录

评论
Loading...