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

[玩转系统] 如何使用 PowerShell 在 SharePoint 中隐藏列表视图?

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

如何使用 PowerShell 在 SharePoint 中隐藏列表视图?


要求:在 SharePoint 中隐藏列表视图。

[玩转系统] 如何使用 PowerShell 在 SharePoint 中隐藏列表视图?

有时您可能需要隐藏 SharePoint 中的列表视图以限制用户对特定数据的访问。在本文中,我们将讨论如何在 SharePoint 中隐藏列表视图。

如何隐藏 SharePoint 列表视图?

要隐藏 SharePoint 中的列表视图,请使用以下 PowerShell 脚本:


Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Config variables
$SiteURL="https://intranet.crescent.com"
$ListName="Projects"
$ViewName="All Projects"

#Get the View
$Web = Get-SPWeb $SiteURL
$List = $Web.Lists[$ListName]
$View = $List.Views[$ViewName]

#Hide the list view
$View.Hidden=$true
$View.Update()

Write-host "List View Hidden from users!"

这将从视图下拉列表和列表设置中向用户隐藏列表视图。不过,如果你知道网址,就可以直接点击获取查看页面!

SharePoint Online:使用 PowerShell 隐藏列表视图

同样,在 SharePoint Online 隐藏列表视图中,以下是 PowerShell 脚本。


#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
   
#Config Parameters
$SiteURL= "https://crescent.sharepoint.com/"
$ListName="Projects"
$ViewName ="All Projects" 

#Get Credentials to connect
$Cred = Get-Credential
 
Try {
    #Setup the context
    $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
    $Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.UserName,$Cred.Password)
   
    #Get the List
    $List=$Ctx.Web.Lists.GetByTitle($ListName)
    
    #Get the List View
    $ListView = $List.views.GetByTitle($ViewName)
    $Ctx.load($ListView)
    $Ctx.executeQuery()

    #Hide SharePoint Online List view
    $ListView.Hidden = $True
    $ListView.Update()
    $Ctx.ExecuteQuery()

    Write-host -f Green "List View Hidden from users!"
}
Catch {
    write-host -f Red "Error Hiding List View!" $_.Exception.Message
}

用于隐藏 SharePoint Online 中的视图的 PnP PowerShell

使用 Set-PnPView cmdlet 设置视图属性!


#Parameters
$SiteURL = "https://crescent.sharepoint.com/sites/Retail"
$ListName = "Projects"
$ViewName = "All Projects"

#Connect to SharePoint Online site
Connect-PnPOnline -Url $SiteURL -Interactive

#Hide the List View
Set-PnPView -List $ListName -Identity $ViewName -Values @{Hidden =$True}

这会对所有用户隐藏 SharePoint Online 中的列表视图。如果您想将视图限制为特定用户或组,请使用另一篇文章:如何设置 SharePoint 列表视图的权限?

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

取消回复欢迎 发表评论:

关灯