سؤال

I want to read the document library content type parent name. Below is the code I used. I am not getting any values in that. Can someone suggest on this?

$contentTypes = $ctx.web.contenttypes  
$ctx.load($contentTypes)  
$ctx.executeQuery()
$ctx.Dispose()
foreach($ct in $contentTypes)
{  
    write-host $ct.Name  
    Write-Host $ct.DocumentTemplate
    Write-Host $ct.DocumentTemplateUrl
    Write-Host $ct.Group
    Write-Host $ct.Description
    Write-Host $ct.Parent.Parent.Name
    Write-Host $ct.Id

Have tried:

$ct.Parent
$ct.Parent.Name
$ct.Parent.Parent.Name
هل كانت مفيدة؟

المحلول

Try this script:

$Web = Get-SPWeb "http://sp"

$cts=$Web.ContentTypes
foreach($ct in $cts)
{
Write-Host $ct.get_Name()
Write-Host $ct.get_Parent().Name
Write-Host "--------------------"
}

Test result:

enter image description here

Updated

Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"



$webURL="http://sp"
$ctx= New-Object Microsoft.SharePoint.Client.ClientContext($webURL)

try{
    $web = $ctx.web
    
    $cts=$web.ContentTypes
    $ctx.Load($web)
    $ctx.Load($cts)
    $ctx.executeQuery()
    foreach($ct in $cts)
{
$ctx.Load($ct.Parent)
    $ctx.executeQuery()
Write-Host $ct.get_Name()
Write-Host $ct.get_Parent().Name
Write-Host "--------------------"
}
}
catch{
    write-host "$($_.Exception.Message)" -foregroundcolor red
}

New test result:

enter image description here

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى sharepoint.stackexchange
scroll top