달력

10

« 2013/10 »

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
2013. 10. 23. 11:31

VBS로 PowerShell 스크립트 실행 Etc.2013. 10. 23. 11:31

가상화 관련 프로젝트를 진행하다 보니 VBS로 PowerShell 스크립트를 실행해야 하는 경우가 생깁니다. SCOM의 경우 Discovery는 Authoring Console을 통해 PowerShell 기반의 Discovery가 가능하나 정작 운영 콘솔 상에서 모니터링 항목을 만들 때는 PowerShell 스크립트를 지원하지 않아 PowerShell 명령으로 모니터링을 하기가 쉽지 않습니다.

물론, Authoring Console을 이용하면 되지만 매우 복잡한 단계를 거쳐야 하기 때문에 간단하게 VBS 스크립트 안에서 PowerShell 스크립트를 실행하거나, 출력된 결과에 기반해 모니터링을 수행할 수 있습니다.


단순 실행 - 출력된 결과에 대한 작업이 필요 없는 경우
(예: 실패한 클러스터 리소스 시작)
PS = "powershell.exe -nologo -command "&Chr(34)&"Get-ClusterResource | Where {$_.State -eq 'Failed'} | Start-ClusterResource"&Chr(34)
 
Set Shell = CreateObject("WScript.Shell")
Shell.Run PS,0,True



결과 반환 - 반환된 결과에 대한 가공 또는 분석이 필요한 경우
PS = "powershell.exe -nologo -command "&chr(34)&"Get-Service | Where {$_.Status -eq 'Stopped'}"&chr(34)

Set Shell = WScript.CreateObject( "WScript.Shell" )
Set Exec = Shell.Exec(PS)
Exec.StdIn.Close()
 
Do While Exec.StdOut.AtEndOfStream <> True
  PSOutput =  Exec.StdOut.ReadLine
  
  <PSOutput 작업>
  
Loop



:
Posted by 커널64
VBS VB 스크립트 기반 SCOM 모니터 - 장애 조치 클러스터의 실패한 클러스터 리소스 그룹 모니터링


'==========================================================
'Normal State: Property[@Name='State'] equals Normal
'Error State: Property[@Name='State'] equals Critical
'Alert Message: $Data/Context/Property[@Name='Message']$
'==========================================================

On Error Resume Next

Set oAPI = CreateObject("MOM.ScriptAPI")
Set oBag = oAPI.CreatePropertyBag()

Set wshShell = WScript.CreateObject( "WScript.Shell" )

strHostName = wshShell.ExpandEnvironmentStrings( "%COMPUTERNAME%" )
Set wshShell = Nothing

Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\mscluster")
Set colItems = objWMIService.ExecQuery("Select * from MSCluster_ResourceGroup Where OwnerNode = '"&strHostName&"' And State = 2")

strFailedRes = ""
If colItems.Count <> 0 Then
  For each Item in colItems
    strFailedRes = strFailedRes & Item.Name & ", "
    Call oBag.AddValue("Failed Resource", Item.Name)
  Next
  Call oBag.AddValue("State", "Critical")
  If colItems.Count = 1 Then
    Call oBag.AddValue("Message", "There is a Failed Cluster Resource. '"&Left(strFailedRes,Len(strFailedRes)-2)&"'")
  Else
    Call oBag.AddValue("Message", "There are Failed Cluster Resources. '"&Left(strFailedRes,Len(strFailedRes)-2)&"'")
  End If
Else
  Call oBag.AddValue("State", "Normal")
  Call oBag.AddValue("Message", "There is no Failed Cluster Resource.")
End If

Set colItems = Nothing
Set objWMIService = Nothing

Call oAPI.Return(oBag)
Set oBag = Nothing 
Set oAPI = Nothing


 
:
Posted by 커널64