Create a discussion topic in SharePoint 2010 using Powershell

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


Powershell Script:


 

$site=Get-SPSite "http://serverName/sites/VJTesting/"

$web=$site.OpenWeb()

$list=$web.Lists.TryGetList("Team Discussion")

if($list -ne $null)

{

     $newTopic = [Microsoft.SharePoint.Utilities.SPUtility]::CreateNewDiscussion($list, "Topic6");

     # In the "body" column you can add the HTML content so that you can add images and add the styles for the contents.

     # To get the HTML content - Go to the "Discussion" list, then click on "Add new Discussion".

     # In the body column add the contents and images.

     # In the ribbon interface, click on "Editing Tools" and then click on "Format text" tab.

     # In the "Markup" group you could see "HTML" option.

     # Click on the down arrow and then click on "Edit HTML Source".

     # Copy the HTML source.

     $newTopic["Body"] = "<div class='ExternalClassF7F26CE68055477797898F1D2250E309'><div class='ExternalClass37FC140BAA764AAD9DAB0F050FD45712' style='color: #ec008c; text-decoration: underline'><p><strong>&quot;My new Topic.&quot;<img alt='DISCUSS.GIF' src='/sites/VJTesting/SiteAssets/Lists/Team%20Discussion/EditForm/DISCUSS.GIF' style='margin: 5px'/><br/><br/></strong>?</p></div></div>";

     $newTopic.Update();     

     Write-Host -ForegroundColor Green $newTopic.Title " discussion topic is created successfully"

}

else

{

      Write-Host -ForegroundColor Yellow "List does not exists." 

}




Ebook Download
View all
Learn
View all