TUTOS.EU

Lister les applications et serveurs d'une ferme Citrix

Lister les serveurs et les applications d'une ferme Citrix PS 4.5 en VbScript

'Extraction de données d'une ferme Citrix en VBscript
'Version du 21 avril 2014

Sub DetectExeType()
	'Version du 10 juillet 2008

	Dim ScriptHost
	Dim ShellObject

	Dim CurrentPathExt
	Dim EnvObject

	Dim RegCScript
	Dim RegPopupType ' This is used to set the pop-up box flags.
											' I couldn't find the pre-defined names
	RegPopupType = 32 + 4

	On Error Resume Next

	ScriptHost = WScript.FullName
	ScriptHost = Right(ScriptHost, Len(ScriptHost) - InStrRev(ScriptHost, "\"))

	If (UCase(ScriptHost) = "WSCRIPT.EXE") Then
		WScript.Echo ("This script does not work with WScript.")

		' Create a pop-up box and ask if they want to register cscript as the default host.
		Set ShellObject = WScript.CreateObject("WScript.Shell")
		' -1 is the time to wait.  0 means wait forever.
		RegCScript = ShellObject.PopUp("Would you like to register CScript as your default host for VBscript?", 0, "Register CScript", RegPopupType)
		                                                    
		If (Err.Number <> 0) Then
			ReportError ()
			WScript.Echo "To run this script using CScript, type: ""CScript.exe " & WScript.ScriptName & """"
			WScript.Quit (GENERAL_FAILURE)
			WScript.Quit (Err.Number)
		End If

		' Check to see if the user pressed yes or no.  Yes is 6, no is 7
		If (RegCScript = 6) Then
			ShellObject.RegWrite "HKEY_CLASSES_ROOT\VBSFile\Shell\Open\Command\", "%WINDIR%\System32\CScript.exe //nologo ""%1"" %*", "REG_EXPAND_SZ"
			ShellObject.RegWrite "HKEY_LOCAL_MACHINE\SOFTWARE\Classes\VBSFile\Shell\Open\Command\", "%WINDIR%\System32\CScript.exe //nologo ""%1"" %*", "REG_EXPAND_SZ"
			' Check if PathExt already existed
			CurrentPathExt = ShellObject.RegRead("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\PATHEXT")
			If Err.Number = &H80070002 Then
				Err.Clear
				Set EnvObject = ShellObject.Environment("PROCESS")
				CurrentPathExt = EnvObject.Item("PATHEXT")
			End If

			ShellObject.RegWrite "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\PATHEXT", CurrentPathExt & ";.VBS", "REG_SZ"

			If (Err.Number <> 0) Then
				ReportError ()
				WScript.Echo "Error Trying to write the registry settings!"
				WScript.Quit (Err.Number)
			Else
				WScript.Echo "Successfully registered CScript"
			End If
		Else
			WScript.Echo "To run this script type: ""CScript.Exe adsutil.vbs <cmd> <params>"""
		End If

		Dim ProcString
		Dim ArgIndex
		Dim ArgObj
		Dim Result

		ProcString = "Cscript //nologo " & WScript.ScriptFullName

		Set ArgObj = WScript.Arguments

		For ArgIndex = 0 To ArgCount - 1
				ProcString = ProcString & " " & Args(ArgIndex)
		Next

		'Now, run the original executable under CScript.exe
		Result = ShellObject.Run(ProcString, 0, True)

		WScript.Quit (Result)
	End If

End Sub

'****************************************************************************
'
'pubAppRpt.vbs
'
'Description: Write to the cmd session a list of all published apps and the
'             users and groups assigned to them.
'
'Usage:       e.g. >cscript pubAppRpt.vbs
'
'****************************************************************************

Call DetectExeType()

Dim mfFarm
Dim mfApp
Dim mfGrp
Dim mfUsr

Set mfFarm = CreateObject("MetaFrameCOM.MetaFrameFarm")

if Err.Number <> 0 Then
	WScript.Echo "Can't create MetaFrameFarm object"
	WScript.Echo "(" & Err.Number & ") " & Err.Description
	WScript.Quit Err.Number
End if


mfFarm.Initialize 1
'mfFarm.Initialize(MetaFrameWinFarmObject)
if Err.Number <> 0 Then
	Wscript.Echo "Can't Initialize MetaFrameFarm object"
	Wscript.Echo "(" & Err.Number & ") " & Err.Description
	WScript.Quit Err.Number
End if

If mfFarm.WinFarmObject.IsCitrixAdministrator = 0 then
          Wscript.Echo "You must be a Citrix admin to run this script"
          WScript.Quit 0
End If

WScript.Echo "MetaFrame Farm Name: " & mfFarm.FarmName

Set Servers = mfFarm.Servers
WScript.Echo Servers.Count & " Server(s) in the farm (" & Now & ")"
WScript.Echo vbcrlf & "------------------------------------------------"

For Each aServer In mfFarm.Servers
	if Err.Number <> 0 Then
			  WScript.Echo "Can't enumerate servers"
			  WScript.Echo "(" & Err.Number & ") " & Err.Description
			  WScript.Echo ""
			  WScript.Quit Err.Number
	End if
	
	WScript.Echo "Name " & vbTab & aServer.ServerName
	WScript.Echo vbTab & "IP Address " & vbTab & aServer.IPAddress

	Set aWinServer = aServer.WinServerObject
	WScript.Echo vbTab & "Windows Version " & vbTab & aWinServer.WinNTVerMajor & "." & aWinServer.WinNTVerMinor
	WScript.Echo vbTab & "PS Version " & vbTab & aWinServer.MFWinVerMajor & "." &  aWinServer.MFWinVerMinor
	WScript.Echo vbTab & "PS Service Pack " & vbTab & aWinServer.MFWinServicePack
	WScript.Echo vbTab & "Product Version (Ent, Adv or Std) " & vbTab & aWinServer.MFWinName
	WScript.Echo vbTab & "PS Build " & vbTab & aWinServer.MFWinBuild
	WScript.Echo vbTab & "Logons Enabled (1=Yes) " & vbTab & aWinServer.EnableLogon
	WScript.Echo vbTab & "Shadow Logging Enabled (1=Yes) " & vbTab & aWinServer.EnableShadowLogging	
	WScript.Echo vbTab & "Use Farm ICA Display Settings (1=Yes) " & vbTab & aWinServer.UseFarmICADisplaySettings
	WScript.Echo vbTab & "Discard Redundant Graphics (1=Yes) " & vbTab & aWinServer.NoRedundantGraphics
	WScript.Echo vbTab & "Alternate Caching Method Enabled (1=Yes) " & vbTab & aWinServer.AlternateCachingMethod
	WScript.Echo vbTab & "Use LEGACY ICA Display Compatability Mode (1=Yes) " & vbTab & aWinServer.LegacyICADisplayCompatibleMode
	WScript.Echo vbTab & "ICA Video Buffer Size (bytes) " & vbTab & aWinServer.ICAVideoBufferSize
	WScript.Echo vbTab & "Degradation Bias (1=Res,2=Color): " & aWinServer.DegradationBias
	WScript.Echo vbTab & "Notify Degradation (1=Yes) " & vbTab & aWinServer.NotifyDegradation
	WScript.Echo vbTab & "Use Farm SNMP Settings (1=Yes) " & vbTab & aWinServer.UseFarmSNMPSettings
	WScript.Echo vbTab & "SNMP Agent Enabled (1=Yes) " & vbTab & aWinServer.EnableSNMPAgent
	WScript.Echo vbTab & "Data Collector Responds to ICA Broadcasts (1=Yes) " & vbTab & aWinServer.RespondToClientBroadcast
			  
	Set aWinServer = Nothing


	Set bWinServer = aServer.WinServerObject2
	WScript.Echo vbTab & "Feature Release Level " & vbTab & bWinServer.FeatureReleaseLevel
	WScript.Echo vbTab & "Console Shadowing Allowed (1=Yes) " & vbTab & bWinServer.IsShadowingConsoleAllowed
	WScript.Echo ""

	WScript.Echo vbTab & "# Installed Hotfixes on " & aServer.ServerName & " : " & vbTab & bWinServer.HotfixCount
	If bWinServer.HotfixCount <> 0 Then
	'If bWinServer.HotfixCount = 0 Then
		nHotfixes = bWinServer.HotfixCount
		aHotfixes = bWinServer.Hotfixes

		'HFList = vbTab & "Hotfix Name" & vbTab & "Installed date" & vbTab & "Installed by"
		WScript.Echo vbTab & "Hotfix Name" & vbTab & "Installed date" & vbTab & "Installed by"
		For iCount = 0 To (nHotfixes - 1)
		Set aHotfix = aHotfixes(iCount)
		Set Datein = aHotfix.InstalledOn
			If iCount = 0 Then
				'WScript.Echo anServer.ServerName 
			End If
			WScript.Echo vbTab & aHotfix.Name & vbTab & Datein.Day & "/" & Datein.Month & "/" & Datein.Year & vbTab & aHotfix.InstalledBy
			'WScript.Echo vbTab & "Hotfix name : " & vbTab & aHotfix.Name
			'WScript.Echo vbTab & "Installed date : " & vbTab & Datein.Day & "/" & Datein.Month & "/" & Datein.Year
			'WScript.Echo vbTab & "Installed by : " & vbTab & aHotfix.InstalledBy
		Next
		'WScript.Echo HFList

	End If
	Set bWinServer = Nothing

Next

Set Servers = Nothing

WScript.Echo ""
WScript.Echo ""

WScript.Echo "Published Applications : "
For Each mfApp In mfFarm.Applications

	mfApp.LoadData 1
	WScript.Echo vbTab & mfApp.Appname

	If mfApp.AppType = 17 Then 		
		Set appContentObj=mfApp.ContentObject
		WScript.Echo vbTab & vbTab & mfApp.DistinguishedName & vbTab & mfApp.AppName & vbTab & mfApp.FarmName & vbTab & appContentObj.Contentaddress
		WScript.Echo vbTab & vbTab & "This is Content, usually an internal shortcut, and just gets passed to the client. Does not run on a Citrix server"
	Else
		Set aWinApp = mfApp.WinAppObject
		WScript.Echo vbTab & vbTab & "DistinguishedName" & vbTab & mfApp.DistinguishedName
		WScript.Echo vbTab & vbTab & "AppName" & vbTab & mfApp.AppName
		WScript.Echo vbTab & vbTab & "FarmName" & vbTab & mfApp.FarmName

		If aWinApp.PNAttributes = 8 Then
			WScript.Echo vbTab & vbTab & "Published Desktop"
		Else
			WScript.Echo vbTab & vbTab & "DefaultInitProg : " & vbTab & aWinApp.DefaultInitProg
			WScript.Echo vbTab & vbTab & "DefaultWorkDir : " & vbTab & aWinApp.DefaultWorkDir
		End if

		Set aWinApp = Nothing
		WScript.Echo ""									
	End if

	WScript.Echo vbTab & vbTab & "Groups"
	For Each mfGrp In mfApp.Groups
		WScript.Echo vbTab & vbTab & vbTab & mfGrp.GroupName
	Next
	WScript.Echo vbTab & vbTab & "Users"
	For Each mfUsr In mfApp.Users
		WScript.Echo vbTab & vbTab & vbTab & mfUsr.UserName
	Next
	WScript.Echo ""

Next

Set mfFarm = Nothing
Lien vers le fichier : cliquez ici Copier le code

2