Add SPList With CSOM
In Powershell
function AddList()
{param($url0, $title)
$context0 = New-Object Microsoft.SharePoint.Client.ClientContext($url0);
$context0.AuthenticationMode = [Microsoft.SharePoint.Client.ClientAuthenticationMode]::FormsAuthentication
$credentials0 = New-Object Microsoft.SharePoint.Client.FormsAuthenticationLoginInfo("d03305", $mypsw);
$context0.FormsAuthenticationLoginInfo = $credentials0;
[Microsoft.SharePoint.Client.Web]$web0 = $context0.Web;
$context0.Load($web0)
$context0.Load($web0.ListTemplates)
$context0.ExecuteQuery()
$template = $web0.ListTemplates | Where-Object {$_.Name -eq "Fiche de conformité"}
$template.Name
#check if list exists
$list = $null;
try
{
$list = $web0.GetList("$($web0.ServerRelativeUrl.TrimEnd("/"))/$($title)");
$context0.Load($list);
$context0.ExecuteQuery();
}
catch
{
$list = $null;
}
if($list -eq $null)
{
Write-Host "list is null"
#creation de la liste
$ListInfo = New-Object Microsoft.SharePoint.Client.ListCreationInformation
$ListInfo.Title = $title
[System.Int32]$lstId = 100#$template.ListTemplateTypeKind;
$ListInfo.TemplateType = $lstId;
$List1 = $web0.Lists.Add($ListInfo);
<#
$List1.Description = "$($title) GED Corporate";
$List1.Update()
#>
$context0.ExecuteQuery()
}
else
{
Write-Host "list is not null"
}
$list.Title;
$context0.Dispose();
$context0 = $null;
}