SharePoint Online: Hozzon létre egy webhelyoszlopot a PowerShell segítségével
Követelmény: Hozzon létre webhelyoszlopokat a SharePoint Online-ban.
Webhelyoszlopok a SharePoint Online-ban
A webhelyoszlopok nagyszerű újrafelhasználhatóságot biztosítanak a SharePointban anélkül, hogy minden alkalommal újra kellene létrehozni a mezőket a listákban és a könyvtárakban. Rengeteg időt takarítanak meg, különösen akkor, ha szabványosítani kell az oszlopokat, adatokat tartalmazó oszlopokat kell létrehozni (például választási mezőket), vagy alapértelmezett értékeket kell hozzájuk rendelni. A legfelső szintű webhelyen létrehozott webhelyoszlop bármely listában vagy tárban, vagy akár tartalomtípusban is használható a SharePoint-webhely-hierarchiában (vagy a tartalomtípus-központtal rendelkező webhelygyűjtemények között).
Hogyan hozhatunk létre webhelyoszlopot a SharePoint Online-ban?
A webhelyoszlopok a SharePoint Online hatékony eszközei, amelyek lehetővé teszik metaadatok meghatározását és újrafelhasználását listákon, könyvtárakon és tartalomtípusokon keresztül. Ez a blogbejegyzés bemutatja, hogyan hozhat létre webhelyoszlopot a SharePoint Online-ban. Nagyszerű módja annak, hogy szabványosítsa a listákban és könyvtárakban tárolt adatokat, és megkönnyítse az információk megtalálását és felhasználását. Kezdjük el!
Ha webhelyoszlopot szeretne létrehozni a SharePoint Online-ban, kövesse az alábbi lépéseket:
- Jelentkezzen be a SharePoint Online webhelyre. Kattintson a Webhelybeállítások fogaskerékre, és válassza a Webhelybeállítások lehetőséget.
- A Webhelybeállítások oldalon kattintson a „Webtervezői galériák” csoportban található „Webhelyoszlopok” hivatkozásra. Ez az oldal felsorolja az összes elérhető webhelyoszlopot.
A Webhelyoszlopok oldalon kattintson a felül található „Létrehozás” linkre.
Az oszlop létrehozása oldalon adja meg a webhely oszlopának nevét. Válassza ki az oszlop típusát, és adjon meg további oszlopbeállításokat az új webhelyoszlophoz. Válassza ki a meglévő csoportot vagy az új csoportot a webhelyoszlophoz. Kattintson az „OK” gombra alul a webhelyoszlop létrehozásának befejezéséhez a SharePoint Online-ban.
Most a webhely oszlop hozzáadódik a webhelyhez. A webhelyoszlop létrehozása után a webhely bármely listájához vagy könyvtárához hozzáadható.
Webhelyoszlopok létrehozása a PowerShell használatával a SharePoint Online-ban:
Nézzük meg, hogyan hozhat létre webhelyoszlopot a SharePoint Online-ban a PowerShell használatával. Íme a PowerShell-szkriptek gyűjteménye, amellyel webhelyoszlopokat hozhat létre a SharePoint Online-ban az ügyféloldali objektummodell (CSOM) használatával.
Egysoros szöveges webhelyoszlop létrehozása a SharePoint Online-ban a PowerShell segítségével
Itt található a SharePoint Online PowerShell webhelyoszlop hozzáadásához:
#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
#Parameters
$SiteURL="https://crescent.sharepoint.com"
$ColumnName="ProjectCode"
$IsRequired = "TRUE"
$ColumnGroup="Crescent Projects"
Try {
$Cred= Get-Credential
$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
#Setup the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Ctx.Credentials = $Credentials
#Get all Site columns from the site
$Fields = $Ctx.web.Fields
$Ctx.Load($Fields)
$Ctx.executeQuery()
#Check if the column name exists
$NewField = $Fields | where {$_.Title -eq $ColumnName}
if($NewField -ne $NULL)
{
Write-host "Site Column $ColumnName already exists!" -f Yellow
}
else
{
#Define XML for Field Schema
$FieldSchema = "<Field Type='Text' DisplayName='$ColumnName' Name='$ColumnName' required='$IsRequired' Group='$ColumnGroup'/>"
$NewField = $Fields.AddFieldAsXml($FieldSchema,$True,[Microsoft.SharePoint.Client.AddFieldOptions]::AddFieldToDefaultView)
$Ctx.ExecuteQuery()
Write-host "Site Column Created Successfully!" -ForegroundColor Green
}
}
Catch {
write-host -f Red "Error Creating Site Column!" $_.Exception.Message
}
Több soros szövegmező hozzáadása a PowerShell segítségével
Ezúttal csomagoljuk be a kódot egy újrafelhasználható függvénybe:
#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
#Custom function to add Multiline Text Field
Function Add-MultilineSiteColumn()
{
param
(
[Parameter(Mandatory=$true)] [string] $SiteURL,
[Parameter(Mandatory=$true)] [string] $ColumnName,
[Parameter(Mandatory=$true)] [string] $NumberofLines,
[Parameter(Mandatory=$true)] [string] $IsRequired,
[Parameter(Mandatory=$true)] [string] $RichText,
[Parameter(Mandatory=$true)] [string] $ColumnGroup
)
#Generate new GUID for Field ID
$FieldID = ([GUID]::NewGuid()).GUID
Try {
$Cred= Get-Credential
$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
#Setup the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Ctx.Credentials = $Credentials
#Get all Site columns from the site
$Fields = $Ctx.web.Fields
$Ctx.Load($Fields)
$Ctx.executeQuery()
#Check if the column name exists
$NewField = $Fields | where {$_.Title -eq $ColumnName}
if($NewField -ne $NULL)
{
Write-host "Site Column $ColumnName already exists!" -f Yellow
}
else
{
#Define XML for Field Schema
$FieldSchema = "<Field Type='Note' ID='{$FieldID}' DisplayName='$ColumnName' Name='$ColumnName' RichText='$RichText' Required='$IsRequired' Group='$ColumnGroup'/>"
$NewField = $Fields.AddFieldAsXml($FieldSchema,$True,[Microsoft.SharePoint.Client.AddFieldOptions]::AddFieldToDefaultView)
$Ctx.ExecuteQuery()
Write-host "Site Column Created Successfully!" -ForegroundColor Green
}
}
Catch {
write-host -f Red "Error Creating Site Column!" $_.Exception.Message
}
}
#Define value for parameters
$SiteURL="https://crescent.sharepoint.com"
$ColumnName="ProjectDescription"
$IsRequired = "TRUE"
$ColumnGroup="Crescent Projects"
$RichText ="FALSE"
$NumberofLines="5"
#Call the function to create Multiline site column
Add-MultilineSiteColumn -SiteURL $SiteURL -ColumnName $ColumnName -IsRequired $IsRequired -NumberofLines $NumberofLines -RichText $RichText -ColumnGroup $ColumnGroup
PowerShell személy vagy csoport (People Picker) webhelyoszlop létrehozásához a SharePoint Online-hoz:
#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
#Custom function to add site column
Function Add-PersonOrGroupSiteColumn()
{
param
(
[Parameter(Mandatory=$true)] [string] $SiteURL,
[Parameter(Mandatory=$true)] [string] $ColumnName,
[Parameter(Mandatory=$true)] [string] $ColumnDisplayName,
[Parameter(Mandatory=$true)] [string] $IsRequired,
[Parameter(Mandatory=$true)] [string] $ColumnGroup
)
#Generate new GUID for Field ID
$FieldID = ([GUID]::NewGuid()).GUID
Try {
$Cred= Get-Credential
$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
#Setup the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Ctx.Credentials = $Credentials
#Get all Site columns from the site
$Fields = $Ctx.web.Fields
$Ctx.Load($Fields)
$Ctx.executeQuery()
#Check if the column name exists already
$NewField = $Fields | where { ($_.Internalname -eq $ColumnName) -or ($_.Title -eq $ColumnDisplayName) }
if($NewField -ne $NULL)
{
Write-host "Site Column $ColumnName already exists!" -f Yellow
}
else
{
#Define XML for Field Schema
$FieldSchema = "<Field Type='User' ID='{$FieldID}' DisplayName='$ColumnDisplayName' Name='$ColumnName' Required='$IsRequired' Group='$ColumnGroup' ShowField='ImnName' List='UserInfo' UserSelectionMode='PeopleOnly' />"
$FieldSchema
$NewField = $Fields.AddFieldAsXml($FieldSchema,$True,[Microsoft.SharePoint.Client.AddFieldOptions]::AddFieldToDefaultView)
$Ctx.ExecuteQuery()
Write-host "Site Column Created Successfully!" -ForegroundColor Green
}
}
Catch {
write-host -f Red "Error Creating Site Column!" $_.Exception.Message
}
}
#Set parameter values
$SiteURL="https://crescent.sharepoint.com"
$ColumnName="ProjectMembers"
$ColumnDisplayName="Project Members"
$IsRequired = "TRUE"
$ColumnGroup="Crescent Projects"
#Call the function to create site column
Add-PersonOrGroupSiteColumn -SiteURL $SiteURL -ColumnName $ColumnName -ColumnDisplayName $ColumnDisplayName -IsRequired $IsRequired -ColumnGroup $ColumnGroup
Dátum és idő webhelyoszlop hozzáadása a SharePoint Online-hoz:
#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
#Custom function to add site column
Function Add-DateTimeSiteColumn()
{
param
(
[Parameter(Mandatory=$true)] [string] $SiteURL,
[Parameter(Mandatory=$true)] [string] $ColumnName,
[Parameter(Mandatory=$true)] [string] $ColumnDisplayName,
[Parameter(Mandatory=$true)] [string] $Format,
[Parameter(Mandatory=$true)] [string] $IsRequired,
[Parameter(Mandatory=$true)] [string] $ColumnGroup
)
#Generate new GUID for Field ID
$FieldID = ([GUID]::NewGuid()).GUID
Try {
$Cred= Get-Credential
$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
#Setup the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Ctx.Credentials = $Credentials
#Get all Site columns from the site
$Fields = $Ctx.web.Fields
$Ctx.Load($Fields)
$Ctx.executeQuery()
#Check if the column name exists already
$NewField = $Fields | where { ($_.Internalname -eq $ColumnName) -or ($_.Title -eq $ColumnDisplayName) }
if($NewField -ne $NULL)
{
Write-host "Site Column $ColumnName already exists!" -f Yellow
}
else
{
#Define XML for Field Schema
$FieldSchema = "<Field Type='DateTime' ID='{$FieldID}' DisplayName='$ColumnDisplayName' Name='$ColumnName' Format='$Format' Required='$IsRequired' Group='$ColumnGroup'/>"
$NewField = $Fields.AddFieldAsXml($FieldSchema,$True,[Microsoft.SharePoint.Client.AddFieldOptions]::AddFieldToDefaultView)
$Ctx.ExecuteQuery()
Write-host "Site Column Created Successfully!" -ForegroundColor Green
}
}
Catch {
write-host -f Red "Error Creating Site Column!" $_.Exception.Message
}
}
#Set parameter values
$SiteURL="https://crescent.sharepoint.com"
$ColumnName="ProjectStartDate"
$ColumnDisplayName="Project Start Date"
$Format="DateOnly"
$IsRequired = "FALSE"
$ColumnGroup="Crescent Projects"
#Call the function to create site column
Add-DateTimeSiteColumn -SiteURL $SiteURL -ColumnName $ColumnName -ColumnDisplayName $ColumnDisplayName -IsRequired $IsRequired -Format $Format -ColumnGroup $ColumnGroup
PowerShell CSOM-szkript pénznem-webhelyoszlop hozzáadásához a SharePoint Online-hoz
#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
#Custom function to add site column
Function Add-CurrencySiteColumn()
{
param
(
[Parameter(Mandatory=$true)] [string] $SiteURL,
[Parameter(Mandatory=$true)] [string] $ColumnName,
[Parameter(Mandatory=$true)] [string] $ColumnDisplayName,
[Parameter(Mandatory=$true)] [string] $LCID,
[Parameter(Mandatory=$true)] [string] $IsRequired,
[Parameter(Mandatory=$true)] [string] $ColumnGroup
)
#Generate new GUID for Field ID
$FieldID = ([GUID]::NewGuid()).GUID
Try {
$Cred= Get-Credential
$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
#Setup the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Ctx.Credentials = $Credentials
#Get all Site columns from the site
$Fields = $Ctx.web.Fields
$Ctx.Load($Fields)
$Ctx.executeQuery()
#Check if the column name exists already
$NewField = $Fields | where { ($_.Internalname -eq $ColumnName) -or ($_.Title -eq $ColumnDisplayName) }
if($NewField -ne $NULL)
{
Write-host "Site Column $ColumnName already exists!" -f Yellow
}
else
{
#Define XML for Field Schema
$FieldSchema = "<Field Type='Currency' ID='{$FieldID}' DisplayName='$ColumnDisplayName' Name='$ColumnName' LCID='$LCID' Required='$IsRequired' Group='$ColumnGroup'/>"
$NewField = $Fields.AddFieldAsXml($FieldSchema,$True,[Microsoft.SharePoint.Client.AddFieldOptions]::AddFieldToDefaultView)
$Ctx.ExecuteQuery()
Write-host "Site Column Created Successfully!" -ForegroundColor Green
}
}
Catch {
write-host -f Red "Error Creating Site Column!" $_.Exception.Message
}
}
#Set parameter values
$SiteURL="https://crescent.sharepoint.com"
$ColumnName="TotalInvestment"
$ColumnDisplayName="Total Investment Amount"
$LCID="1081" #India
$IsRequired = "TRUE"
$ColumnGroup="Crescent Projects"
#Call the function to create site column
Add-CurrencySiteColumn -SiteURL $SiteURL -ColumnName $ColumnName -ColumnDisplayName $ColumnDisplayName -IsRequired $IsRequired -LCID $LCID -ColumnGroup $ColumnGroup
Az összes LCID-hez tekintse meg a https://msdn.microsoft.com/en-us/library/microsoft.sharepoint.splocale.lcid.aspx webhelyet.
SharePoint Online: Helyszámoszlop hozzáadása a PowerShell segítségével
#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
#Custom function to add site column
Function Add-NumberSiteColumn()
{
param
(
[Parameter(Mandatory=$true)] [string] $SiteURL,
[Parameter(Mandatory=$true)] [string] $ColumnName,
[Parameter(Mandatory=$true)] [string] $ColumnDisplayName,
[Parameter(Mandatory=$true)] [string] $IsRequired,
[Parameter(Mandatory=$true)] [string] $ColumnGroup
)
#Generate new GUID for Field ID
$FieldID = ([GUID]::NewGuid()).GUID
Try {
$Cred= Get-Credential
$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
#Setup the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Ctx.Credentials = $Credentials
#Get all Site columns from the site
$Fields = $Ctx.web.Fields
$Ctx.Load($Fields)
$Ctx.executeQuery()
#Check if the column name exists
$NewField = $Fields | where { ($_.Internalname -eq $ColumnName) -or ($_.Title -eq $ColumnDisplayName) }
if($NewField -ne $NULL)
{
Write-host "Site Column $ColumnName already exists!" -f Yellow
}
else
{
#Define XML for Field Schema
$FieldSchema = "<Field Type='Number' ID='{$FieldID}' DisplayName='$ColumnDisplayName' Name='$ColumnName' Required='$IsRequired' Group='$ColumnGroup'/>"
$NewField = $Fields.AddFieldAsXml($FieldSchema,$True,[Microsoft.SharePoint.Client.AddFieldOptions]::AddFieldToDefaultView)
$Ctx.ExecuteQuery()
Write-host "Site Column Created Successfully!" -ForegroundColor Green
}
}
Catch {
write-host -f Red "Error Creating Site Column!" $_.Exception.Message
}
}
#Set parameter values
$SiteURL="https://crescent.sharepoint.com"
$ColumnName="HeadCount"
$ColumnDisplayName="Head Count"
$IsRequired = "TRUE"
$ColumnGroup="Crescent Projects"
#Call the function to create site column
Add-NumberSiteColumn -SiteURL $SiteURL -ColumnName $ColumnName -ColumnDisplayName $ColumnDisplayName -IsRequired $IsRequired -ColumnGroup $ColumnGroup
Hogyan adhatunk Choice Site oszlopot a SharePoint Online-hoz a PowerShell segítségével?
#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
#Custom function to add site column
Function Add-ChoiceSiteColumn()
{
param
(
[Parameter(Mandatory=$true)] [string] $SiteURL,
[Parameter(Mandatory=$true)] [string] $ColumnName,
[Parameter(Mandatory=$true)] [string] $ColumnDisplayName,
[Parameter(Mandatory=$true)] [string] $ChoiceValues,
[Parameter(Mandatory=$true)] [string] $IsRequired,
[Parameter(Mandatory=$true)] [string] $ColumnGroup
)
#Generate new GUID for Field ID
$FieldID = ([GUID]::NewGuid()).GUID
Try {
$Cred= Get-Credential
$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
#Setup the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Ctx.Credentials = $Credentials
#Get all Site columns from the site
$Fields = $Ctx.web.Fields
$Ctx.Load($Fields)
$Ctx.executeQuery()
#Check if the column name exists already
$NewField = $Fields | where { ($_.Internalname -eq $ColumnName) -or ($_.Title -eq $ColumnDisplayName) }
if($NewField -ne $NULL)
{
Write-host "Site Column $ColumnName already exists!" -f Yellow
}
else
{
#Frame Choices
$ChoiceOptions=[string]::Empty
$Choices = $ChoiceValues.Split(",")
foreach ($Choice in $Choices)
{
$ChoiceOptions = $ChoiceOptions + "<CHOICE>$Choice</CHOICE>"
}
#Define XML for Field Schema
$FieldSchema = "<Field Type='Choice' ID='{$FieldID}' DisplayName='$ColumnDisplayName' Name='$ColumnName' Required='$IsRequired' Group='$ColumnGroup'> <CHOICES>$ChoiceOptions</CHOICES></Field>"
$FieldSchema
$NewField = $Fields.AddFieldAsXml($FieldSchema,$True,[Microsoft.SharePoint.Client.AddFieldOptions]::AddFieldToDefaultView)
$Ctx.ExecuteQuery()
Write-host "Site Column Created Successfully!" -ForegroundColor Green
}
}
Catch {
write-host -f Red "Error Creating Site Column!" $_.Exception.Message
}
}
#Set parameter values
$SiteURL="https://crescent.sharepoint.com"
$ColumnName="ProjectDepartment"
$ColumnDisplayName="Project Department"
$IsRequired = "TRUE"
$ChoiceValues="IT,Sales,Operations,Marketing,HR"
$ColumnGroup="Crescent Projects"
#Call the function to create site column
Add-ChoiceSiteColumn -SiteURL $SiteURL -ColumnName $ColumnName -ColumnDisplayName $ColumnDisplayName -IsRequired $IsRequired -ChoiceValues $ChoiceValues -ColumnGroup $ColumnGroup
A további testreszabáshoz hozzáadhatja a Type=”MultiChoice” és a Format=”RadioButtons” beállítást is.
Hozzon létre egy keresési webhely oszlopot a SharePoint Online-ban a PowerShell használatával:
#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
#Custom function to add site column
Function Add-LookupSiteColumn()
{
param
(
[Parameter(Mandatory=$true)] [string] $SiteURL,
[Parameter(Mandatory=$true)] [string] $ColumnName,
[Parameter(Mandatory=$true)] [string] $ColumnDisplayName,
[Parameter(Mandatory=$true)] [string] $LookupListName,
[Parameter(Mandatory=$true)] [string] $LookupField,
[Parameter(Mandatory=$true)] [string] $IsRequired,
[Parameter(Mandatory=$true)] [string] $ColumnGroup
)
#Generate new GUID for Field ID
$FieldID = ([GUID]::NewGuid()).GUID
Try {
$Cred= Get-Credential
$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
#Setup the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Ctx.Credentials = $Credentials
#Get all Site columns from the site
$Web = $Ctx.web
$Ctx.Load($Web)
$Fields = $web.Fields
$Ctx.Load($Fields)
$Ctx.executeQuery()
#Check if the column name exists already
$NewField = $Fields | where { ($_.Internalname -eq $ColumnName) -or ($_.Title -eq $ColumnDisplayName) }
if($NewField -ne $NULL)
{
Write-host "Site Column $ColumnName already exists!" -f Yellow
}
else
{
#Get IDs of Lookup List and Web
$LookupList=$Web.Lists.GetByTitle($LookupListName)
$Ctx.Load($LookupList)
$Ctx.executeQuery()
$LookupListID= $LookupList.id
$LookupWebID=$Ctx.web.Id
#Define XML for Field Schema
$FieldSchema = "<Field Type='Lookup' ID='{$FieldID}' DisplayName='$ColumnDisplayName' Name='$ColumnName' Required='$IsRequired' Group='$ColumnGroup' List='$LookupListID' WebId='$LookupWebID' ShowField='$LookupField' />"
$NewField = $Fields.AddFieldAsXml($FieldSchema,$True,[Microsoft.SharePoint.Client.AddFieldOptions]::AddFieldToDefaultView)
$Ctx.ExecuteQuery()
Write-host "Site Column Created Successfully!" -ForegroundColor Green
}
}
Catch {
write-host -f Red "Error Creating Site Column!" $_.Exception.Message
}
}
#Set parameter values
$SiteURL="https://crescent.sharepoint.com"
$ColumnName="ParentProject"
$ColumnDisplayName="Parent Project"
$IsRequired = "TRUE"
$ColumnGroup="Crescent Projects"
$LookupList="Projects" #Parent Lookup
$LookupField="ProjectName"
#Call the function to create site column
Add-LookupSiteColumn -SiteURL $SiteURL -ColumnName $ColumnName -ColumnDisplayName $ColumnDisplayName -IsRequired $IsRequired -ColumnGroup $ColumnGroup -LookupList $LookupList -LookupField $LookupField
Tekintse meg ezt az MSDN-cikket a webhelyoszlopok séma XML-attribútumainak keretezéséről: https://msdn.microsoft.com/en-us/library/office/aa979575.aspx
SharePoint Online PnP PowerShell a webhelyoszlop létrehozásához
Hadd mutassam meg, hogyan hozhat létre webhelyoszlopot a SharePoint Online-ban a PnP PowerShell segítségével.
#Config Variables
$SiteURL = "https://Crescent.sharepoint.com"
$ColumnTitle = "Project Name"
$ColumnInternalName = "ProjectName"
$ColumnGroup="Crescent Site Columns"
$ColumnType = "Text"
#Get Credentials to connect
$Cred = Get-Credential
Try {
#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Credentials $Cred
#Create Site Column
Add-PnPField -DisplayName $ColumnTitle -InternalName $ColumnInternalName -Group $ColumnGroup -Type $ColumnType
}
catch {
write-host "Error: $($_.Exception.Message)" -foregroundcolor Red
}
Választási oszlop hozzáadásához a PnP PowerShell segítségével a következőket használhatja:
#Create a choice Site Column
Add-PnPField -DisplayName "Project Status" -InternalName "ProjectStatus" -Type Choice -Choices "Active", "On-Hold", "Completed"
Az összes elérhető mezőtípust a Microsoft dokumentációjában találja: https://learn.microsoft.com/en-us/dotnet/api/microsoft.sharepoint.client.fieldtype?view=sharepoint-csom!
Hasonlóképpen webhelyoszlopokat is létrehozhat XML-sémából:
#Config Variables
$SiteURL = "https://Crescent.sharepoint.com"
#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Interactive
#Define XML Schema for Text Field
$FieldXML= "<Field Type='Text' Name='ProjectCode' ID='$([GUID]::NewGuid())' DisplayName='Project Code' Required ='FALSE' EnforceUniqueValues = 'TRUE' Indexed='TRUE'></Field>"
#Create Single Line of Text site column
Add-PnPFieldFromXml -FieldXml $FieldXML
Ha a webhely SharePoint-webhelyoszlopa készen áll, hozzáadhatja a listához a listabeállítások, webhelyoszlopok részben. Meglévő webhelyoszlop hozzáadásához a SharePoint Online listához vagy Könyvtárhoz használja a következőket: Hogyan adjunk webhelyoszlopot a SharePoint Online listához?

