Skip to main content

sms: moving collections through a command line...

well, during my travel, i find myself at a site whose collection management was a little sparse. to help move them along, i wrote up a script to move a collection to a new parent collection, through a command line. it was a little bit of a challenge because there weren't very many samples floating around.

many thanks to dave lippa and the rest of the group at myitforum for their help! i shamelessly stole stuff out of greg ramsey's script. the script is located here.

there's not that much to it, actually. you simply tell it the old parent, the new parent, and the id of the collection you're moving. i suppose it's more concept than anything else. it'd be easy to make this thing much more useful... but you know... necessity. less words. :| just keep in mind when doing something like this that in order to remove the current collection link, you have to add a new one. otherwise, it will go through as if it works but never remove it.

order it correctly and things are great. 1. add. 2. delete.

[usage] sms_collmove.vbs
[example] sms_collmove.vbs collroot abc0019a abc0014a

 

strSMSServer = "<SMS Server Name>"

Set objArguments = WScript.Arguments
If objArguments.Count <> 3 Then
    ListHelp
    WScript.Quit
End If

strOldParentColl = UCase(objArguments(0))
strNewParentColl = UCase(objArguments(1)) 'parent collection ID
strSubColl =       UCase(objArguments(2)) 'collection ID to link

Set objLoc =  CreateObject("WbemScripting.SWbemLocator")
Set objSMS = objLoc.ConnectServer(strSMSServer, "root\sms")
Set Results = objSMS.ExecQuery("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true")
For Each Loc in Results
    If Loc.ProviderForLocalSite = True Then
        Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & Loc.SiteCode)
    End If
Next

' Add a collection link
Set ColSvcs = objSMS.Get("SMS_Collection")

' Verify no looping in the collection
ColSvcs.VerifyNoLoops "SMS_Collection.CollectionID=""" & _
    strNewParentColl & """", "SMS_Collection.CollectionID=""" & _
    strSubColl & """", Result

if Result = 0 then
    wscript.echo "Link would cause looping condition, exiting"
else
    Set objCol = objSMS.Get("SMS_CollectToSubCollect").SpawnInstance_()
    objCol.parentCollectionID = strNewParentColl
    objCol.subCollectionID = strSubColl
    objCol.Put_
    wscript.echo "Added collection link: " & strSubColl & " to " & strNewParentColl & " ..."
end If

' Delete a collection link
Set Coll = objSMS.ExecQuery("select * from sms_collecttosubcollect where parentcollectionid= '" & strOldParentColl & "' and subcollectionid = '" & strSubColl & "'")

For Each colitem In Coll
    WScript.Echo "Deleting subcollection link: " & colitem.subcollectionid & " from " & strOldParentColl & " ..."
    colitem.delete_
Next

Function ListHelp
    WScript.Echo VbCrLf & "SMS Change Parent Collection" & VbCrLf & VbCrLf & _
        "[Usage  ]   sms_collmove.vbs <old parent> <new parent> <subcollection>" & VbCrLf & VbCrLf &_
        "[Example]   sms_collmove.vbs collroot abc0019a abc0014a" & VbCrLf & _
        "              - Transfers subcollection ABC0014A to new parent" & VbCrLf &_
        "              - ABC0019A from old parent COLLROOT" & VbCrLf & VbCrLf &_
        "[Misc   ]   Use COLLROOT as the old parent if the" & VbCrLf &_
           "        subcollection does not have a parent."
End Function

Comments

  1. Oh my goodness, BLESS YOU for this script. It works like a charm.

    ReplyDelete

Post a Comment

Popular posts from this blog

using preloadpkgonsite.exe to stage compressed copies to child site distribution points

UPDATE: john marcum sent me a kind email to let me know about a problem he ran into with preloadpkgonsite.exe in the new SCCM Toolkit V2 where under certain conditions, packages will not uncompress.  if you are using the v2 toolkit, PLEASE read this blog post before proceeding.   here’s a scenario that came up on the mssms@lists.myitforum.com mailing list. when confronted with a situation of large packages and wan links, it’s generally best to get the data to the other location without going over the wire. in this case, 75gb. :/ the “how” you get the files there is really not the most important thing to worry about. once they’re there and moved to the appropriate location, preloadpkgonsite.exe is required to install the compressed source files. once done, a status message goes back to the parent server which should stop the upstream server from copying the package source files over the wan to the child site. anyway, if it’s a relatively small amount of packages, you can

How to Identify Applications Using Your Domain Controller

Problem Everyone has been through it. We've all had to retire or replace a domain controller at some point in our checkered collective experiences. While AD provides very intelligent high availability, some applications are just plain dumb. They do not observe site awareness or participate in locating a domain controller. All they want is the name or IP of one domain controller which gets hardcoded in a configuration file somewhere, deeply embedded in some file folder or setting that you are never going to find. How do you look at a DC and decide which applications might be doing it? Packet trace? Logs? Shut it down and wait for screaming? It seems very tedious and nearly impossible. Potential Solution Obviously I wouldn't even bother posting this if I hadn't run across something interesting. :) I ran across something in draftcalled Domain Controller Isolation. Since it's in draft, I don't know that it's published yet. HOWEVER, the concept is based off

sccm: content hash fails to match

back in 2008, I wrote up a little thing about how distribution manager fails to send a package to a distribution point . even though a lot of what I wrote that for was the failure of packages to get delivered to child sites, the result was pretty much the same. when the client tries to run the advertisement with an old package, the result was a failure because of content mismatch. I went through an ordeal recently capturing these exact kinds of failures and corrected quite a number of problems with these packages. the resulting blog post is my effort to capture how these problems were resolved. if nothing else, it's a basic checklist of things you can use.   DETECTION status messages take a look at your status messages. this has to be the easiest way to determine where these problems exist. unfortunately, it requires that a client is already experiencing problems. there are client logs you can examine as well such as cas, but I wasn't even sure I was going to have enough m