Steps Involved
- Open SharePoint 2010 Management Shell by going to Start | All Programs | SharePoint | Microsoft SharePoint 2010 Products | SharePoint 2010 Management Shell (Run as Administrator).
- Run the following script.
Powershell Script
##Add new tag with the specified keyword to the specified url using SharePoint 2010 web service in powershell
$uri="http://serverName:10736/sites/ECT/_vti_bin/SocialDataService.asmx?wsdl"
## $url is a string that contains the URL for which the comment has to be added by the specified user
$url="http://serverName:10736/sites/ECT/"
## $keyword is a string that contains the contents of the social tag
$keyword="My New Tag"
## $isHighPriority -true to indicate the social tag is private; otherwise, false. If this value is null, this method assumes false for this parameter.
$isPrivate=$false
## $title is a string that contains the title of the social tag
$title="My New Tag"
## Get the credential for which the new tag has to be added for the specified url $url
$credential=Get-Credential
## Web Service Reference - http://Site/_vti_bin/SocialDataService.asmx
$socialDataServiceWebServiceReference = New-WebServiceProxy -Uri $uri -Credential $credential
$tag=$socialDataServiceWebServiceReference.AddTagByKeyword($url,$keyword,$title,$isPrivate)
## $tag is of Type: [SocialDataService Web service].SocialTagDetail()
##[SocialDataService Web service].SocialTagDetail() - Refer http://msdn.microsoft.com/en-us/library/websvcsocialdataservice.socialcommentdetail_members.aspx

Vijai Anand RamalingamPosted Dec 28, 2011, 1:31 AM
Hi Achyutha Rao, Thats great!!! Thanks Vijai
Achyutha RaoPosted Dec 28, 2011, 12:39 AM
Hi Vijai, Thanks for all your help. The script works fine now and creates tags on the intended documents. (Just needed to change the document format from docx to doc) Thanks and Best Regards, Achyutha
Achyutha RaoPosted Dec 23, 2011, 8:53 AM
Vijai, The script works fine not with $uri="http://sp2010cluster:3333/Shared%20Documents/_vti_bin/SocialDataService.asmx?wsdl", but with $uri="http://sp2010cluster:3333/_vti_bin/SocialDataService.asmx?wsdl". I shows the msg. that the New Tag was added to the specified documents under "Shared Documents". But when I manually check if the tags were added by individually going to the documents, I see that the tags are still not added. I did a content database crawl once more, but the newly added tags are not getting displayed.
Vijai Anand RamalingamPosted Dec 23, 2011, 8:05 AM
Hi Achyutha Rao, please try the following script. CreateMultipleTags.ps1: #----------------Get the xml file--------------------------------------------------------------- [xml]$xmlData=Get-Content "C:\scripts\CreateMultipleTags.xml" #----------------Create Multiple Tags function---------------------------------------------------- Function CreateMultipleTags() { ##Add multiple tags with the specified keyword to the specified url using SharePoint 2010 web service in powershell $uri="http://sp2010cluster:3333/Shared%20Documents/_vti_bin/SocialDataService.asmx?wsdl" ## Get the credential for which the new tag has to be added for the specified url $url $credential=Get-Credential Write-Host -ForegroundColor Magenta "Creating new tags........." foreach($newTag in $xmlData.CreateTags.Tag) { ## $url is a string that contains the URL for which the comment has to be added by the specified user $url=$newTag.Url ## $keyword is a string that contains the contents of the social tag $keyword=$newTag.Keyword ## $isHighPriority -true to indicate the social tag is private; otherwise, false. If this value is null, this method assumes false for this parameter. if($newTag.IsPrivate -eq "True") { $isPrivate=$true } else { $isPrivate=$false } ## $title is a string that contains the title of the social tag $title=$newTag.Title ## Web Service Reference - http://Site/_vti_bin/SocialDataService.asmx # Web Service Reference - http://sp2010cluster:3333/_vti_bin/SocialDataService.asmx $socialDataServiceWebServiceReference = New-WebServiceProxy -Uri $uri -Credential $credential $tag=$socialDataServiceWebServiceReference.AddTagByKeyword($url,$keyword,$title,$isPrivate) Write-Host -ForegroundColor Green " A new Tag named " $keyword " is created successfully for the URL : " $url } } CreateMultipleTags.xml: <?xml version="1.0" encoding="utf-8" ?> <CreateTags> <Tag url="http://sp2010cluster:3333/Shared%20Documents/002.docx" Keyword="New Tag 1" Title="New Tag 1" IsPrivate="False" /> <Tag url="http://sp2010cluster:3333/Shared%20Documents/06_CoDR_UPS.docx" Keyword="New Tag 2" Title="New Tag 2" IsPrivate="False" /> <Tag url="http://sp2010cluster:3333/Shared%20Documents/06_Transportation.docx" Keyword="New Tag 3" Title="New Tag 3" IsPrivate="False" /> <Tag url="http://sp2010cluster:3333/Shared%20Documents/1PG.docx" Keyword="New Tag 4" Title="New Tag 4" IsPrivate="False" /> </CreateTags>
Achyutha RaoPosted Dec 23, 2011, 7:37 AM
Vijai, Here was the modified powershell script that I executed: #----------------Get the xml file--------------------------------------------------------------- [xml]$xmlData=Get-Content "C:\scripts\CreateMultipleTags.xml" #----------------Create Multiple Tags function---------------------------------------------------- Function CreateMultipleTags() { ##Add multiple tags with the specified keyword to the specified url using SharePoint 2010 web service in powershell #$uri="http://serverName:10736/sites/ECT/_vti_bin/SocialDataService.asmx?wsdl" $uri="http://sp2010cluster:3333/Shared%20Documents/Forms/AllItems.aspx" ## Get the credential for which the new tag has to be added for the specified url $url $credential=Get-Credential Write-Host -ForegroundColor Magenta "Creating new tags........." foreach($newTag in $xmlData.CreateTags.Tag) { ## $url is a string that contains the URL for which the comment has to be added by the specified user $url=$newTag.Url ## $keyword is a string that contains the contents of the social tag $keyword=$newTag.Keyword ## $isHighPriority -true to indicate the social tag is private; otherwise, false. If this value is null, this method assumes false for this parameter. if($newTag.IsPrivate -eq "True") { $isPrivate=$true } else { $isPrivate=$false } ## $title is a string that contains the title of the social tag $title=$newTag.Title ## Web Service Reference - http://Site/_vti_bin/SocialDataService.asmx # Web Service Reference - http://sp2010cluster:3333/Shared%20Documents/Forms/AllItems.aspx $socialDataServiceWebServiceReference = New-WebServiceProxy -Uri $uri -Credential $credential $tag=$socialDataServiceWebServiceReference.AddTagByKeyword($url,$keyword,$title,$isPrivate) Write-Host -ForegroundColor Green " A new Tag named " $keyword " is created successfully for the URL : " $url ## $tag is of Type: [SocialDataService Web service].SocialTagDetail() ##[SocialDataService Web service].SocialTagDetail() - Refer http://msdn.microsoft.com/en-us/library/websvcsocialdataservice.socialcommentdetail_members.aspx } } #----------------Calling the function------------------------------------------------------------ CreateMultipleTags ============================================================== And here was the CreateMultipleTags.xml that I created: <?xml version="1.0" encoding="utf-8" ?> - <CreateTags> <Tagurl="http://sp2010cluster:3333/Shared%20Documents/002.docx" Keyword="New Tag 1" Title="New Tag 1" IsPrivate="False" /> <Tagurl="http://sp2010cluster:3333/Shared%20Documents/06_CoDR_UPS.docx" Keyword="New Tag 2" Title="New Tag 2" IsPrivate="False" /> <Tagurl="http://sp2010cluster:3333/Shared%20Documents/06_Transportation.docx" Keyword="New Tag 3" Title="New Tag 3" IsPrivate="False" /> <Tagurl="http://sp2010cluster:3333/Shared%20Documents/1PG.docx" Keyword="New Tag 4" Title="New Tag 4" IsPrivate="False" /> </CreateTags> =================================================== But I got an erroneous output: PS C:\Windows\system32> C:\scripts\tag1.ps1 Cannot convert value "System.Object[]" to type "System.Xml.XmlDocument". Error: "Data at the root level is invalid. Line 2, position 1. " At C:\scripts\tag1.ps1:3 char:14 + [xml]$xmlData <<<< =Get-Content "C:\scripts\CreateMultipleTags.xml" + CategoryInfo : MetadataError: (:) [], ArgumentTransformationMetadataException + FullyQualifiedErrorId : RuntimeException Creating new tags......... New-WebServiceProxy : The HTML document does not contain Web service discovery information. At C:\scripts\tag1.ps1:33 char:60 + $socialDataServiceWebServiceReference = New-WebServiceProxy <<<< -Uri $uri -Credential $credential + CategoryInfo : InvalidOperation: (http://sp2010cl...s/AllItems.aspx:Uri) [New-WebServiceProxy], InvalidOperationExcepti on + FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.Commands.NewWebServiceProxy You cannot call a method on a null-valued expression. At C:\scripts\tag1.ps1:34 char:59 + $tag=$socialDataServiceWebServiceReference.AddTagByKeyword <<<< ($url,$keyword,$title,$isPrivate) + CategoryInfo : InvalidOperation: (AddTagByKeyword:String) [], RuntimeException + FullyQualifiedErrorId : InvokeMethodOnNull A new Tag named is created successfully for the URL : ======================================== Could you please let me know where I did a mistake?
Vijai Anand RamalingamPosted Dec 23, 2011, 7:19 AM
Hi Achyutha Rao, You just need to modify $uri value. Other than that you no need to modify anything in the powershell script. You need to modify the CreateMultipleTags.xml file alone. In that you modify the parameter values according to your requirement. Thanks, Vijai
Achyutha RaoPosted Dec 23, 2011, 6:40 AM
Ok, Vijai. But in the script that you mentioned at http://www.c-sharpcorner.com/Blogs/7841/create-multiple-tags-for-the-sharepoint-2010-site-url-using.aspx, on these lines, what shud I change? ------------------------------------- $socialDataServiceWebServiceReference = New-WebServiceProxy -Uri $uri -Credential $credential $tag=$socialDataServiceWebServiceReference.AddTagByKeyword ----------------------------------- bcos these lines have a reference to "Social Data Service". But if it is to be a default page as I mentioned earlier, what wud be the variable that I need to use instead of the above 2 lines mentioned? Thanks, Achyutha
Vijai Anand RamalingamPosted Dec 23, 2011, 6:18 AM
Hi Achyutha Rao, You could use the same script to add tags to the multiple documents, in the CreateMultipleTags.xml replace the Url attribute value with your documents url for example http://serverName:10736/sites/ECT/Shared%20Documents/123.docx. So that you could add the "n" number of document urls in the CreateMultipleTags.xml and you could add the tags to multiple documents. I hope this would help you . Thanks, Vijai
Achyutha RaoPosted Dec 23, 2011, 6:03 AM
Vijai, thanks for your reply on site page tagging. Could you also please let me know if there is a script to automate tagging of individual documents under a site. I have some 35 documents (ppt, doc, pdf, xl) to which I tried manually adding the tags to each of the individual files (by selecting them using the checkbox) and then doing a content database crawl using "Search Service Application" and the tags appear on the site page when I search for a particualr keyword that was used as tag. Now, it wud be great to automate this process of manually adding tags to variosu documents under a site using PowerShell. Please let me know if I can get a script for the same. Thanks, Achyutha
Vijai Anand RamalingamPosted Dec 23, 2011, 4:44 AM
Hi Achyutha Rao, in the CreateMultipleTags.xml replace the Url attribute value with your default site page url. So that ttags will be created for the default site page. SocialDataService.asmx is web service that will be available in the _vti_bin. You no need to create any service. By default it will be available for SharePoint in the path C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\isapi. Thanks, Vijai
Achyutha RaoPosted Dec 23, 2011, 3:10 AM
Vijai, I was more looking for creating multiple tags under the default site page that we get once we create a web applicaiton -> create a team site using that web app. But in the example that you have just now posted, I see thiat the multiple tags are created taking into account the social data service. Is this a service application that needs to be added at Central Admin -> Manager Service application or could you please let me know if I can just create multiple tags under the default condition that mentioned above. (using PowerShell) Thanks, Achyutha
Vijai Anand RamalingamPosted Dec 23, 2011, 2:43 AM
Hi Achyutha Rao, Please refer my blog http://www.c-sharpcorner.com/Blogs/7841/create-multiple-tags-for-the-sharepoint-2010-site-url-using.aspx for creating multiple social tags for the specified url. Hope this blog would helps for your requirement. Thanks, Vijai
Achyutha RaoPosted Dec 23, 2011, 1:37 AM
Vijai Anand, Could you please let me know, how to create tags using PowerShell on SharePoint 2010? My requirement is as follows: I have a web application created, with the public url, http://sp2010cluster:3333 and I have created a team site under this web application, clicking which, I get the url, http://sp2010cluster:3333/SitePages/Forms/AllPages.aspx Now, it is under this site that I want tags to be created using PowerShell scripting. Because my intent is to have multiple tags created, for which I need a PowerShell script to speed up my process for creating many no. of tags. Could you please let me know what the PowerShell script wud be for this? Thanks, Achyutha