提升PowerShell易用性,升级到最新版。

推荐使用Winget进行安装。

Windows 包管理器 Winget 是一种命令行工具,用户可以使用它在 Windows 客户端计算机上查找、安装、升级、删除和配置应用程序。 此工具是 Windows 程序包管理器服务的客户端接口。 默认情况下,winget 命令行工具作为应用安装程序与 Windows 11 和现代版本的 Windows 10 捆绑在一起。

通过以下命令,可使用已发布的 winget 包安装 PowerShell:

搜索最新版本的 PowerShell

winget search Microsoft.PowerShell
Output
Name               Id                           Version   Source
-----------------------------------------------------------------
PowerShell         Microsoft.PowerShell         7.4.5.0   winget
PowerShell Preview Microsoft.PowerShell.Preview 7.5.0.3   winget

使用 id 参数安装 PowerShell 或 PowerShell 预览版

winget install --id Microsoft.Powershell --source winget
winget install --id Microsoft.Powershell.Preview --source winget

更改终端默认配置文件为新安装的PowerShell。

2024-10-23T05:36:46.png

重新打开终端,查看当前 PowerShell 版本:

$PSVersionTable.PSVersion

更新帮助文档,方便查看命令参数:

Update-Help -UICulture en-US
Update-Help -ErrorAction SilentlyContinue

使用 PowerShell 修改 Windows Defender 设置。

Add-MpPreference
   [-AsJob]
   [-AttackSurfaceReductionOnlyExclusions <String[]>]
   [-AttackSurfaceReductionRules_Actions <ASRRuleActionType[]>]
   [-AttackSurfaceReductionRules_Ids <String[]>]
   [-CimSession <CimSession[]>]
   [-ControlledFolderAccessAllowedApplications <String[]>]
   [-ControlledFolderAccessProtectedFolders <String[]>]
   [-ExclusionExtension <String[]>]
   [-ExclusionIpAddress <String[]>]
   [-ExclusionPath <String[]>]
   [-ExclusionProcess <String[]>]
   [-Force]
   [-ThreatIDDefaultAction_Actions <ThreatAction[]>]
   [-ThreatIDDefaultAction_Ids <Int64[]>]
   [-ThrottleLimit <Int32>]
   [<CommonParameters>]

添加忽略排查目录、类型、进程:

Add-MpPreference -ExclusionPath 'C:\Temp'
Add-MpPreference -ExclusionExtension '.vhd'
Add-MpPreference -ExclusionProcess 'c:\apps\test.exe'
Add-MpPreference -ExclusionProcess 'test.exe'

移除忽略排查目录、类型、进程:

Remove-MpPreference -ExclusionPath "C:\Temp"
Remove-MpPreference -ExclusionExtension '.vhd'
Remove-MpPreference -ExclusionProcess 'c:\apps\test.exe'
Remove-MpPreference -ExclusionProcess 'test.exe'

查看 Windows Defender 配置详情:

$Preferences = Get-MpPreference
$Preferences.ExclusionPath

参考文档:

【1】在 Windows 上安装 PowerShell
【2】PowerShell 参考文档

最后修改:2024 年 10 月 23 日
如果觉得我的文章对你有用,请随意赞赏