1

I've written a bit of powershell for creating a list just wondering how add say an if statement to check if its already been created. In Client side not server side here is my code :

   param(
    [Parameter(Mandatory=$true)][string]$url,
    [Parameter(Mandatory=$true)][System.Net.NetworkCredential]$credentials,
    [Parameter(Mandatory=$true)][string]$listName

)

$context = New-Object Microsoft.SharePoint.Client.ClientContext($url)
$context.Credentials = $credentials
$web = $context.Web 
$context.Load($web)    
$context.ExecuteQuery()

$ListInfo = New-Object Microsoft.SharePoint.Client.ListCreationInformation
$ListInfo.Title = $ListTitle
$ListInfo.TemplateType = "100"
$myList = $web.Lists.Add($ListInfo)
$myList.Description = $ListTitle
$myList.Update()
$Fields=$myList.Fields
$context.Load($Fields)
$context.ExecuteQuery() 
2
$list1 = $web.Lists | where{$_.Title -eq $listName1}if($list1){// Execute if list exists}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.