I have a Discussion list in which i need to add a new topic in SharePoint 2010 using Powershell.


Powershell Script:
  1. $site=Get-SPSite "http://serverName/sites/VJTesting/"
  2. $web=$site.OpenWeb()
  3. $list=$web.Lists.TryGetList("Team Discussion")
  4. if($list -ne $null)
  5. {
  6. $newTopic = [Microsoft.SharePoint.Utilities.SPUtility]::CreateNewDiscussion($list, "Topic6");
  7. # In the "body" column you can add the HTML content so that you can add images and add the styles for the contents.
  8. # To get the HTML content - Go to the "Discussion" list, then click on "Add new Discussion".
  9. # In the body column add the contents and images.
  10. # In the ribbon interface, click on "Editing Tools" and then click on "Format text" tab.
  11. # In the "Markup" group you could see "HTML" option.
  12. # Click on the down arrow and then click on "Edit HTML Source".
  13. # Copy the HTML source.
  14. $newTopic["Body"] = "<div class='ExternalClassF7F26CE68055477797898F1D2250E309'><div class='ExternalClass37FC140BAA764AAD9DAB0F050FD45712' style='color: #ec008c; text-decoration: underline'><p><strong>"My new Topic."<img alt='DISCUSS.GIF' src='/sites/VJTesting/SiteAssets/Lists/Team%20Discussion/EditForm/DISCUSS.GIF' style='margin: 5px'/><br/><br/></strong>?</p></div></div>";
  15. $newTopic.Update();
  16. Write-Host -ForegroundColor Green $newTopic.Title " discussion topic is created successfully"
  17. }
  18. else
  19. {
  20. Write-Host -ForegroundColor Yellow "List does not exists."
  21. }