Wednesday, July 25, 2012

Script to move package to another folder

Recently i was required to move some packages to an 'Archive' folder. Instead of doing this manually, I created this script. The list of packages has to be put into the array in the script:


Option Explicit
'On error resume next

Dim strSMSServer, strSMSSiteCode, strPackageIDs
Dim intSourceFolder, intDestFolder, intObjectType
Dim loc, objSMS
Dim objFolder
Dim arrPackageIDs
Dim retval

strSMSServer   = "xxx"
strSMSSiteCode = "xxx"
strPackageIDs  = "99900048,9990004B..." 'to move more than one, separate with commas

intSourceFolder = 0 'Source Folder (In Production=8, Root=0)
intDestFolder   = 310 'Destination Folder (TobeDeleted = 310)
intObjectType   = 2 '2=Package for type of object

Set loc         = CreateObject("WbemScripting.SWbemLocator")
Set objSMS      = loc.ConnectServer(strSMSServer, "root\SMS\site_" & strSMSSiteCode)

Set objFolder = objSMS.Get("SMS_ObjectContainerItem")
arrPackageIDs = Split(strPackageIDs, ",")

retval = objFolder.MoveMembers(arrPackageIDs, intSourceFolder , intDestFolder , intObjectType)
If Err.Number <> 0 Then
    Wscript.Echo Err.Description
End Ifss

Wscript.echo "Done"

-----

to get the folder numbers, use this:

strSiteCode = "xxx"

Set SWBemlocator  = CreateObject("WbemScripting.SWbemLocator")
Set objWMIService = SWBemlocator.ConnectServer(strComputer,"\root\sms\site_" & strSiteCode,UserName,Password)

Dim AdvertisementInfo, objItem
Set AdvertisementInfo = objWMIService.ExecQuery ("select * from SMS_ObjectContainerNode") ' where Name = '" & FolderName & "'")
For Each objItem in AdvertisementInfo
    wscript.echo "The folder node ID for """ & objItem.Name & """ is: " & objItem.ContainerNodeID
Next

Thursday, June 14, 2012

AD Script to list OUs

I created this script to list out all the OUs and count of computers in each OU. You need to run it on a DC, and replace XXX with complete distinguished DC name:

'On Error Resume Next

Const ADS_SCOPE_SUBTREE = 2

Set objConnection = CreateObject("ADODB.Connection")
Set objCommand =   CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection

objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE

objCommand.CommandText = _
    "SELECT ADsPath FROM 'LDAP://xxxx/OU=xx,OU=xx,DC=xx,DC=xx' WHERE objectCategory='organizationalUnit'" 

Set objRecordSet = objCommand.Execute

objRecordSet.MoveFirst
Wscript.echo "OU,Count of Computers"
    intCtr = 0
Do Until objRecordSet.EOF
    Set objOU = GetObject(objRecordSet.Fields("ADsPath").Value)
    'Wscript.Echo objOU.distinguishedName
    If Instr(objOU.distinguishedName,"T_Workstations") Then
        Continue
    End If

    objOU.Filter = Array("Computer")
    intCtr=0
    For Each objItem in objOU
        'Wscript.Echo objItem.CN
    intCtr = intCtr + 1
    Next
    Wscript.Echo objOU.distinguishedName & "," & intCtr
   
    objRecordSet.MoveNext
Loop

AD Script to list Sites, Descriptions

Recently, I had to list and dump the sites information from AD. So, I created this script for it:

on error resume next

Set objRootDSE = GetObject("LDAP://RootDSE")
strConfigurationNC = objRootDSE.Get("configurationNamingContext")

strSitesContainer = "LDAP://cn=Sites," & strConfigurationNC
Set objSitesContainer = GetObject(strSitesContainer)
objSitesContainer.Filter = Array("site")
intCtr = 0
For Each objSite In objSitesContainer
    intStart = Instr(objSite.description,"(")
    intEnd = Instr(objSite.description,")")
    'Wscript.echo objSite.description
    strSiteCode = Mid(objSite.description,intStart)

    intStart = Instr(objSite.description,":")
    intEnd = Instr(objSite.description,",")
    strBusiness = Mid(objSite.description,intStart+1, intEnd-intStart-1)

    intStart = InstrRev(objSite.description,"/")
    intEnd = InstrRev(objSite.description,":")
    strLocation = Mid(objSite.description,intStart+1, intEnd-intStart-1)

    intStart = Instr(objSite.description,"/")
    intEnd = InstrRev(objSite.description,"/")
    strCountry = Mid(objSite.description,intStart+1, intEnd-intStart-1)

    WScript.Echo strSiteCode & "-" & strLocation & ";" & objSite.cn &  ";" & strCountry & ";" & strBusiness
    intCtr = intCtr + 1
    'If intcTR = 15 Then Exit For
Next

You need to run in on a DC.

Monday, December 19, 2011

Troubleshooting advertisements stuck in - Waiting for content



Sometimes an Advertisement gets stuck in Waiting state, like this:


Upon viewing the execmgr.log file, you may see this line:


And, in the contentTransfermgr.log, you can see this line:


Cause:

This is due to some error in BITS transfer from the DP to the client cache.

Resolution:

1.     First disable BITS on the DP from where the client is downloading the content (you can get this from datatransferservice.log).


2.     Wait for 10 minutes for changes to take effect.
3.     Reset the policies on the client (use SCCM Client Center->Policy Reset (Hard-Reset)).

4.     Delete the cache folder for that advertisement.
5.     Request the Machine Policy.
6.     Rerun the Advertisment.
7.     Check the execmgr.log for success.
8.     To rerun the Advertisement on ALL the failed computers, create a new Program with same settings and rerun the Advertisement,