|
#修改颜色块的设定
Function Set-CellColor
{
[CmdletBinding()]
Param (
[Parameter(Mandatory,Position=0)]
[string]$Property,
[Parameter(Mandatory,Position=1)]
[string]$Color,
[Parameter(Mandatory,ValueFromPipeline)]
[Object[]]$InputObject,
[Parameter(Mandatory)]
[string]$Filter,
[switch]$Row
)
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 an error, stopping script!"
Write-Warning $Error[0]
Exit
}
}
Else
{ Write-Warning "Could not locate $Property in the Filter, which is required. Filter: $Filter"
Exit
}
}
}
Process {
ForEach ($Line in $InputObject)
{ If ($Line.IndexOf("(.*?)' -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 to locate property: $Property in table header"
Exit
}
Write-Verbose "$(Get-Date): $Property column found at index: $Index"
}
If ($Line -match "(.*?)' -AllMatches
$Value = $Search.Matches[$Index].Groups[1].Value -as [double]
If (-not $Value)
{ $Value = $Search.Matches[$Index].Groups[1].Value
}
If (Invoke-Command $Filter)
{ If ($Row)
{ Write-Verbose "$(Get-Date): Criteria met! Changing row to $Color..."
If ($Line -match "")
{ $Line = $Line -replace " |
|
|