[玩转系统] 如何安装 Microsoft PowerShell PSResourceGet 模块
作者:精品下载站 日期:2024-12-14 06:31:47 浏览:14 分类:玩电脑
如何安装 Microsoft PowerShell PSResourceGet 模块
PSResourceGet 是一个模块,其中包含用于发现、安装、更新和发布 PowerShell 工件(例如模块、DSC 资源、角色功能和脚本)的命令。 PSResourceGet 是最新的包管理器,取代了 PowerShellGet v2 模块。在本文中,您将学习如何安装 Microsoft PowerShell PSResourceGet 模块。
Microsoft PowerShell PSResourceGet
PSResourceGet 模块提供了在 PowerShell Gallery 等存储库中安装、更新和定位模块和脚本的功能。
PSResourceGet 是 PowerShell 的新包管理器。它取代了 PowerShellGet v2 模块。现在你可能会问为什么还没有变成v3?那是在项目的初始阶段。最终决定在多次重大变更中更改名称。您将在 PowerShell 库中找到 v3 作为兼容性模块。
Windows PowerShell 5.1 预装了 PowerShellGet 1.0.0.1 版本。此版本的 PowerShellGet 功能有限,并且不支持 PowerShell 库的更新功能。要安装 PSResourceGet,您必须首先更新到 PowerShellGet 的最新版本。
安装 Microsoft PowerShell PSResourceGet 模块
要在系统上安装 Microsoft PowerShell PSResourceGet 模块,请按照以下步骤操作。
1. 设置 Windows PowerShell 执行策略
默认情况下,我们无法安装脚本。要要求从 Internet 下载的所有 PowerShell 脚本均由受信任的发布者签名,请以管理员身份运行 PowerShell,然后运行 cmdlet。
Set-ExecutionPolicy RemoteSigned -Force
重要提示:关闭并重新打开提升的 Windows PowerShell 窗口以使更改生效。
2.安装PowerShellGet模块
以管理员身份运行 PowerShell。运行命令Install-Module PowershellGet -Force。当要求安装 NuGet 提供程序时,按 Y 并按 Enter 键。
Install-Module PowershellGet -Force
如果您收到无法安装的错误,请阅读文章无法安装 PowerShell 的 NuGet 提供程序。
3. 安装 Microsoft PowerShell PSResourceGet 模块
安装 Microsoft PowerShell PSResourceGet 模块。
Install-Module -Name Microsoft.PowerShell.PSResourceGet -Force
4.信任PowerShell Gallery存储库
安装 Microsoft PowerShell PSResourceGet 后,您应该打开一个新的 PowerShell 会话。当您使用 PowerShell cmdlet 时,PowerShell 会自动加载最新版本的模块。
我们还建议您将 PowerShell 库注册为受信任的存储库。当您每次想要下载模块时,这不会提示您信任存储库。
Set-PSResourceRepository -Name PSGallery -Trusted
获取 PSResourceGet 模块版本
验证是否安装了 PSResourceGet 模块。
Get-PSResource Microsoft.PowerShell.PSResourceGet -Scope AllUsers | ft -AutoSize
将出现以下 PowerShell 输出。
Version Name Repository Description
------- ---- ---------- -----------
1.0.2 Microsoft.PowerShell.PSResourceGet PSGallery PowerShell module with commands for discovering, installing, updating and publishing the PowerShell artifacts like Modules, Scripts, and DSC Resources.
查找 PSResourceGet 模块最新可用版本
Find-Module Microsoft.PowerShell.PSResourceGet | ft -AutoSize
将出现以下输出。
Version Name Repository Description
------- ---- ---------- -----------
1.0.2 Microsoft.PowerShell.PSResourceGet PSGallery PowerShell module with commands for discovering, installing, updating and publishing the PowerShell artifacts like Modules, Scripts, and DSC Resources.
Microsoft PowerShell PSResourceGet cmdlet
请参阅以下所有 cmdlet 的列表。
Find-PSResource根据名称或其他包属性从存储库(本地或远程)搜索包。
Get-InstalledPSResource通过 PowerShellGet 返回计算机上安装的模块和脚本。
Get-PSResourceRepository查找并返回已注册的存储库信息。
Get-PSScriptFileInfo返回脚本的元数据。
Import-PSGetRepository查找使用 PowerShellGet 注册的存储库并将其注册到 PSResourceGet。
Install-PSResource从注册的存储库安装资源。
New-PSScriptFileInfo该 cmdlet 创建一个新的脚本文件,包括有关该脚本的元数据。
Publish-PSResource将指定模块从本地计算机发布到 PSResource 存储库。
Register-PSResourceRepository注册 PowerShell 资源的存储库。
Save-PSResource将注册存储库中的资源(模块和脚本)保存到计算机上。
Set-PSResourceRepository设置已注册存储库的信息。
Test-PSScriptFileInfo测试 .ps1 文件中基于评论的元数据,以确保其对于发布有效。
Uninstall-PSResource卸载使用 PowerShellGet 安装的资源。
Unregister-PSResourceRepository从本地计算机中删除已注册的存储库。
Update-PSModuleManifest更新模块清单文件。
Update-PSResource下载并安装本地计算机上已安装的软件包的最新版本。
Update-PSScriptFileInfo此 cmdlet 更新现有脚本 .ps1 文件中基于注释的元数据。
如何使用 Microsoft PowerShell PSResourceGet
让我们看看如何使用 PSResourceGet 安装模块。
安装-PSResource
在我们的示例中,我们希望安装这两个模块:
Microsoft Graph PowerShell 模块
Microsoft Graph Beta PowerShell 模块
我们不必在下面的命令中添加 -TrustReposority 参数,因为我们已经在之前的安装步骤中将 PSGallery 添加到了受信任的存储库中。但你可能忽略了它,所以让我们添加它。
注意: 使用命令中的-Reinstall 参数来安装最新版本的模块,即使已经安装了最新版本。安装的版本被覆盖。这允许您修复损坏的模块安装。如果安装了旧版本的模块,则新版本会并排安装在新版本特定的文件夹中。
Install-PSResource Microsoft.Graph -Reinstall -Scope AllUsers -TrustRepository
Install-PSResource Microsoft.Graph.Beta -Reinstall -Scope AllUsers -TrustRepository
如果您想安装特定的模块版本,请使用-Version参数。
Install-PSResource Microsoft.Graph -Version 2.14.0 -Scope AllUsers -TrustRepository
Install-PSResource Microsoft.Graph.Beta -Version 2.14.0 -Scope AllUsers -TrustRepository
获取安装的 PS 资源
检查机器上安装了哪些模块。
Get-InstalledPSResource -Scope AllUsers
过滤已安装的模块。
Get-InstalledPSResource Microsoft.Graph* -Scope AllUsers | Where-Object { $_.Name -notlike "Microsoft.Graph.Beta*" }
Get-InstalledPSResource Microsoft.Graph* -Scope AllUsers | Where-Object { $_.Name -like "Microsoft.Graph.Beta*" }
让我们获取模块安装的位置路径。
注意:当您运行Install-PSResource cmdlet 来安装模块时,可以将其安装在从 Windows PowerShell 5.1 或 PowerShell 7 运行时的不同位置。
Get-InstalledPSResource -Scope AllUsers | ft Name, InstalledLocation
下面的文件夹路径是安装模块的默认位置。您可以在文件资源管理器中打开以下文件夹。
当前用户的 Windows PowerShell 5.1:
%USERPROFILE%\Documents\WindowsPowerShell\Modules
适用于所有用户的 Windows PowerShell 5.1:
C:\Program Files\WindowsPowerShell\Modules
当前用户的 PowerShell 7:
%USERPROFILE%\Documents\PowerShell\Modules
适用于所有用户的 PowerShell 7:
C:\Program Files\PowerShell\Modules
卸载-PSResource
如果我们想使用 PSResourceGet 卸载模块,则需要使用 Uninstall-PSResource cmdlet。
这将删除所有 Microsoft Graph 模块。
Get-InstalledPSResource Microsoft.Graph* -Scope AllUsers | Uninstall-PSResource -Scope AllUsers -SkipDependencyCheck
您始终可以过滤并删除不需要的模块。
Get-InstalledPSResource Microsoft.Graph* -Scope AllUsers | Where-Object { $_.Name -notlike "Microsoft.Graph.Beta*" } | Uninstall-PSResource -Scope AllUsers -SkipDependencyCheck
Get-InstalledPSResource Microsoft.Graph* -Scope AllUsers | Where-Object { $_.Name -like "Microsoft.Graph.Beta*" } | Uninstall-PSResource -Scope AllUsers -SkipDependencyCheck
PSResourceGet 与 PowerShellGet v2
让我们比较一下 PSResourceGet 和 PowerShellGet v2,看看哪一个在安装和删除模块方面更快。
在此示例中,我们将使用 Measure-Command cmdlet 安装和卸载 Microsoft Graph PowerShell 模块。这是一个非常好的测试,因为它有 39 个模块。
与 PowerShellGet v2 相比,PSResourceGet 速度要快得多。
就是这样!
了解更多:如何安装和更新 PowerShell 7 »
结论
您学习了如何安装 Microsoft PowerShell PSResourceGet 模块。运行 Windows PowerShell 5.1 或 PowerShell 7 并逐步运行命令以安装最新的 PSResourceGet 模块。从现在开始,使用 PSResourceGet 来安装、更新和删除模块。
您喜欢这篇文章吗?您可能还喜欢连接到 Exchange Online PowerShell。不要忘记关注我们并分享这篇文章。
猜你还喜欢
- 03-30 [玩转系统] 如何用批处理实现关机,注销,重启和锁定计算机
- 02-14 [系统故障] Win10下报错:该文件没有与之关联的应用来执行该操作
- 01-07 [系统问题] Win10--解决锁屏后会断网的问题
- 01-02 [系统技巧] Windows系统如何关闭防火墙保姆式教程,超详细
- 12-15 [玩转系统] 如何在 Windows 10 和 11 上允许多个 RDP 会话
- 12-15 [玩转系统] 查找 Exchange/Microsoft 365 中不活动(未使用)的通讯组列表
- 12-15 [玩转系统] 如何在 Windows 上安装远程服务器管理工具 (RSAT)
- 12-15 [玩转系统] 如何在 Windows 上重置组策略设置
- 12-15 [玩转系统] 如何获取计算机上的本地管理员列表?
- 12-15 [玩转系统] 在 Visual Studio Code 中连接到 MS SQL Server 数据库
- 12-15 [玩转系统] 如何降级 Windows Server 版本或许可证
- 12-15 [玩转系统] 如何允许非管理员用户在 Windows 中启动/停止服务
取消回复欢迎 你 发表评论:
- 精品推荐!
-
- 最新文章
- 热门文章
- 热评文章
[影视] 黑道中人 Alto Knights(2025)剧情 犯罪 历史 电影
[古装剧] [七侠五义][全75集][WEB-MP4/76G][国语无字][1080P][焦恩俊经典]
[实用软件] 虚拟手机号 电话 验证码 注册
[电视剧] 安眠书店/你 第五季 You Season 5 (2025) 【全10集】
[电视剧] 棋士(2025) 4K 1080P【全22集】悬疑 犯罪 王宝强 陈明昊
[软件合集] 25年6月5日 精选软件22个
[软件合集] 25年6月4日 精选软件36个
[短剧] 2025年06月04日 精选+付费短剧推荐33部
[短剧] 2025年06月03日 精选+付费短剧推荐25部
[软件合集] 25年6月3日 精选软件44个
[剧集] [央视][笑傲江湖][2001][DVD-RMVB][高清][40集全]李亚鹏、许晴、苗乙乙
[电视剧] 欢乐颂.5部全 (2016-2024)
[电视剧] [突围] [45集全] [WEB-MP4/每集1.5GB] [国语/内嵌中文字幕] [4K-2160P] [无水印]
[影视] 【稀有资源】香港老片 艺坛照妖镜之96应召名册 (1996)
[剧集] 神经风云(2023)(完结).4K
[剧集] [BT] [TVB] [黑夜彩虹(2003)] [全21集] [粤语中字] [TV-RMVB]
[实用软件] 虚拟手机号 电话 验证码 注册
[资源] B站充电视频合集,包含多位重量级up主,全是大佬真金白银买来的~【99GB】
[影视] 内地绝版高清录像带 [mpg]
[书籍] 古今奇书禁书三教九流资料大合集 猎奇必备珍藏资源PDF版 1.14G
[电视剧] [突围] [45集全] [WEB-MP4/每集1.5GB] [国语/内嵌中文字幕] [4K-2160P] [无水印]
[剧集] [央视][笑傲江湖][2001][DVD-RMVB][高清][40集全]李亚鹏、许晴、苗乙乙
[电影] 美国队长4 4K原盘REMUX 杜比视界 内封简繁英双语字幕 49G
[电影] 死神来了(1-6)大合集!
[软件合集] 25年05月13日 精选软件16个
[精品软件] 25年05月15日 精选软件18个
[绝版资源] 南与北 第1-2季 合集 North and South (1985) /美国/豆瓣: 8.8[1080P][中文字幕]
[软件] 25年05月14日 精选软件57个
[短剧] 2025年05月14日 精选+付费短剧推荐39部
[短剧] 2025年05月15日 精选+付费短剧推荐36部
- 最新评论
-
- 热门tag