首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Powershell // CSV-前端输出

Powershell // CSV-前端输出
EN

Stack Overflow用户
提问于 2016-03-17 14:47:53
回答 1查看 170关注 0票数 1

我正在使用SCOM (SystemCenterOperationsManager),并为一个预定的任务编写了一个小脚本。

它应该收集所有的NEW ( ResolutionState = 0 )警报并使用我的通配符规则过滤它们。

它将将所有收集到的警报的解析状态更改为特定的解析状态。

我的问题:

要获得所有选择的警报的报告,我想要生成一个“文件外”,我应该把它放在哪里?

这是我的代码:

代码语言:javascript
复制
if ($LastHourAlerts)
{
   foreach($Alert in $LastHourAlerts)
   {      
   $newState = $null

   switch -wildcard ($Alert.Name) 
      {
      "Operations Manager failed to start a process" { $newState = 255 } 
      "Operations Manager failed to check the state of a service" { $newState = 255 }
      "Operations Manager failed to run a WMI query" { $newstate =255 }
      "Interface Utilization Alert" { $newState = 15 }
      "Veeam VMware: Datastore Provisioning Analysis" { $newState = 17 }
      "Veeam VMware Collector: VMware connection data processing errors" { $newState = 17 }
      "Veeam VMware Collector: VMware connection is unavailable" { $newState = 17 }
      "Veeam VMware: Virtual Machine Memory Usage Analysis" { $newState = 17 }
      "Veeam VMware: Virtual Machine CPU Usage Analysis" { $newState = 17 }
      "Veeam VMware: Virtual Machine Memory Ballooning and Swapping Analysis" { $newState = 17 }
      "Veeam VMware: Virtual Machine Storage Latency Analysis" { $newState = 17 }
      "Veeam VMware: Virtual Machine Consolidation Needed status Alarm" { $newState = 17 }
      "Veeam VMware: Maintenance Mode Tracker" { $newState = 17 }
      "Veeam VMware: vSphere Host Storage Commands Failed Analysis" { $newState = 17 }
      "Veeam VMware: vSphere Host Network Packet Loss Analysis" { $newState = 17 }
      "Veeam VMware: vSphere Host Memory Swapping Analysis" { $newState = 17 }
      "Veeam VMware: vSphere Host Memory Usage Analysis" { $newState = 17 }
      "Veeam VMware: vSphere Host Kernel Latency Analysis" { $newState = 17 }
      "Veeam VMware: vSphere Cluster Memory Overcommit Analysis" { $newState = 17 }
      "Veeam VMware: VM customization failed" { $newState = 17 }

      }


      if($newState -ne $null)
         {
         $Alert.ResolutionState = $newState
         $Alert.Update(“Resolution State changed automatically by Automation”)              
         }
     }    
}

在if循环的末尾,我看到了这样的东西:

代码语言:javascript
复制
$Alert.Name | Out-File ("$path\" + "Report.csv") -Append

虽然它采用了名称,但只在所有处理过的警报数量中写入第一个告警对象的名称。例如:

5个不同的警报:

代码语言:javascript
复制
Operations Manager failed to start a process
Interface Utilization Alert
Veeam VMware: VM customization failed
Veeam VMware: Virtual Machine CPU Usage Analysis
Veeam VMware Collector: VMware connection is unavailable

这是在.csv中的:

代码语言:javascript
复制
Operations Manager failed to start a process
Operations Manager failed to start a process
Operations Manager failed to start a process
Operations Manager failed to start a process
Operations Manager failed to start a process

有更好的方法来获得数据输出吗?而且,我不仅想要$Alert.Name,而且想要$Alert.Name, $Alert.TimeRaised, $ResolutionState

EN

回答 1

Stack Overflow用户

发布于 2016-03-17 15:42:43

把这样的东西放在循环的末尾:

代码语言:javascript
复制
if ($Alert.ResolutionState -eq 0) {
  $Alert.Name | Out-File 'C:\path\to\your.txt' -Append
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36063971

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档