I know it's trivial to use colours in scripting, but it does help if you have tons of outputs. I have the following script and would like to change the colour of the output depending on the result.
I added line numbers for easy navigation...
1 function Add-Group2Folder
2 {
3 param ($Url, $sourceFolder, $GroupName, $PermissionLevel)
4 try{
5 $web = Get-SPWeb -Identity $Url
6
7 if($web -ne $null){
8 # $sourceFolderGets the folder that is located at the specified URL.
9 $folder = $web.GetFolder($sourceFolder)
10 try{
11 $group = $web.SiteGroups[$GroupName]
12 $roleAssignment = new-object Microsoft.SharePoint.SPRoleAssignment($group)
13 $roleDefinition = $web.RoleDefinitions[$PermissionLevel];
14 $roleAssignment.RoleDefinitionBindings.Add($roleDefinition);
15
16 # apply the new roleassignment to the folder.
17 $folder.Item.RoleAssignments.Add($roleAssignment);
18 write-host -f green "Group ""$GroupName"" Successfully Added to ""$Url$sourceFolder"""
19
20 $folder.Item.Update();
21 $web.Dispose()
22 }
23 catch [System.Exception]
24 {
25 write-host -f red "Folder ""$folder"" not found."
26 }
27 }
28 }
29 catch [System.Exception]
30 {
31 write-host -f red $_.Exception.ToString()
32 }
33 write-host -f magenta "DONE!"
34 }
Lines 18 and 25 do not give the relevant colour output.
I added the last line (33) (Not required) just for testing purposes and it works fine...
Any advice? TIA