The following examples are sample scripts that you can use with your multicast transmissions. To use each script, copy the code to a file and then save, it using the .vbs file name extension. Then open an elevated Command Prompt window and run a command that uses the following syntax: cscript <nameoffile>.vbs <WDSServer>. For example: cscript mcinfo.vbs localhost.
In This Topic
Stop Transmissions Slower than 1 MB per Second
The following Microsoft Visual Basic script will stop the transmission of the master client for any multicast session that has been transmitting data at a rate slower then 1 MB per second for longer than 60 seconds. You can configure these values by using the parameters at the top of the script. The master client is the slowest client in a transmission — that is, the client that is not capable of installing any faster while the other clients may be able to install at a faster rate. To determine the master client, view the output of the following command: WDSUTIL /Get-MulticastTransmission /Show-clients. Note that there may be as many master clients as the server has network adapters.
' -------------Times are in milliseconds sleepTime = 5000 ' Minimum time to wait between each query to the server timeThreshold = 60000 ' Minimum time to wait before kicking the master client out of a slow session ' ------------- Speeds are in KB/sec speedThreshold = 1024 ' Minimum transfer rate for a session ' ------------- Display variables displayAllSessions = true ' Display all sessions on the server, not just the slow sessions printStatusDots = true ' Print a dot every time we contact the server. Useful to show that the script is doing something ' ------------------------------- End user defined settings ------------------------------- Dim sessionDictionary, Manager, Server, hostname ' WDS Transport type definitions WdsTptDisconnectUnknown = 0 WdsTptDisconnectFallback = 1 WdsTptDisconnectAbort = 2 ' Run main main() ' ---------------------------------- main sub main if WScript.Arguments.Count < 1 then wscript.echo "[WARN]: Hostname not specified on command line, trying to connect to localhost" hostname = "localhost" else hostname = WScript.Arguments.Item(0) end if ' We use a dictionary to keep track of sessions on the server Set sessionDictionary = CreateObject("Scripting.Dictionary") ' Create the Transport Manager Set Manager = CreateObject("WdsTptMgmt.WdsTransportManager") ' Connect to the server Set Server = Manager.GetWdsTransportServer(hostname) ' Echo out current settings if displayAllSessions = false then wscript.echo "[INFO]: Not displaying information for all sessions" end if if printStatusDots then wscript.echo "[INFO]: Printing status dots" end if wscript.echo "[INFO]: Speed Threshold: " + Cstr(speedThreshold) + " KB/sec, Time Threshold: " + Cstr(Int(timeThreshold/1000)) + "s, Sleep time: " + Cstr(Int(sleepTime/1000)) + "s" wscript.echo "[INFO]: Examining sessions on " + Server.name + "..." + vbCrLf ' Loop forever. User must control C out of the script to stop execution. Do while true if printStatusDots then Wscript.StdOut.Write(".") end if loopAndKick() wscript.sleep(sleepTime) loop end sub ' ---------------------------------- loopAndKick sub loopAndKick ' Get a list of the namespaces on the server Set NamespaceCollection = Server.NamespaceManager.RetrieveNamespaces("", "", False) ' Get all namespaces present on the server for i = 1 to CLng(NamespaceCollection.count) Set ns = NamespaceCollection.Item(i) ' Get all contents for this namespace Set ContentCollection = NamespaceCollection.Item(i).RetrieveContents() for j = 1 to CLng(ContentCollection.count) Set content = ContentCollection.item(j) ' Get all sessions for this content Set SessionCollection = content.RetrieveSessions() for k = 1 to CLng(SessionCollection.count) Set session = SessionCollection.item(k) Set ClientCollection = session.RetrieveClients() 'Calculate the transfer rate, in KB/sec, for this session tRate = CLng(session.TransferRate) tRate = Int(tRate / 1024) ' Echo this session out to the screen if displayAllSessions then wscript.echo ns.name + content.name + ", Num clients: " + CStr(ClientCollection.count) + ", " + CStr(tRate) + " kB/sec" end if ' If the session ID already exists in the dictionary, but no clients are connected, remove the entry from the dictionary if ( (CLng(ClientCollection.count) = 0) AND sessionDictionary.Exists( CLng(session.ID)) ) then wscript.echo vbTab + "Remove: " + Cstr(session.ID) sessionDictionary.Remove(CLng(session.ID)) ' If the session ID exists in the dictionary, update the session details, and kick the master client if needed elseif sessionDictionary.Exists( CLng(session.ID) ) then ' Retrieve and update timeSlow timeSlow = sessionDictionary.Item( CLng(session.ID) ) timeSlow = timeSlow + sleepTime ' If we've gone too slow for too long, kick the current master client if ( (tRate < speedThreshold) AND (timeSlow > timeThreshold) ) then ' Make sure we have a valid master client ID before we attempt to kick if Clng(session.MasterClientId) <> 0 then wscript.echo vbTab + "Kicking client: " + Cstr(session.MasterClientId) Server.DisconnectClient session.MasterClientId, WdsTptDisconnectFallback ' Reset time slow for this session timeSlow = 0 end if end if ' Remove the old entry from the dictionary sessionDictionary.Remove(CLng(session.ID)) ' If the session is still too slow, add it back to the dictionary with the new time value if( tRate < speedThreshold) then wscript.echo vbTab + "Update: " + Cstr(session.ID) + ", Time slow: " + Cstr(Int(timeSlow/1000)) + "s" sessionDictionary.Add CLng(session.ID), timeSlow Otherwise, we've removed the session from the dictionary above else wscript.echo vbTab + "Remove: " + Cstr(session.ID) end if ' The session isn't in the dictionary. If the session is going too slow and has clients connected, add it to the dictionary else if( (tRate < speedThreshold) AND (CLng(ClientCollection.count) <> 0) ) then wscript.echo vbTab + "Add: " + Cstr(session.ID) sessionDictionary.Add CLng(session.ID), 0 end if end if next next next end sub
Display Performance Information About Clients
The following Visual Basic script displays performance information for all clients in all transmissions that are connected to the same server.
' Create the Tranport Manager Set Manager = CreateObject("WdsTptMgmt.WdsTransportManager") if WScript.Arguments.Count = 0 then wscript.echo "INFO: Specify a host name on the command line to connect to a remote host" & vbCrLf Set Server = Manager.GetWdsTransportServer("localhost") else Set Server = Manager.GetWdsTransportServer(WScript.Arguments.Item(0)) end if ' Print Server name wscript.echo "Server: " + Server.name ' Get a list of the namespaces on the server Set NamespaceCollection = Server.NamespaceManager.RetrieveNamespaces("", "", False) ' Get all namespaces present on the server for i = 1 to CLng(NamespaceCollection.count) Set ns = NamespaceCollection.Item(i) wscript.echo " Namespace ID: " + CStr(ns.id) + ", Name: " + ns.name ' Get all contents for this namespace Set ContentCollection = NamespaceCollection.Item(i).RetrieveContents() for j = 1 to CLng(ContentCollection.count) Set content = ContentCollection.item(j) wscript.echo " Content ID : " + CStr(content.id) + ", Name: " + content.name ' Get all sessions for this content Set SessionCollection = content.RetrieveSessions() for k = 1 to CLng(SessionCollection.count) Set session = SessionCollection.item(k) tRate = CLng(session.TransferRate) tRate = Int(tRate / 1024) ' Get all clients for this session Set ClientCollection = session.RetrieveClients() wscript.echo " Session ID: " + CStr(session.id) + ", NIC Name: " + session.NetworkInterfaceName &_ + ", tRate: " + CStr(tRate) + " kB/sec, clients: " + Cstr(ClientCollection.count) for l = 1 to Cint(ClientCollection.count) set client = ClientCollection.item(l) ' Determine if this client is the master client if Clng(session.MasterClientId) = Clng(client.id) then wscript.echo " * Client ID: " + CStr(client.id) + ", Name: " + client.name &_ + ", IP: " + client.IpAddress + ", MAC: " + client.MacAddress + ", Time connected: " + Cstr(client.JoinDuration) else wscript.echo " Client ID: " + CStr(client.id) + ", Name: " + client.name &_ + ", IP: " + client.IpAddress + ", MAC: " + client.MacAddress + ", Time connected: " + Cstr(client.JoinDuration) end if next next next next
The following code is example output from the preceding script:
C:\Users\administrator>cscript MCInfo.vbs localhost Microsoft (R) Windows Script Host Version 5.7 Copyright (C) Microsoft Corporation. All rights reserved. Server: wds-server.fabrikam.com Namespace ID: 2471217798, Name: WDS:Server08/install-(2).wim/1 Namespace ID: 2471217799, Name: WDS:Server08/install.wim/1 Namespace ID: 2471217807, Name: WDS:Server03/amd64.wim/1 Namespace ID: 2471217808, Name: WDS:Server03/x86.wim/1 Namespace ID: 2471217810, Name: WDS:Vista/amd64.wim/1 Namespace ID: 2471217811, Name: WDS:Vista/x86.wim/1 Namespace ID: 2471217812, Name: WDS:XP_SP2/install-(2).wim/1 Content ID : 3263057331, Name: Res.rwm Session ID: 3353296855, NIC Name: Broadcom NetXtreme Gigabit Ethernet #2, tRate: 0 kB/sec, clients: 0 Namespace ID: 2471217813, Name: WDS:XP_SP2/Install.wim/1 Content ID : 3263057330, Name: Res.rwm Session ID: 3353296854, NIC Name: Broadcom NetXtreme Gigabit Ethernet #2, tRate: 883 kB/sec, clients: 1 * Client ID: 3267943420, Name: MININT-1U7QOTT, IP: 172.30.170.162, MAC: 000E7F28D375, Time connected: 1111