Function not working on Powershell v1


hi all,

i found great function online change colour of html table cell based on value. works great when testing (powershell v2) however our prod servers running powershell v1 , fails becasue doesnt recognise parameters syntax.

any suggestions?

[cmdletbinding()]      param (          [parameter(mandatory,position=0)]          [string]$property,          [parameter(mandatory,position=1)]          [string]$color,          [parameter(mandatory,valuefrompipeline)]          [object[]]$inputobject,          [parameter(mandatory)]          [string]$filter      )            begin {          write-verbose "$(get-date): function set-cellcolor begins"          if ($filter)          {   if ($filter.toupper().indexof($property.toupper()) -ge 0)              {   $filter = $filter.toupper().replace($property.toupper(),"`$value")                  try {                      [scriptblock]$filter = [scriptblock]::create($filter)                  }                  catch {                      write-warning "$(get-date): ""$filter"" caused error, stopping script!"                      write-warning $error[0]                      exit                  }              }              else              {   write-warning "could not locate $property in filter, required.  filter: $filter"                  exit              }          }      }            process {          foreach ($line in $inputobject)          {   if ($line.indexof("<tr><th") -ge 0)              {   write-verbose "$(get-date): processing headers..."                  $search = $line | select-string -pattern '<th ?[a-z\-:;"=]*>(.*?)<\/th>' -allmatches                  $index = 0                  foreach ($match in $search.matches)                  {   if ($match.groups[1].value -eq $property)                      {   break                      }                      $index ++                  }                  if ($index -eq $search.matches.count)                  {   write-warning "$(get-date): unable locate property: $property in table header"                      exit                  }                  write-verbose "$(get-date): $property column found @ index: $index"              }              if ($line.indexof("<tr><td") -ge 0)              {   $search = $line | select-string -pattern '<td ?[a-z\-:;"=]*>(.*?)<\/td>' -allmatches                  $value = $search.matches[$index].groups[1].value -as [double]                  if (-not $value)                  {   $value = $search.matches[$index].groups[1].value                  }                  if (invoke-command $filter)                  {   write-verbose "$(get-date): criteria met!  changing cell $color..."                      $line = $line.replace($search.matches[$index].value,"<td style=""background-color:$color"">$value</td>")                  }              }              write-output $line          }      }            end {          write-verbose "$(get-date): function set-cellcolor completed"      }  }

advanced functions weren't added until powershell 2.0, right?  of function wouldn't work in 1.0.



Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

2008 Windows Deployment Server Properties Error

Can no longer user MS Update - Files required to use Microsoft Update are no longer registered

How do a find data in one file, search for it in another file and if not found, write a custom message to another file