locked
Criação de Collection no SMS via VBScript RRS feed

  • Pergunta

  • Bom dia a todos.

     

    Alguém sabe com criar uma collection via VBS??

    E adicionar um Membershiprule via VBS?

     

    Procurei alguns códigos na internet porem a maioria esta gerando erros que nao estou conseguindo resolver!

     

    Obrigado.

     

     

     

    quinta-feira, 10 de abril de 2008 11:59

Respostas

  • Tenta utilizar o script abaixo, é só executar no servidor do SMS que o script lhe perguntará o nome da collection.

     

    Code Snippet
    'get a command-line argument - this makes the script flexible
    newname = InputBox("Digite o nome da Collection","Collection")
    'connect to WMI and the SMS namespace, as usual
    Set lLocator = CreateObject("WbemScripting.SWbemLocator")
    Set gService = lLocator.ConnectServer( , "root\sms\site_B2K")
    'check if the Collection name specified is unique
    alreadyused = False
    Set Collections = gService.ExecQuery("Select * From SMS_Collection")
    For Each Collection In Collections
        If Collection.Name = newname Then alreadyused = True
    Next
    If alreadyused Then
       MsgBox "This collection name is already in use. Please enter a different name."
       Else
       'create the collection
       Dim newCollection
       Set newCollection = gService.Get("SMS_Collection").SpawnInstance_()
       newCollection.Name = newname
       newCollection.OwnedByThisSite = True
       newCollection.comment = "this is just a test"   newCollection.Put_
       path=newCollection.Put_
       'and get the automatically assigned collection ID for our new collection
       Set Collection=gService.Get(path)
       newcollectionid= Collection.CollectionID
       'create the collection relationship
       'you could use the VerifyNoLoops method of the SMS_Collection class if you
       'want to ensure that you won't create a loop of collections
       Dim newCollectionRelation
       Set newCollectionRelation = gService.Get( "SMS_CollectToSubCollect" ).SpawnInstance_()
       newCollectionRelation.parentCollectionID = "COLLROOT"  
       newCollectionRelation.subCollectionID = newcollectionid
       newCollectionRelation.Put_
       'determine the current user, as a resource ID
       Set oWshNetwork=CreateObject("Wscript.Network")
       username = oWshNetwork.UserName
       Set Users = gService.ExecQuery("Select * From SMS_R_User WHERE Name LIKE ""%" + username + "%""")
       For Each User In Users
          If User.username = username Then
             ResID = User.ResourceID
          End If
       Next
       'you might want to handle the contingency of a user that is new to
       'the domain and hasn't been added to the list of SMS users yet
       'create a direct collection rule for the user we just determined
       Set CollectionRule = gService.Get("SMS_CollectionRuleDirect").SpawnInstance_()
       CollectionRule.ResourceClassName = "SMS_R_User"  
       CollectionRule.RuleName = "ResourceID=" & ResID
       CollectionRule.ResourceID = ResID
       'add the rule to the collection
       Collection.AddMembershipRule CollectionRule
       If Err.Number = 0 Then
          Wscript.Echo "You were added to the " + Collection.Name + " collection!"  
          End If
    End If 'this is the end of the test for a unique collection

     

     

     

    quinta-feira, 24 de abril de 2008 22:42

Todas as Respostas

  • Tenta utilizar o script abaixo, é só executar no servidor do SMS que o script lhe perguntará o nome da collection.

     

    Code Snippet
    'get a command-line argument - this makes the script flexible
    newname = InputBox("Digite o nome da Collection","Collection")
    'connect to WMI and the SMS namespace, as usual
    Set lLocator = CreateObject("WbemScripting.SWbemLocator")
    Set gService = lLocator.ConnectServer( , "root\sms\site_B2K")
    'check if the Collection name specified is unique
    alreadyused = False
    Set Collections = gService.ExecQuery("Select * From SMS_Collection")
    For Each Collection In Collections
        If Collection.Name = newname Then alreadyused = True
    Next
    If alreadyused Then
       MsgBox "This collection name is already in use. Please enter a different name."
       Else
       'create the collection
       Dim newCollection
       Set newCollection = gService.Get("SMS_Collection").SpawnInstance_()
       newCollection.Name = newname
       newCollection.OwnedByThisSite = True
       newCollection.comment = "this is just a test"   newCollection.Put_
       path=newCollection.Put_
       'and get the automatically assigned collection ID for our new collection
       Set Collection=gService.Get(path)
       newcollectionid= Collection.CollectionID
       'create the collection relationship
       'you could use the VerifyNoLoops method of the SMS_Collection class if you
       'want to ensure that you won't create a loop of collections
       Dim newCollectionRelation
       Set newCollectionRelation = gService.Get( "SMS_CollectToSubCollect" ).SpawnInstance_()
       newCollectionRelation.parentCollectionID = "COLLROOT"  
       newCollectionRelation.subCollectionID = newcollectionid
       newCollectionRelation.Put_
       'determine the current user, as a resource ID
       Set oWshNetwork=CreateObject("Wscript.Network")
       username = oWshNetwork.UserName
       Set Users = gService.ExecQuery("Select * From SMS_R_User WHERE Name LIKE ""%" + username + "%""")
       For Each User In Users
          If User.username = username Then
             ResID = User.ResourceID
          End If
       Next
       'you might want to handle the contingency of a user that is new to
       'the domain and hasn't been added to the list of SMS users yet
       'create a direct collection rule for the user we just determined
       Set CollectionRule = gService.Get("SMS_CollectionRuleDirect").SpawnInstance_()
       CollectionRule.ResourceClassName = "SMS_R_User"  
       CollectionRule.RuleName = "ResourceID=" & ResID
       CollectionRule.ResourceID = ResID
       'add the rule to the collection
       Collection.AddMembershipRule CollectionRule
       If Err.Number = 0 Then
          Wscript.Echo "You were added to the " + Collection.Name + " collection!"  
          End If
    End If 'this is the end of the test for a unique collection

     

     

     

    quinta-feira, 24 de abril de 2008 22:42
  • Bruno,

     

    Obrigodo pela resposta..

     

    Eu ja havia consigo desenvolver um script, porem apos quebrar um pouco a cuca eu resolvi!!

    Mesmo assim mto obrigado!!!

     

    sexta-feira, 2 de maio de 2008 12:06