0

I am using the following code/function to add groups to a site:

function Create-SPGroupInWeb 
{  
    param ($url, $groupName, $permissionLevel, $description)  
    try{
        $web = Get-SPWeb -Identity $url
        if($web -ne $null){
            if ($web.SiteGroups[$groupName] -ne $null)  
            {  
                write-Host -f red "Group $groupName already exists!"
            }  
            else  
            {  
                $web.SiteGroups.Add($groupName, $web.Site.Owner, $web.Site.Owner, $description)  
                $group = $web.SiteGroups[$groupName]  
                $roleAssignment = new-object Microsoft.SharePoint.SPRoleAssignment($group)  
                $roleDefinition = $web.Site.RootWeb.RoleDefinitions[$permissionLevel]  
                $roleAssignment.RoleDefinitionBindings.Add($roleDefinition)  
                $web.RoleAssignments.Add($roleAssignment)  
                $web.Update()
                write-Host "Group $groupName created successfully"
            }  

            $web.Dispose() 
        }
    }
    catch [System.Exception]
    {
        write-host -f red $_.Exception.ToString()
    }
}


Create-SPGroupInWeb -url "http://my-webApp:port/" -groupName "New Group" -permissionLevel "Read" -description "My New Group Description"

Now, this works perfectly as is. However, this does not like it if I use HTML Code...

The Issue is: It creates the description as Plain Text...

Q) How do I get it to accept or convert the Description to HTML?

Original Script used from: Create Site Permission Groups and Add Users for SharePoint - Powershell

Sample Output Thanks

2
  • Where are you trying to add the HTML? At the Create-SPGroupInWeb part?
    – Brandon C.
    Commented Jul 3, 2014 at 13:18
  • Yes: e.g. Create-SPGroupInWeb -url "abc.com" -groupName "Group 1" -permissionLevel "Read" -description "This is my description with - <STRONG><U>My HTML Code</U></STRONG>"
    – RaveWolf
    Commented Jul 3, 2014 at 13:27

1 Answer 1

1

If your description is $description, you can try writing it as such.

$header = "<STRONG><U>"
$footer = "</U></STRONG>"
$myHTMLDescription = $description | ConvertTo-HTML -Fragment -PreContent $header -PostContent $footer | Out-String

If that doesn't work for you, take a look at these two links:

https://stackoverflow.com/questions/4950645/convertto-html-outputting-pre-post-content-showing-up-as-system-string-instead

http://technet.microsoft.com/en-us/library/hh849944.aspx

5
  • Yeah, of course! :)
    – Brandon C.
    Commented Jul 3, 2014 at 13:39
  • Thanks, but no luck. It doesn't swear at me so the script does whatever the script does without error, but doesn't do what I want it to do. :/ I added an Image (need to open in new tab).
    – RaveWolf
    Commented Jul 4, 2014 at 9:27
  • You could try taking a look here: msdn.microsoft.com/en-us/library/… Although, I don't know if you want to edit the .aspx page
    – Brandon C.
    Commented Jul 4, 2014 at 9:39
  • OR you could try to write it as $myDescription = SPEncode.HtmlEncode($description) if that works for you.
    – Brandon C.
    Commented Jul 4, 2014 at 9:44
  • Still no luck. Decided to scrap that Idea for now, but will keep trying to find a solution. There might some stupid SP setting other than security that's preventing me from changing it. Thanks again for your Help. I will continue to update this post for future reference and knowledge sharing.
    – RaveWolf
    Commented Jul 7, 2014 at 11:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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