Accueil > SCCM > SCCM – Automating Configuration by Scripting for SCCM Secondary Site Servers

SCCM – Automating Configuration by Scripting for SCCM Secondary Site Servers

Bonjour à tous,

Bonne Année 2012 à toutes et à tous !!! 🙂

hydration_SCR

Pour commencer, je profite de cette nouvelle année 2012 pour vous faire partager un script VBS qui permet d’activer et de configurer tous les rôles d’un site secondaire sous SCCM 2007 SP2.

En rouge : Ce que vous devez modifier
En vert : Les rôles que vous désirez activer. Pour ce faire, supprimer le (‘) se trouvant devant la ligne du rôle que vous souhaitez installer.

Script

‘********************************************************************
‘ Main routine
‘********************************************************************
 
On Error Resume Next

‘ Set variables (site code, system to configure, domain)  
strSiteCode = "MCM"
strComputerName = "SMSMEMBER"
strDomainName = "smsdomain.smsdemo.microsoft.com"
    
‘ Connect to the Configuration Manager server.
Set objConnection = ConnectToSMS(strSiteCode)
    
‘ Load the the site control file.
Set objContext = CreateObject("WbemScripting.SWbemNamedValueSet")
objContext.Add "SessionHandle", objConnection.ExecMethod("SMS_SiteControlFile", "GetSessionHandle").SessionHandle
    
‘ Enable site system.
EnableSiteRole objConnection, objContext, "SMS Site System", strComputerName, strSiteCode, strDomainName

‘ Enable site role(s).
‘ Uncomment site roles to install.
‘ ———————————

‘EnableSiteRole objConnection, objContext, "SMS Branch Distribution Point", strComputerName, strSiteCode, strDomainName
‘EnableSiteRole objConnection, objContext, "SMS Distribution Point", strComputerName, strSiteCode, strDomainName    
‘EnableSiteRole objConnection, objContext, "SMS Fallback Status Point", strComputerName, strSiteCode, strDomainName
‘EnableSiteRole objConnection, objContext, "SMS Management Point", strComputerName, strSiteCode, strDomainName
‘EnableSiteRole objConnection, objContext, "SMS PXE Service Point", strComputerName, strSiteCode, strDomainName
‘EnableSiteRole objConnection, objContext, "SMS Reporting Point", strComputerName, strSiteCode, strDomainName
‘EnableSiteRole objConnection, objContext, "SMS Server Locator Point", strComputerName, strSiteCode, strDomainName
‘EnableSiteRole objConnection, objContext, "SMS Software Update Point", strComputerName, strSiteCode, strDomainName
‘EnableSiteRole objConnection, objContext, "SMS State Migration Point", strComputerName, strSiteCode, strDomainName

‘ Release the site control file
objConnection.Get("SMS_SiteControlFile").ReleaseSessionHandle objContext.Item("SessionHandle").Value

‘ Cleanup
Set strSiteCode = Nothing
Set strComputerName = Nothing 
Set strDomainName = Nothing
Set objConnection = Nothing
Set objContext = Nothing

‘********************************************************************
‘ Function: ConnectToSMS
‘ Description: This routine makes a connection to the specified site code.
‘********************************************************************
Function ConnectToSMS(strSiteCode)

Dim objLocator
Dim objConnection

‘ Initialization
Set objLocator = CreateObject("WbemScripting.SWbemLocator")

‘ Find the provider server
Set objConnection = objLocator.ConnectServer( , "root\sms\site_" & strSiteCode )

‘ Return the connection object
Set ConnectToSMS = objConnection

End Function

‘********************************************************************
‘ Function:    EnableSiteRole
‘ Description: This enables the specified site system role.
‘********************************************************************

Function EnableSiteRole(objConnection, objContext, strSiteRole, strComputerName, strSiteCode, strDomainName)

Dim objRole
Dim objProp
Dim objPropLists
Dim objComponents
Dim objComponent
Dim objComponentProps
Dim strTempSiteRole

‘ Refresh our copy of the site control file.
objConnection.ExecMethod "SMS_SiteControlFile.Filetype=1,Sitecode=’" & strSiteCode & "’", "RefreshSCF", , , objContext

‘ Note: There is no separate site role for a Branch Distribution Point, instead the
IsPeerDP property is enabled
‘ on a SMS Distribution Point role.   
‘ Workaround: Set variable to SMS Distribution Point, if the site role is a Branch

Distribution Point
If strSiteRole = "SMS Branch Distribution Point" Then strTempSiteRole = "SMS Distribution Point" Else strTempSiteRole = strSiteRole End If
    
‘ Retrieve the site control object.
On Error Resume Next
Set objRole = objConnection.Get("SMS_SCI_SysResUse.FileType=2,ItemName=" & Chr(34) & _
"[\" & Chr(34) & "Display=\\\\" &  strComputerName & "\\\" & Chr(34) & "]MSWNET:[\" & Chr(34) & "SMS_SITE=" & _
strSiteCode & "\" & Chr(34) & "]\\\\" & strComputerName & "\\," & strTempSiteRole & Chr(34) & ",ItemType=" & Chr(34) & _
"System Resource Usage" & Chr(34) & ",SiteCode=" & Chr(34) & strSiteCode & Chr(34), , objContext)
       
‘ If the site role already exists, then get the current properties
If Err.Number = 0 then 
objProp = objRole.Props
wscript.echo strTempSiteRole & " already exists. "
wscript.echo "Attempting to enable the site role."

‘ If the site role is not found, then create it
ElseIf CStr(Hex(Err.Number)) = "80041002" then 
Set objRole = objConnection.Get("SMS_SCI_SysResUse").SpawnInstance_
objRole.NALPath  = "[" & Chr(34) & "Display=\\" &  strComputerName & "\" & Chr(34) & "]MSWNET:[" & Chr(34) & "SMS_SITE=" & strSiteCode & Chr(34) & "]\\" & strComputerName & "\"
objRole.NALType  = "Windows NT Server"
objRole.RoleName = strTempSiteRole
objRole.Sitecode = strSiteCode
objProp = Array()
wscript.echo strTempSiteRole & " doesn’t exist. "
wscript.echo "Attempting to create the site role." 
        
‘ On any other error, fail and exit the function
Else
EnableSiteRole = False 
wscript.echo "Unexpected error: 0x" & Hex(Err.Number) & " – " & Err.Description
wscript.echo "Not attempting to enable the site role." 
Exit Function
       
End If

On Error GoTo 0
   
objPropLists = objRole.PropLists
If IsNull(objPropLists) then
objPropLists = Array()
End if

‘ Set the appropriate properties for the specified role
Select Case strSiteRole
                   
Case "SMS Branch Distribution Point"           
SetProperty objConnection, objProp, "IsPeerDP",1, "", ""
SetProperty objConnection, objProp, "MinFreeSpace",50, "", ""
SetProperty objConnection, objProp, "Server Remote Name",0, strComputerName & "." & strDomainName, ""
               
Case "SMS Distribution Point"
SetProperty objConnection, objProp, "Site Info", 0, strComputerName, strSiteCode
SetProperty objConnection, objProp, "BITS download", 1, "", ""
SetProperty objConnection, objProp, "Is protected", 0, "", ""
SetProperty objConnection, objProp, "IsAnonymousEnabled", 1, "", ""
SetProperty objConnection, objProp, "Server Remote Name",0, strComputerName & "." & strDomainName, ""

Case "SMS Fallback Status Point"
SetProperty objConnection, objProp, "FSPInternetFacing",0, "", ""
SetProperty objConnection, objProp, "Server Remote Name",0, "", ""
SetProperty objConnection, objProp, "Throttle Count",10000, "", ""
SetProperty objConnection, objProp, "Throttle Interval",3600000, "", ""
SetProperty objConnection, objProp, "Server Remote Name",0, strComputerName & "." & strDomainName, ""

Case "SMS Management Point"
SetProperty objConnection, objProp, "Server Remote Name",0, strComputerName & "." & strDomainName, ""
                       
Case "SMS PXE Service Point"
SetProperty objConnection, objProp, "IsActive",1, "", ""
SetProperty objConnection, objProp, "BindPolicy",0, "", ""
SetProperty objConnection, objProp, "ResponseDelay",0, "", ""
SetProperty objConnection, objProp, "PXEPassword",0, "", ""

‘SetProperty objConnection, objProp, "AuthType",0, "", ""
‘SetProperty objConnection, objProp, "UserName",0, "", ""
‘SetProperty objConnection, objProp, "CertificateType",0, "", ""
‘SetProperty objConnection, objProp, "CertificateFile",0, "", ""

SetProperty objConnection, objProp, "Server Remote Name",0, strComputerName & "." & strDomainName, ""

Case "SMS Reporting Point"
SetProperty objConnection, objProp, "ReportingPointFolder", 0, "", "SMSReporting_" & strSiteCode
SetProperty objConnection, objProp, "Protocol", 0, "", ""
SetProperty objConnection, objProp, "PortNumber", 80, "", ""

Case "SMS Server Locator Point"
SetProperty objConnection, objProp, "UseSiteDatabase", 1, "", ""
SetProperty objConnection, objProp, "SQLServerName", 0, "", ""
SetProperty objConnection, objProp, "DatabaseName", 0, "", ""
SetProperty objConnection, objProp, "Authentication type", 0, "", ""
SetProperty objConnection, objProp, "UserName", 0, "", ""
SetProperty objConnection, objProp, "Server Remote Name",0, strComputerName & "." & strDomainName, ""
                       
Case "SMS Site System"
SetProperty objConnection, objProp, "Server Remote Name",0, strComputerName & "." & strDomainName, ""
SetProperty objConnection, objProp, "IsProtected",0, "", ""
SetProperty objConnection, objProp, "Server Remote Public Name",0, "", ""
SetProperty objConnection, objProp, "FDMOperation",0, "", ""            
           
Case "SMS Software Update Point"
SetProperty objConnection, objProp, "UseProxy",0, "", ""
SetProperty objConnection, objProp, "ProxyName",0, "", ""
SetProperty objConnection, objProp, "ProxyServerPort",80, "", ""
SetProperty objConnection, objProp, "AnonymousProxyAccess",1, "", ""
SetProperty objConnection, objProp, "UserName",0, "", ""
           
Case "SMS State Migration Point"           
SetProperty objConnection, objProp, "Server Remote Name",0, strComputerName & "." & strDomainName, ""
SetProperty objConnection, objProp, "SMPQuiesceState",0, "", ""
SetProperty objConnection, objProp, "SMPStoreDeletionDelayTimeInMinutes",1440, "", ""
SetProperty objConnection, objProp, "SMPStoreDeletionCycleTimeInMinutes",1440, "", ""
SetPropertyList  objConnection, objPropLists, "Directories", Array("Directory=D:\StateMigration;MaxClients=100;MinDiskSpace=100;MinDiskSpaceUnit=1;")           
                                       
Case Else
wscript.echo " Invalid role specified: " & strSiteRole
EnableSiteRole = False
Exit Function

End Select

‘ Save the (possibly) updated properties.
objRole.Props = objProp
objRole.PropLists = objPropLists

‘ Store the new role instance.
On Error Resume Next
objRole.Put_ , objContext
If Err Then
wscript.echo " Error assigning role " & strSiteRole & " to " & strComputerName & ": " & Err.Description
Err.Clear
Else
wscript.echo " Setting " & strComputerName & " to an " & strSiteRole
End If
On Error GoTo 0
    
‘ Commit the changes to the Site Control file.
Set InParams = objConnection.Get("SMS_SiteControlFile").Methods_("CommitSCF").InParameters.SpawnInstance_
InParams.SiteCode = strSiteCode
objConnection.ExecMethod "SMS_SiteControlFile", "CommitSCF", InParams, , objContext
    
‘ Cleanup
Set objRole = Nothing
Set objProp = Nothing
Set objPropLists = Nothing
Set objComponents = Nothing
Set objComponent = Nothing
Set objComponentProps = Nothing
   
End Function

‘********************************************************************
‘ Function:    SetProperty
‘ Description: This is used to set or create entries in a site control property array.
‘********************************************************************
Function SetProperty(objConnection, objProp, strPropertyName, intValue, strValue1, strValue2)

Dim index
Dim bFoundProperty
Dim objNewProp

bFoundProperty = False

‘ Loop through properties until a match is found and then set the properties using the values passed in.
For index = 0 to UBound(objProp)

If objProp(index).PropertyName = strPropertyName then
                   
bFoundProperty = TRUE
objProp(index).Value = intValue
objProp(index).Value1 = strValue1
objProp(index).Value2 = strValue2
Exit For

End if

Next

‘ If the property doesn’t exist, then create it and set the property values using the values passed in.    
If not bFoundProperty then 
   
Set objNewProp = objConnection.Get("SMS_EmbeddedProperty").SpawnInstance_
objNewProp.PropertyName = strPropertyName
objNewProp.Value = intValue
objNewProp.Value1 = strValue1
objNewProp.Value2 = strValue2

ReDim Preserve objProp(UBound(objProp) + 1)
Set objProp(UBound(objProp)) = objNewProp
       
End if

‘ Cleanup
Set index = Nothing
Set bFoundProperty = Nothing
Set objNewProp = Nothing
     
End Function

‘********************************************************************
‘ Function:    SetPropertyList
‘ Description: This is used to set or create entries in a site control property list array.
‘********************************************************************
Function SetPropertyList(objConnection, objPropLists, strPropertyListName, arrList)

Dim index
Dim bFoundProperty
Dim objNewProp

bFoundProperty = False
   
‘ If the Property List Name already exists, set the values using the arrList variable passed in. 
For index = 0 to UBound(objPropLists)
If objPropLists(index).PropertyListName = strPropertyListName then
bFoundProperty = TRUE
objPropLists(index).Values = arrList
Exit For
End if
Next

‘ If the Property List Name does not exist, create it and set values using the arrList variable passed in.
If not bFoundProperty then
Set objNewProp = objConnection.Get("SMS_EmbeddedPropertyList").SpawnInstance_
objNewProp.PropertyListName = strPropertyListName
objNewProp.Values = arrList

‘ Resize the property list and add the new Property List Name.
ReDim Preserve objPropLists(UBound(objPropLists) + 1)
Set objPropLists(UBound(objPropLists)) = objNewProp
End if
 
‘ Cleanup
Set index = Nothing
Set bFoundProperty = Nothing
Set objNewProp = Nothing
    
End Function

Source :
http://social.technet.microsoft.com/Forums/de-DE/configmgrsdk/thread/d6f7e8b7-7214-4e42-bd20-16136b76a3a4

Enjoy !

Michel PICOLLET | EXAKIS Paris
Consultant Senior Microsoft [System Center]
mpicollet@event-horizon.fr

Catégories :SCCM Étiquettes : , ,
  1. Daniel
    février 24, 2012 à 3:20

    Just wanted to say thank you for this. I have been looking for a script for this for a few weeks now. It wasn’t even a search for this that lead me hear, but thank you!

  1. No trackbacks yet.

Laisser un commentaire

Entrez vos coordonnées ci-dessous ou cliquez sur une icône pour vous connecter:

Logo WordPress.com

Vous commentez à l'aide de votre compte WordPress.com. Déconnexion / Changer )

Image Twitter

Vous commentez à l'aide de votre compte Twitter. Déconnexion / Changer )

Photo Facebook

Vous commentez à l'aide de votre compte Facebook. Déconnexion / Changer )

Photo Google+

Vous commentez à l'aide de votre compte Google+. Déconnexion / Changer )

Connexion à %s

%d blogueurs aiment cette page :