上帝大脸 发表于 2018-9-1 13:16:43

PowerShell 发送美观的Vsphere DataStore警报

#修改颜色块的设定  
Function Set-CellColor
  
{
  
   
  
    Param (
  
      
  
      $Property,
  
      
  
      $Color,
  
      
  
      ]$InputObject,
  
      
  
      $Filter,
  
      $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 {
  
                  $Filter = ::Create($Filter)
  
                }
  
                Catch {
  
                  Write-Warning "$(Get-Date): ""$Filter"" caused an error, stopping script!"
  
                  Write-Warning $Error
  
                  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.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.Value -as
  
                If (-not $Value)
  
                {   $Value = $Search.Matches[$Index].Groups.Value
  
                }
  
                If (Invoke-Command $Filter)
  
                {   If ($Row)
  
                  {   Write-Verbose "$(Get-Date): Criteria met!Changing row to $Color..."
  
                        If ($Line -match "")
  
                        {   $Line = $Line -replace "
页: [1]
查看完整版本: PowerShell 发送美观的Vsphere DataStore警报