I need to set target audience field in a list while populating the list with data. How can I achieve this using PowerShell command.

I found this article. But it didn't worked as it throws

Column 'Target Audiences' does not exist. It may have been deleted by another user.

But Target audiences field is there when I inspect from list settings.

Here is the sample code I used :

$SiteUrl = "SiteUrl"
$listName = "ListName"
$spWeb = Get-SPWeb -Identity $SiteUrl 
$dataCount = 100
$targetAudience = "newusers"
    if($list -ne $null)
      write-host -f green $listName "List exists. Now Populating data."
        for($i=0; $i -lt $dataCount; $i++)
             $newItem = $list.Items.Add()
             $randomCatg = "data"          
             $newItem["Menu Category"] = "data"
             $newItem["MenuItem"] = "data"
             $newItem["Date"] = "data"
             $newItem["Target Audiences"] = $targetAudience

Update :
Then I set the target audience field as below by referring this SO Post $newItem[$newItem.Fields["Target Audiences"].InternalName] = $targetAudience but still not solved

Is this really possible or am I doing it in the wrong way?

  • 1
    It worked after I restarted the Sharepoint server. I don't know what the reason is but it worked after restarting. – Unknown Dec 8 '16 at 5:55

Your Answer

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

Browse other questions tagged or ask your own question.