Get-xSPOListProperty.ps1


<#PSScriptInfo
 
.VERSION 1.0
 
.GUID a98e5cc1-5e44-4e30-ab2a-6b3353bb684f
 
.AUTHOR Chendrayan Venkatesan
 
.COMPANYNAME
 
.COPYRIGHT
 
.TAGS SharePointOnline CSOM PowerShell
 
.LICENSEURI
 
.PROJECTURI
 
.ICONURI
 
.EXTERNALMODULEDEPENDENCIES
 
.REQUIREDSCRIPTS
 
.EXTERNALSCRIPTDEPENDENCIES
 
.RELEASENOTES
 
 
#>


<#
 
.DESCRIPTION
 Retrieves SharePoint Online List or Document Libraries properties (Excludes Collections)
 
#>
 
Param
(
    # SharePoint Online Url
    [Parameter(Mandatory,ValueFromPipeline,ValueFromPipelineByPropertyName)]
    [Uri]
    $Url,
    
    # SharePoint Online Admin Credential
    [Parameter(Mandatory)]
    [System.Management.Automation.CredentialAttribute()]
    [pscredential]
    $Credential
)
Import-Module 'C:\Program Files\NuGet\Packages\Microsoft.SharePointOnline.CSOM.16.1.5312.1200\lib\net45\Microsoft.SharePoint.Client.dll'

function Get-xSPOListProperty
{
<#
.SYNOPSIS
    Get SharePoint list properties
.DESCRIPTION
    Get-xSPOListProperty retrieves all the SharePoint online list or document library properties.
    This function allows to select the properties with tab completion.
.EXAMPLE
    C:\PS> Get-xSPOListProperty -Url "https://contoso.sharepoint.com" -Credential "Chendrayan@contoso.onmicrosoft.com"
    Get all the properties of list or document library
.EXAMPLE
    C:\PS> Get-xSPOListProperty -Url "https://contoso.sharepoint.com" -Credential "Chendrayan@contoso.onmicrosoft.com" | Select Title , NoCrawl , Hidden
    Get selected the properties of the list or document library
.EXAMPLE
    C:\PS> "https://chensoffice365.sharepoint.com", "https://contoso.sharepoint.com/subsite" , "https://contoso.sharepoint.com/subsite1" |
    Get-xSPOListProperty -Credential "Chendrayan@contoso.onmicrosoft.com" | Select Title , ParentWebUrl
    Get Title and parentweburl properties of list or document library from multiple sharepoint online sites
.LINK
    https://msdn.microsoft.com/en-us/library/microsoft.sharepoint.client.list.aspx
.NOTES
    To check the list properties use help Get-xSPOListProperty -Online
#>

    [Outputtype('Microsoft.SharePoint.Client.List')]
    param 
    (
        # SharePoint Online Url
        [Parameter(Mandatory,ValueFromPipeline,ValueFromPipelineByPropertyName)]
        [Uri]
        $Url,

        # SharePoint Online Admin Credential
        [Parameter(Mandatory)]
        [System.Management.Automation.CredentialAttribute()]
        [pscredential]
        $Credential
    )

    process
    {
        try 
        {
            $SPOClientContext = [Microsoft.SharePoint.Client.ClientContext]::new($Url)
            $SPOClientContext.Credentials = [Microsoft.SharePoint.Client.SharePointOnlineCredentials]::new($Credential.UserName,$Credential.Password)
            $ListCollection = $SPOClientContext.Web.Lists
            $SPOClientContext.Load($ListCollection)
            $SPOClientContext.ExecuteQuery()
            $SPOClientContext.Dispose()
            foreach($List in $ListCollection)
            {
                $List | Select -Property ([Microsoft.SharePoint.Client.List].GetProperties().Where({$_.Propertytype -notlike "*Collection*"})).Name
            }
            
        }
        catch
        {
            $_.Exception.Message
        }
    }
}