You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

非PnP PowerShell获取网站列ShowInEditForm属性时遇Get-SPOField错误求助

不用PnP PowerShell修改网站列ShowInEditForm属性的解决办法

原生SharePoint Online Management Shell没有Get-SPOField这个cmdlet,你可以通过PowerShell调用CSOM(客户端对象模型)来实现需求,具体步骤如下:

1. 加载CSOM程序集

先加载必需的SharePoint CSOM程序集,如果你已经安装了SharePoint Online Management Shell,程序集默认在以下路径:

Add-Type -Path "C:\Program Files\SharePoint Online Management Shell\Microsoft.Online.SharePoint.PowerShell\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\SharePoint Online Management Shell\Microsoft.Online.SharePoint.PowerShell\Microsoft.SharePoint.Client.Runtime.dll"

2. 连接站点并获取目标字段

替换代码中的站点URL、账号信息,或者复用已有的SPO连接凭据:

# 你的站点地址
$siteUrl = "https://***.sharepoint.com/"
# 账号密码(如果已用Connect-SPOService连接,可跳过此部分,直接用下面的复用凭据代码)
$username = "your-admin@tenant.onmicrosoft.com"
$password = ConvertTo-SecureString "your-password" -AsPlainText -Force
$credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $password)

# 创建客户端上下文
$ctx = New-Object Microsoft.SharePoint.Client.ClientContext($siteUrl)
# 复用已有的SPO连接凭据(如果已经运行过Connect-SPOService,用这行代替上面的credentials赋值)
# $ctx.Credentials = Get-SPOCredential

# 获取网站级字段(如果是列表字段,看下方补充)
$field = $ctx.Site.RootWeb.Fields.GetByInternalNameOrTitle("CarNumber")
$ctx.Load($field)
$ctx.ExecuteQuery()

3. 修改并保存字段属性

# 设置ShowInEditForm为False
$field.SetShowInEditForm($false)
$field.Update()
$ctx.ExecuteQuery()

Write-Host "字段CarNumber的ShowInEditForm属性已成功设置为False"

补充:处理列表级字段

如果目标字段是某个列表的专属字段而非网站列,需要先获取对应列表再取字段:

# 替换为你的列表名称
$list = $ctx.Web.Lists.GetByTitle("目标列表名称")
$field = $list.Fields.GetByInternalNameOrTitle("CarNumber")
$ctx.Load($field)
$ctx.ExecuteQuery()

内容的提问来源于stack exchange,提问作者John John

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.02 16:32:33