当前位置:网站首页 > 更多 > 玩电脑 > 正文

[玩转系统] 如何安装 SharePoint Online 的 PnP PowerShell 模块?

作者:精品下载站 日期:2024-12-14 21:33:08 浏览:16 分类:玩电脑

如何安装 SharePoint Online 的 PnP PowerShell 模块?


什么是 PnP PowerShell?新的 PnP PowerShell 模块 PnP.PowerShell 是一款跨平台、基于 .net 框架的 PowerShell 产品,可以运行在任何支持 .net core 的操作系统上,如 Windows、Linux、macOS 等,并提供 500 多个 cmdlet使用 Microsoft 365 环境(不支持本地服务器产品,请注意!)云产品,例如 SharePoint Online、Microsoft Teams、Microsoft Planner、安全与合规性、Azure Active Directory 等。如果您正在管理 Microsoft SharePoint,您就会知道 PnP PowerShell 是管理环境的重要工具。它是一个开源组件和社区提供的库,有活跃的社区成员提供支持,因此不会有任何来自 Microsoft 的 SLA 或直接支持。本文将向您展示如何安装 SharePoint Online 的 PnP PowerShell 模块。

要安装新的 PnP PowerShell 模块,您必须执行以下步骤:

  1. 卸载旧版 SharePointPnPPowerShellOnline 模块(如果已安装)。
  2. 安装新的 PnP PowerShell 模块。
  3. 注册 Azure AD 应用程序并向租户授予访问权限。

让我们开始吧!以管理员身份打开 Windows PowerShell 控制台并执行以下步骤来安装 PnP.PowerShell 模块。

[玩转系统] 如何安装 SharePoint Online 的 PnP PowerShell 模块?

步骤 1:卸载旧版 SharePointPnPPowerShellOnline 模块

使用以下命令检查是否安装了经典 PnP PowerShell 模块:


Get-Module SharePointPnPPowerShellOnline -ListAvailable | Select-Object Name,Version

这将返回计算机上安装的旧版 PnP PowerShell 的名称和版本(如果有)。卸载以前安装的任何适用于 SharePoint Online 的 PnP PowerShell 模块:


Uninstall-Module SharePointPnPPowerShellOnline -Force -AllVersions

步骤 2:安装新的 PnP PowerShell 模块

如何安装新的 PowerShell 模块?要安装新的 PnP PowerShell 模块,请使用:


Install-Module PnP.PowerShell

如何离线安装 PnP PowerShell?如果需要,您还可以使用安装文件下载 PnP PowerShell 离线安装包并使用以下命令进行安装:


Install-Package C:\Path\File.nupkg

步骤 3:注册新的 Azure AD 应用程序并向租户授予访问权限


Register-PnPManagementShellAccess

最后一步是授予租户对 PnP Management Shell 多租户 Azure AD 应用程序的访问权限。执行上述 cmdlet 时,系统将提示您登录并同意您的租户。您必须使用全局管理员(或租户管理员)权限登录并完成此步骤。

[玩转系统] 如何安装 SharePoint Online 的 PnP PowerShell 模块?

如果您不是全局管理员,请使用:Register-PnPManagementShellAccess -ShowConsentUrl 并与租户管理员共享从此 cmdlet 获取的 URL,他们可以通过您共享的 URL 完成此同意步骤。

[玩转系统] 如何安装 SharePoint Online 的 PnP PowerShell 模块?

最后,您可以通过获取 PnP PowerShell cmdlet 列表来验证安装:


Get-Command -Module PnP.Powershell

使用 PnP PowerShell 连接 SharePoint Online 网站

如何在 SharePoint Online 中使用 PnP PowerShell?完成上述步骤后,您可以通过 PnP PowerShell 脚本连接到 SharePoint Online,用户名和密码如下:


#Connect to PnP Online
Connect-PnPOnline -Url "https://Crescent.sharepoint.com/sites/Marketing/" -Credential (Get-Credential)

#Get All Lists
Get-PnPList

使用 MFA 连接 PnPOnline:

要使用 PnP PowerShell MFA(多重身份验证)连接到 SharePoint Online: 如果您的帐户启用了 MFA,请使用“-Interactive”开关而不是“凭据”。在幕后,每个 cmdlet 都会执行客户端对象模型代码来实现功能。


#Connect to SharePoint site
Connect-PnPOnline -Url "https://Crescent.sharepoint.com/sites/Marketing/" -Interactive

#Get All Lists
Get-PnPList
如果您想安排 PowerShell 脚本,您可以使用 Windows 任务计划程序或 Azure 自动化!如何使用 Azure 自动化安排 PowerShell 脚本?

用于连接到 OneDrive for Business 的 PowerShell

Microsoft OneDrive for Business - Office 365 套件中基于云的存储和文件共享部分也可以使用 PowerShell 进行管理。要从 PowerShell 访问 OneDrive for Business 站点,您需要首先通过运行以下 cmdlet 连接到 OneDrive 站点:Connect-PnPOnline。通过身份验证后,您就可以对 OneDrive for Business 网站运行任何可用的 cmdlet,就像对任何其他 SharePoint Online 网站一样。例如,让我们连接到 OneDrive 站点并创建一个新文件夹:


#Parameters
$OneDriveSiteURL = "https://crescent-my.sharepoint.com/personal/salaudeen_crescent_com"
$FolderName = "Archives"
  
Try {
    #PowerShell to Connect to OneDrive for Business
    Connect-PnPOnline -Url $OneDriveSiteURL -Interactive
      
    #ensure folder in SharePoint Online using powershell
    Resolve-PnPFolder -SiteRelativePath "Documents/$FolderName"
}
catch {
    write-host "Error: $($_.Exception.Message)" -foregroundcolor Red
}

更新 SharePoint Online 的 PnP PowerShell

如何更新 PnP PowerShell?要更新 PnP PowerShell,请运行:


Update-Module -Name "PnP.PowerShell"

这将下载最新的 PnP PowerShell 模块并将其安装在本地计算机上。

[玩转系统] 如何安装 SharePoint Online 的 PnP PowerShell 模块?

我拥有什么版本的 PnP PowerShell?

要检查系统中已安装的 PnP PowerShell 版本,请使用:


Get-InstalledModule -Name "PnP.PowerShell"

卸载 PnP PowerShell 模块

如果您想删除 PnP PowerShell,可以运行以下命令:


Uninstall-Module -Name "PnP.PowerShell"

我可以同时拥有新 PnP PowerShell 和经典 PnP 模块吗?

如果要使用 SharePoint Server(本地)的 PnP PowerShell 模块,可以将其与 Pnp.PowerShell 模块一起安装,如下所示:


Install-Module -Name SharePointPnPPowerShell2019 -AllowClobber

此脚本安装 SharePointPnPPowerShell2019 模块并使 cmdlet 可从此模块使用。您可以在第一行使用“Import-Module SharePointPnPPowerShell2019”来指示脚本从该特定模块加载和使用 Cmdlet。附带说明一下,旧的 SharePointPnPPowerShellOnline 模块已存档并且不再更新。

有时,您可能需要将 CSOM PowerShell 脚本与 PnP PowerShell cmdlet 组合使用,因为我们没有适用于 SharePoint Online 中的所有内容的 PnP PowerShell cmdlet:如何使用 CSOM PowerShell 连接到 SharePoint Online?

经常问的问题:

如何通过 PnP PowerShell 获取网站中的所有列、类型和内部名称?

使用:获取 PnPField |选择标题、类型显示名称、内部名称
详细信息:使用 PowerShell 在 SharePoint Online 中获取网站列

如何通过 PnP Online 获取所有 SP 库 ID?

要获取所有 SharePoint Online 文档库的 ID,请使用:Get-PnPList | Where-Object {$_.BaseType -eq “DocumentLibrary”}
详细信息:获取 SharePoint Online 中的所有文档库

如何在 PowerShell 中创建顶部链接导航?

使用 Add-PnPNavigationNode cmdlet 创建指向 SharePoint Online 网站的顶部导航链接。
详细信息:使用 PowerShell 在 SharePoint Online 中添加顶部导航链接

如何使用SharePoint Online Management Shell?

SharePoint Online Management Shell 是一个 PowerShell 模块,可帮助管理员管理 SharePoint Online 网站。只需安装 PowerShell 模块“Microsoft.Online.SharePoint.PowerShell”,使用 Connect-SPOService 连接到 SharePoint Online,然后就可以开始使用任何可用的 cmdlet。
更多信息:从 PowerShell 连接到 SharePoint Online

如何安装 SharePointPnPPowerShellOnline 模块?

如果您想要安装旧版 SharePointPnPPowerShellOnline 模块以实现向后兼容性或管理 SharePoint 本地版本,请使用:“安装模块 SharePointPnPPowerShellOnline”
详细信息:如何使用 PnP PowerShell 连接到 SharePoint Online?

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯