SharePoint Online: PowerShell kullanarak Site Sütunu Oluşturma


Gereksinim: SharePoint Online'da site sütunları oluşturun.

SharePoint Online'daki site sütunları

Site sütunları, listelerde ve kitaplıklarda ihtiyaç duyduğunuzda alanları yeniden oluşturmak zorunda kalmadan SharePoint'te mükemmel bir yeniden kullanılabilirlik sağlar. Özellikle sütunları standartlaştırmanız, veri içeren sütunlar oluşturmanız (seçim alanları gibi) veya bunlara varsayılan değerler atamanız gerektiğinde, çok fazla zaman tasarrufu sağlarlar. Bir site sütunu, üst düzey sitede oluşturulduktan sonra herhangi bir listede veya kitaplıkta, hatta SharePoint site hiyerarşinizdeki (veya içerik türü merkeziyle site koleksiyonları genelinde) içerik türlerinde kullanılabilir.

SharePoint Online'da Site Sütunu Nasıl Oluşturulur?

Site sütunları, SharePoint Online'da listeler, kitaplıklar ve içerik türleri arasında meta verileri tanımlamanıza ve yeniden kullanmanıza olanak tanıyan güçlü bir araçtır. Bu blog gönderisi, SharePoint Online'da nasıl site sütunu oluşturulacağını gösterecektir. Listelerinizde ve kitaplıklarınızda depolanan verileri standartlaştırmanın ve bilgileri bulmayı ve kullanmayı kolaylaştırmanın harika bir yoludur. Başlayalım!

SharePoint Online'da site sütunu oluşturmak için şu adımları izleyin:

  1. SharePoint Online sitesine giriş yapın. Site Ayarları Dişlisi'ne tıklayın ve Site Ayarları'nı seçin.
  2. Site Ayarları sayfasında “Web Tasarımcısı Galerileri” grubunun altındaki “Site Sütunları” bağlantısını tıklayın. Bu sayfa mevcut tüm site sütunlarını listeler.
  3. Site Sütunları sayfasında üstteki “Oluştur” bağlantısını tıklayın.

  4. Sütun oluştur sayfasında site sütununuzun adını girin. Sütun türünü seçin ve yeni site sütununa özel ek sütun ayarlarını belirtin. Site sütununuz için mevcut grubu veya yeni grubu seçin. SharePoint Online'da site sütununu oluşturmayı tamamlamak için alttaki “Tamam” düğmesine tıklayın.

Artık site sütunu siteye eklenecektir. Bir site sütunu oluşturduktan sonra sitenizdeki herhangi bir listeye veya kitaplığa eklenebilir.

SharePoint Online'da PowerShell'i kullanarak Site Sütunları Oluşturun:

PowerShell kullanarak SharePoint Online'da nasıl site sütunu oluşturulacağını görelim. İstemci tarafı nesne modelini (CSOM) kullanarak SharePoint Online'da site sütunları oluşturmak için PowerShell komut dosyaları koleksiyonumu burada bulabilirsiniz.

Önemli: Alan Şeması XML'si büyük/küçük harfe duyarlıdır!

PowerShell'i kullanarak SharePoint Online'da Tek Satırlı Metin Sitesi Sütunu Oluşturma

Site sütunu eklemek için SharePoint Online PowerShell'i burada bulabilirsiniz:


#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
}

PowerShell kullanarak Birden Çok Satır Metin Alanı Ekleme

Bu sefer kodu yeniden kullanılabilir bir fonksiyona saralım:


#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

SharePoint Online'da Kişi veya Grup (Kişi Seçici) Site Sütunu Oluşturmak için PowerShell:


#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 

SharePoint Online'a Tarih ve Saat Sitesi Sütunu Ekleme:


#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

SharePoint Online için Para Birimi Sitesi Sütunu Eklemeye yönelik PowerShell CSOM betiği


#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

Tüm LCID'ler için https://msdn.microsoft.com/en-us/library/microsoft.sharepoint.splocale.lcid.aspx adresine bakın.

SharePoint Online: PowerShell ile Numaralı Site Sütunu Ekleme


#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

PowerShell kullanarak SharePoint Online'a Seçim Sitesi Sütunu Nasıl Eklenir?


#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

Daha da özelleştirmek için Type=”MultiChoice” ve Format=”RadioButtons” da ekleyebilirsiniz.

PowerShell'i kullanarak SharePoint Online'da Arama Sitesi Sütunu oluşturun:


#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

Site sütunlarına ilişkin çerçeve şeması XML niteliklerini öğrenmek için bu MSDN makalesine bakın: https://msdn.microsoft.com/en-us/library/office/aa979575.aspx

Site Sütunu Oluşturmak için SharePoint Çevrimiçi PnP PowerShell

PnP PowerShell ile SharePoint Online'da nasıl site sütunu oluşturulacağını size göstereyim.


#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
}

PnP PowerShell ile bir seçim sütunu eklemek için şunları kullanabilirsiniz:


#Create a choice Site Column
Add-PnPField -DisplayName "Project Status" -InternalName "ProjectStatus" -Type Choice -Choices "Active", "On-Hold", "Completed"

Mevcut tüm alan türleri için https://learn.microsoft.com/en-us/dotnet/api/microsoft.sharepoint.client.fieldtype?view=sharepoint-csom Microsoft belgelerine bakın!

Benzer şekilde, XML şemasından site sütunlarını şu şekilde oluşturabilirsiniz:


#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

Site SharePoint site sütunu hazır olduğunda liste ayarları, site sütunları bölümünden listenize ekleyebilirsiniz. SharePoint Online listesine veya Kitaplığına mevcut bir site sütununu eklemek için şunu kullanın: SharePoint Çevrimiçi Listesine Site Sütunu Nasıl Eklenir?

İlgili makaleler