Option Explicit '------------------------------------------------------------------------- ' Runonpassivenode.1.1.vbs ' ' Beschreibung ' Skript sucht den passenden Knoten für das Exchange VSS Backup ' Optional wird eine Kommandozeile remote ausgeführt ' Es wird nicht auf den Abschluss des entfernten Jobs gewartet ' Laufzeitfehler werde nicht abgefangen und beenden das Skript. ' ' Das Skript wird mit den Berechtigungen des angemeldeten Benutzers ' ausgeführt. Die entsprechenden Berechtigungen sind sicher zu stellen ' ' (c)2004 Net at Work Netzwerksysteme GmbH ' ' Version 1.0 (28. Mrz 2008) ' ' Failover Cluster Automation Server Reference ' http://msdn2.microsoft.com/en-us/library/aa369077(VS.85).aspx ' ' WMI - start a process on remote machine and passing custom credentials. ' http://weblogs.asp.net/steveschofield/archive/2006/06/06/WMI---start-a-process-on-remote-machine-passing-credentials_2E00_.aspx ' http://msdn.microsoft.com/en-us/library/aa394599.aspx ' http://msdn.microsoft.com/en-us/library/aa394375(VS.85).aspx Win32_ProcessStartup Class '------------------------------------------------------------------------- const ExClusterName = "EXCLUSTER" const strDefaultRemoteCommand = "" 'const strDefaultRemoteCommand = "c:\WINDOWS\NOTEPAD.EXE" WScript.Echo "RunonpassiveNode: Startet with ExClusternmae=" & ExClusterName dim strRemoteCommand if wscript.arguments.count >0 then strRemoteCommand = wscript.arguments(0) WScript.Echo "RunonpassiveNode: RemoteCommand (Commandline) =" & strRemoteCommand else strRemoteCommand = strDefaultRemoteCommand WScript.Echo "RunonpassiveNode: RemoteCommand (defaultconfig) =" & strRemoteCommand end if WScript.Echo "RunonpassiveNode: Startet with ExClusternmae=" & ExClusterName Dim objCluster Set objCluster = CreateObject("MSCluster.Cluster") WScript.Echo "RunonpassiveNode: Connect to local cluster service" objCluster.Open("") WScript.Echo "RunonpassiveNode: Local Cluster object successful opened" dim strExNode strExNode = objCluster.ResourceGroups.Item(ExClusterName).OwnerNode.Name WScript.Echo "RunonpassiveNode: Active Exchange Node:" & strExNode if objCluster.Nodes.count <> 2 then WScript.Echo "RunonpassiveNode: Error: Anzahl der Knoten <>2: " & objCluster.Nodes.count wscript.quit(255) else WScript.Echo "RunonpassiveNode: Anzahl der Knoten: " & objCluster.Nodes.count dim node, strNodeName, strPassiveNode strPassiveNode = strExNode for each node in objCluster.Nodes 'sonst item(xx) strNodeName = node.name select case node.state case 0 wscript.echo "RunonpassiveNode: Node:" & strNodeName & " State: uP" case 1 wscript.echo "RunonpassiveNode: Node:" & strNodeName & " State: DOWN" case 2 wscript.echo "RunonpassiveNode: Node:" & strNodeName & " State: PAUSED" case 3 wscript.echo "RunonpassiveNode: Node:" & strNodeName & " State: JOINING" case -1 wscript.echo "RunonpassiveNode: Node:" & strNodeName & " State: unknown" Case Else wscript.echo "RunonpassiveNode: Node:" & strNodeName & " State: ERRROR. State=" & node.state end select if (node.state = 0) and (strNodeName <> strExNode) then strPassiveNode = strNodeName end if next end if if strPassiveNode <> strExNode then wscript.echo "RunonpassiveNode: Selected Node (Passive):" & strPassiveNode else wscript.echo "RunonpassiveNode: Selected Node (Active) :" & strPassiveNode end if if strRemoteCommand <> "" then dim WMIResult, intProcessID, objProcess, objProcessStart , objConfig wscript.echo "RunonpassiveNode: Starting Backup on:" & strPassiveNode ' Set objProcess = GetObject("winmgmts:\\" & strPassiveNode & "\root\cimv2:Win32_Process") Set objProcessStart = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strPassiveNode & "\root\cimv2:Win32_ProcessStartup") Set objConfig = objStartup.SpawnInstance_ objConfig.ShowWindow = 0 ' HIDDEN_WINDOW Set objProcess = GetObject("winmgmts:root\cimv2:Win32_Process") WMIResult = objProcess.Create(Chr(34) & strRemoteCommand & Chr(34),null,objConfig,intProcessID) If WMIResult = 0 Then Wscript.Echo "RunonpassiveNode: Backup startet. ProcessID:" & intProcessID Else Wscript.Echo "RunonpassiveNode: Backup NICHT gestartet. Error:" & WMIResult End If else WScript.Echo "RunonpassiveNode: Kein Kommando angegeben" end if WScript.Echo "RunonpassiveNode: Free Ressouces" Set objCluster = Nothing WScript.Echo "RunonpassiveNode: Ende"