Miioua
Posts: 47
Joined: 5.Jun.2007
Status: offline
|
Yes, surely : Export: quote:
'========================================================================================= Option Explicit Dim DEBUG DEBUG = true Dim Destination 'Destination="L:\ISA2004-2006" Destination="\\si0vm055\Isa2004-2006$" '===================================================================================== '################################################################################### 'MAIN - Hauptprozedur '----------------------------------------------------------------------------------- Dim boolRunAsCScript 'Checking if code is running on cscript and not wscript...ie we are printing the output to the console If (UCase(Right(WScript.FullName, 11)) <> UCase("CScript.exe")) Then WScript.Echo "Must be run under CScript" & " Example: CScript " & ScriptName & ".vbe" WScript.Echo vbTab & "Version " & SCRIPT_VERSION boolRunAsCScript = False Call EndScript Else Dim StartTime StartTime = Now() boolRunAsCScript = True Call StartScript Call GetISAellements() Call EndScript End If '################################################################################### '========================================================================================= Sub EndScript() 'Alles was beim Ende des Sripted getan werden muß - wird immer aufgerufen End Sub 'EndScript() 'Alles was beim Ende des Sripted getan werden muß - wird immer aufgerufen '============================================================================ '============================================================================ Sub StartScript() 'Alles was beim Ende des Sripted getan werden muß - wird immer aufgerufen End Sub 'StartScript() 'Alles was beim Ende des Sripted getan werden muß - wird immer aufgerufen '============================================================================ '========================================================================================= Sub GetISAellements() 'as String 'This routine will analyse all policies in the ISA Enterprise configuration 'and list all accounts defined in applies to. Additionally it will resolve all 'subtree groupmemberships for any group defined to list all user accounts that are 'affected by a policy Dim ISAEnterprise ' as FPCDS 'The ISA Dim Arr, CompuSet, Compu, Urls, ISAUrlSet , Range, entRuleElement , DomNamSets Dim USet, Account,dateLastMod,MyDate Dim FileToSave ,File, PreviousVersionExported Dim Count If (DEBUG) Then wscript.echo ("Connecting to the ISA Configuration...") Set ISAEnterprise = CreateObject ("FPC.Root") ISAEnterprise.ConnectToConfigurationStorageServer "ISAserver2004.myfirm.com" Set FileToSave = CreateObject ("Scripting.FileSystemObject") Set File= FileToSave.OpenTextFile(Destination &"\Lastexported.txt",1, true) PreviousVersionExported = File.ReadLine File.close dateLastMod = CStr(ISAEnterprise.StorageChangeNumber) If PreviousVersionExported = dateLastMod Then If (DEBUG) Then wscript.echo ("No news version: " & PreviousVersionExported ) ISAEnterprise.DisconnectFromConfigurationStorageServer wscript.Quit End If If (DEBUG) Then wscript.echo "Old Version: " & PreviousVersionExported If (DEBUG) Then wscript.echo "New Version: " & dateLastMod set entRuleElement = ISAEnterprise.Enterprise.RuleElements '############################################################################################### '# Computer '############################################################################################### wscript.echo "Computers" Set File= FileToSave.OpenTextFile(Destination &"\Computers.txt",2, true) For Each Compu In entRuleElement.Computers If (DEBUG ) Then wscript.echo " "&Compu.Name & " " & Compu.IPaddress File.WriteLine Compu.Name & ";" & Compu.Description & ";" & Compu.IPaddress Next File.close If (DEBUG ) Then wscript.echo "" '############################################################################################### '# Computers Sets '############################################################################################### wscript.echo "ComputerSet" Set File = FileToSave.OpenTextFile(Destination &"\ComputersSets.txt",2, true) For Each CompuSet In entRuleElement.ComputerSets File.WriteLine CompuSet.Name File.WriteLine ("<") For Each Compu in CompuSet.Computers If (DEBUG) Then wscript.echo " Compu " & Compu.Name & ";" & Compu.IPaddress File.WriteLine "Compu"& ";" & Compu.Name & ";" & Compu.IPaddress Next For Each Range in CompuSet.AddressRanges If (DEBUG) Then wscript.echo " Range " & range.Name & " "& Range.IP_From & " "& Range.IP_To File.WriteLine "Range" & ";" & range.Name & ";" & Range.IP_From & ";" & Range.IP_To Next File.WriteLine ">" File.WriteLine ("") Next File.close If (DEBUG ) Then wscript.echo "" '############################################################################################### '# URL Sets '############################################################################################### wscript.echo "URLSets" Set File = FileToSave.OpenTextFile(Destination &"\URLSets.txt",2, true) For Each ISAUrlSet In entRuleElement.UrlSets File.WriteLine ISAUrlSet File.WriteLine ("<") For Count=1 to ISAUrlSet.Count If (DEBUG ) Then wscript.echo " " & ISAUrlSet.Item(Count) File.WriteLine ISAUrlSet.Item(Count) Next File.WriteLine (">") File.WriteLine ("") Next File.close If (DEBUG ) Then wscript.echo "" '############################################################################################### '# Domain Name Sets '############################################################################################### wscript.echo "Domain Name Set" Set File = FileToSave.OpenTextFile(Destination &"\DomainNameSets.txt",2, true) For Each DomNamSets In entRuleElement.DomainNameSets If (DEBUG ) Then wscript.echo " DomNamSets: " & DomNamSets File.WriteLine DomNamSets File.WriteLine ("<") For Count=1 to DomNamSets.Count If (DEBUG ) Then wscript.echo " " & DomNamSets.Item(Count) File.WriteLine DomNamSets.Item(Count) Next File.WriteLine (">") File.WriteLine ("") Next File.close If (DEBUG ) Then wscript.echo "" '############################################################################################### '# Users Sets '############################################################################################### wscript.echo "User Sets" Set File = FileToSave.OpenTextFile(Destination &"\UserSets.txt",2, true) For Each USet In entRuleElement.UserSets If (DEBUG ) Then wscript.echo " USets " & USet File.WriteLine USet.Name File.WriteLine ("<") For Each Account in USet.Accounts If (DEBUG ) Then wscript.echo " " & Account.Account File.WriteLine Account.Account Next File.WriteLine ">" File.WriteLine ("") Next File.close If (DEBUG ) Then wscript.echo "" Set File= FileToSave.OpenTextFile(Destination &"\exported.txt",2, true) File.WriteLine ISAEnterprise.StorageChangeNumber File.close Set File= FileToSave.OpenTextFile(Destination &"\Lastexported.txt",2, true) File.WriteLine ISAEnterprise.StorageChangeNumber File.close End Sub 'GetISAellements() Import: quote:
'========================================================================================= Option Explicit Const ERROR_FileNotFound = &H80070002 Dim ISAEnterprise ' as FPCDS 'The ISA Dim entRuleElement Dim FileObj Dim DEBUG DEBUG = TRUE Dim Destination 'Destination="L:\ISA2004-2006" Destination="\\si0vm055\Isa2004-2006$" '===================================================================================== '################################################################################### 'MAIN - Hauptprozedur '----------------------------------------------------------------------------------- Dim boolRunAsCScript 'Checking if code is running on cscript and not wscript...ie we are printing the output to the console If (UCase(Right(WScript.FullName, 11)) <> UCase("CScript.exe")) Then WScript.Echo "Must be run under CScript" & " Example: CScript " & ScriptName & ".vbe" WScript.Echo ";" & "Version " & SCRIPT_VERSION boolRunAsCScript = False Call EndScript Else Dim StartTime StartTime = Now() boolRunAsCScript = True Call StartScript Call ISASets() Call EndScript End If '################################################################################### '========================================================================================= Sub EndScript() 'Alles was beim Ende des Sripted getan werden muß - wird immer aufgerufen End Sub 'EndScript() 'Alles was beim Ende des Sripted getan werden muß - wird immer aufgerufen '============================================================================ '============================================================================ Sub StartScript() 'Alles was beim Ende des Sripted getan werden muß - wird immer aufgerufen End Sub 'StartScript() 'Alles was beim Ende des Sripted getan werden muß - wird immer aufgerufen '============================================================================ '========================================================================================= Sub ISASets() 'as String 'This routine will analyse all policies in the ISA Enterprise configuration 'and list all accounts defined in applies to. Additionally it will resolve all 'subtree groupmemberships for any group defined to list all user accounts that are 'affected by a policy If (DEBUG= true) Then wscript.echo ("Connecting to the ISA Configuration...") Set ISAEnterprise = CreateObject ("FPC.Root") Set FileObj = CreateObject ("Scripting.FileSystemObject") wscript.echo Date & " " & Time If FileObj.FileExists(Destination &"\exported.txt")=False then If (DEBUG) Then wscript.echo ("No new Export") wscript.Quit end if ' ISAEnterprise.ConnectToConfigurationStorageServer "localhost", "User1","gix8fe.test", "cDFGpo25E" ISAEnterprise.ConnectToConfigurationStorageServer "si0vm055" set entRuleElement = ISAEnterprise.Enterprise.RuleElements CompuSets UrlSets UserSets DomainNameSets FileObj.DeleteFile(Destination &"\exported.txt") End Sub 'ISASets() Sub CompuSets() '############################################################################################### '# ComputerSets '############################################################################################### Dim File, tmp, Splited Dim ComputerSets, ComputerSet, Computers ,Ranges Dim Count Set File= FileObj.OpenTextFile("ComputersSets.txt") 'On Error Resume Next Do While File.AtEndOfStream <> true tmp = File.ReadLine If tmp <>"" Then Splited= split(tmp, ";") wscript.echo "ComputerSet found: "& Splited(0) On Error Resume Next Set ComputerSet = entRuleElement.ComputerSets(Splited(0)) If Err.Number=ERROR_FileNotFound Then err.Clear Wscript.echo "New Computer Sets: " & Splited(0) Set ComputerSet = entRuleElement.ComputerSets.add(Splited(0)) End If On Error GoTo 0 tmp = File.ReadLine Set computers = computerSet.Computers Set Ranges= computerSet.AddressRanges On Error Resume Next do While tmp <> ">" If tmp <> "<" Then If split(tmp,";")(0) = "Compu" Then wscript.echo " Add Computer: " & split(tmp,";")(1) &";" & split(tmp,";")(2) computers.Add split(tmp,";")(1) , split(tmp,";")(2) ElseIf split(tmp,";")(0) = "Range" Then wscript.echo " Add Range: " & split(tmp,";")(1) &" " & split(tmp,";")(2)&" " & split(tmp,";")(3) Ranges.Add split(tmp,";")(1) , split(tmp,";")(2), split(tmp,";")(3) End If End If tmp = File.ReadLine loop On Error GoTo 0 ComputerSet.save End If loop End Sub 'CompuSets() Sub UrlSets() '############################################################################################### '# UrlSets '############################################################################################### Dim File, tmp, Splited Dim URLSets, UrlSet Dim Count Set File= FileObj.OpenTextFile("URLSets.txt") 'On Error Resume Next Do While File.AtEndOfStream <> true tmp = File.ReadLine If tmp <>"" Then Splited= split(tmp, ";") wscript.echo "URLSet found in File: "& Splited(0) On Error Resume Next Set UrlSet = entRuleElement.UrlSets(Splited(0)) If Err.Number=ERROR_FileNotFound Then err.Clear Wscript.echo "New URLSets: " & Splited(0) Set UrlSet = entRuleElement.UrlSets.add(Splited(0)) End If On Error GoTo 0 tmp = File.ReadLine On Error Resume Next Do While tmp <> ">" If tmp <> "<" Then wscript.echo " Add URL: " & split(tmp,";")(0) UrlSet.Add split(tmp,";")(0) End If tmp = File.ReadLine loop On Error GoTo 0 UrlSet.save End If loop End Sub 'URLSets() Sub UserSets() '############################################################################################### '# USerSets '############################################################################################### Dim File, tmp, Splited Dim UsersSets, UserSet Dim Count Set File= FileObj.OpenTextFile("UserSets.txt") 'On Error Resume Next Do While File.AtEndOfStream <> true tmp = File.ReadLine If tmp <>"" Then Splited= split(tmp, ";") wscript.echo "UserSet found in File: "& Splited(0) On Error Resume Next Set UserSet = entRuleElement.UserSets(Splited(0)) If Err.Number=ERROR_FileNotFound Then err.Clear Wscript.echo "New UserSets: " & Splited(0) Set UserSet = entRuleElement.UserSets.add(Splited(0)) End If On Error GoTo 0 tmp = File.ReadLine On Error Resume Next Do While tmp <> ">" If tmp <> "<" Then If (InStr (split(tmp,";")(0) ,"\")) Then wscript.echo " Add User: " & split(tmp,";")(0) UserSet.Accounts.Add split(tmp,";")(0) Else wscript.echo " Invalid User: " & split(tmp,";")(0) End If End If tmp = File.ReadLine loop On Error GoTo 0 UserSet.save End If loop End Sub 'UserSets() Sub DomainNameSets() '############################################################################################### '# UrlSets '############################################################################################### Dim File, tmp, Splited Dim DomainNSets, DomainNSet Dim Count Set File= FileObj.OpenTextFile("DomainNameSets.txt") On Error Resume Next Do While File.AtEndOfStream <> true tmp = File.ReadLine If tmp <>"" Then Splited= split(tmp, ";") wscript.echo "DomainNSet found in File: "& Splited(0) On Error Resume Next Set DomainNSet = entRuleElement.DomainNameSets(Splited(0)) If Err.Number=ERROR_FileNotFound Then err.Clear Wscript.echo "New DomainNSets: " & Splited(0) Set DomainNSet = entRuleElement.DomainNameSets.add(Splited(0)) End If On Error GoTo 0 tmp = File.ReadLine On Error Resume Next Do While tmp <> ">" If tmp <> "<" Then wscript.echo " Add Domain Name: " & split(tmp,";")(0) DomainNSet.Add split(tmp,";")(0) End If tmp = File.ReadLine loop On Error GoTo 0 DomainNSet.save End If loop End Sub 'URLSets() I start those scripts every 15 minutes (Import 5 minutes after export) PS : I'm not script specialiste, there is probably better way to do what I did....
< Message edited by Miioua -- 10.Dec.2007 2:53:51 AM >
|