SharePoint Online: PowerShell kullanarak İçerik Türünden Sütunlar Alın
Gereksinim: SharePoint Online'da İçerik Türü Alanlarını Almak için PowerShell.
SharePoint Online'daki İçerik Türünden Sütunlar Almak için PowerShell:
SharePoint Online içerik türünüzdeki tüm alanların bir listesini almaya hiç ihtiyaç duydunuz mu? İçerik türünün tüm alanlarını içerik türü ayarları sayfasından alabilirsiniz.
Belirli bir içerik türü için tüm meta verileri dışa aktarmaya ne dersiniz? PowerShell kurtarmaya!
#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"
Function Get-SPOContentTypeFields()
{
param
(
[Parameter(Mandatory=$true)] [string] $SiteURL,
[Parameter(Mandatory=$true)] [string] $ContentTypeName
)
Try {
#Get Credentials to connect
$Cred= Get-Credential
#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 web
$Web = $Ctx.Web
$Ctx.Load($Web)
$Ctx.ExecuteQuery()
#Get the content type from web
$ContentTypeColl = $Web.ContentTypes
$Ctx.Load($ContentTypeColl)
$Ctx.ExecuteQuery()
#Get the content type
$CType = $ContentTypeColl | Where {$_.Name -eq $ContentTypeName}
If($CType -ne $Null)
{
$Ctx.Load($CType.FieldLinks)
$Ctx.ExecuteQuery()
#Get columns from the content type
ForEach($FieldLink in $CType.FieldLinks)
{
Write-Host -f Green $FieldLink.Name
}
}
else
{
Write-host "Content Type '$ContentTypeName' doesn't exist!'" -f Yellow
Return
}
}
Catch {
write-host -f Red "Error:" $_.Exception.Message
}
}
#Set parameter values
$SiteURL="https://crescent.sharepoint.com/sites/marketing"
$ContentTypeName="Announcement"
#Call the function
Get-SPOContentTypeFields -SiteURL $SiteURL -ContentTypeName $ContentTypeName
SharePoint Online: Bir Listeden İçerik Türü Alanlarını Almak için PowerShell
İçerik Türü ve sütunlarının bir listesini almak, bunlar arasında geçiş yapmak ve aşağıdaki verileri içeren bir CSV dosyası çıktısı almak için PowerShell'im:
- Sütun Başlığı
- Sütun Dahili Adı
- Sütun Kimliği
- Sütun Grubu
- Kolon AÇIKLAMASI
#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"
Function Get-SPOListCTypeFields()
{
param
(
[Parameter(Mandatory=$true)] [string] $SiteURL,
[Parameter(Mandatory=$true)] [string] $ListName,
[Parameter(Mandatory=$true)] [string] $ContentTypeName,
[Parameter(Mandatory=$true)] [string] $CSVPath
)
Try {
#Get Credentials to connect
$Cred= Get-Credential
#Setup the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
#Get content types from web
$ContentTypes = $Ctx.Web.ContentTypes
$Ctx.Load($ContentTypes)
$Ctx.ExecuteQuery()
#Get the content type
$CType = $ContentTypes | Where {$_.Name -eq $ContentTypeName}
If($CType -ne $Null)
{
#Get Columns from the content type
$Ctx.Load($CType.Fields)
$Ctx.ExecuteQuery()
$ResultArray = @()
#Loop through the Fields in the Content Type
ForEach ($Field in $CType.Fields)
{
#Create a new custom object to hold our row of data with property names:
$Result = New-Object PSObject
$Result | Add-Member -MemberType NoteProperty -Name "Title" -Value $Field.Title
$Result | Add-Member -MemberType NoteProperty -Name "Internal Name" -Value $Field.InternalName
$Result | Add-Member -MemberType NoteProperty -Name "ID" -Value $Field.Id
$Result | Add-Member -MemberType NoteProperty -Name "Group" -Value $Field.Group
$Result | Add-Member -MemberType NoteProperty -Name "Description" -Value $Field.Description
#Add the object to array
$ResultArray += $Result
}
$ResultArray | Format-table -AutoSize
# Export the results to CSV
$ResultArray | Export-Csv $CSVPath -NoTypeInformation -force
Write-host "Content Type Columns Exported to CSV successfully!'" -f Green
}
else
{
Write-host "Content Type '$ContentTypeName' doesn't exist!'" -f Yellow
}
}
Catch {
write-host -f Red "Error:" $_.Exception.Message
}
}
#Set parameter values
$SiteURL ="https://crescent.sharepoint.com/sites/marketing"
$ListName ="News"
$ContentTypeName="Announcement"
$CSVPath = "C:\Temp\CtypeFields.csv"
#Call the function
Get-SPOListCTypeFields -SiteURL $SiteURL -ListName $ListName -ContentTypeName $ContentTypeName -CSVPath $CSVPath
Bir İçerik türünden Tüm Alanları Almak için PnP PowerShell
Bir içerik türünden alanlar almak için PowerShell'i nasıl kullanacağınızı size göstereyim.
#Parameters
$SiteURL = "https://crescent.sharepoint.com/sites/marketing"
$ContentTypeID ="0x0104004A217DA260E04940AC9DB4A010797423"
#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Interactive
#Get the site content type
$ContentType = Get-PnPContentType -Identity $ContentTypeID
#Get All Fields from the Content Type
$ContentTypeFields = Get-PnPProperty -ClientObject $ContentType -Property Fields
#Get Field Title and ID
$ContentTypeFields | Select Title, ID
Benzer şekilde, bir liste içerik türünden tüm alanları almak için şunu kullanın:
#Parameters
$SiteURL = "https://crescent.sharepoint.com/sites/marketing"
$ListName = "Projects"
$ContentTypeName ="Crescent Project V2"
#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Interactive
#Get the List content type
$ContentType = Get-PnPContentType -Identity $ContentTypeName -List $ListName
#Get All Fields from the Content Type
$ContentTypeFields = Get-PnPProperty -ClientObject $ContentType -Property Fields
#Get Field Title, Internal Name and ID
$ContentTypeFields | Select Title, InternalName, ID
Kapanıyor
Özetle, SharePoint Online'da belirli bir içerik türüyle ilişkili alanların PowerShell kullanarak nasıl alınacağını gördük. Sağlanan betiği kullanarak SharePoint Online ortamınıza bağlanabilir ve belirli bir içerik türüyle ilişkili alanların ayrıntılarını alabilirsiniz. Bu bilgiler, SharePoint içeriğinizi yönetmek veya raporlama amaçları gibi yönetimsel amaçlar için yararlı olabilir. PowerShell'in yardımıyla görevleri otomatikleştirip kolaylaştırabilir, böylece SharePoint Online yönetim görevlerinizi daha verimli hale getirebilirsiniz.
