Deployment and Imaging Group

 View Only

DS6.9 - Set %SITE% Location Details 

May 02, 2012 04:47 PM

Years ago I wrote a script to set the SITE location for our computers in DS. This was to allow us to have scripts and jobs to run locally to whichever site they were on instead of across WAN traffic occuring.  This has also allowed us to run local jobs across domains and on seperate networks.

It may help a few people who work in this sort of environment.

The SQL part was canabalised from someone elses code to do some updates on the fly from the server.
The job needs to be setup as a 'runscript' task and ran on the server.  You will also need an SQL account with access to the location table to update or insert in to. Once you have created the account replace the placeholders in the script ({USERNAME}, {PASSWORD}, {DBSERVER}, {DBNAME}) with your sql user details, server details and database name.

 

' Site Update Script
' vbscript

Function Computer 
On Error Resume Next 

'*************************************************************************************
' SITE DEPOT DETAILS
''*************************************************************************************
dim TestIP
dim IPPart
dim Altiris_Depot
dim lntRowsUpdated
IntRowsUpdated = 0

TestIP = "%AGENTIPADDR%"
' Split IP Address in to pieces to handle locale
' E.g. IP is 10.90.25.11
' IPPart(0) = 10, IPPart(1) = 90, IPPart(2) = 25, IPPart(3) = 11 
IPPart = Split(TestIP,".", -1, 1)

If IPPart(0) = "10" Then ' CHECK THEY ARE FROM A COMPANY SITE ON 10 NETWORK
	Select Case IPPart(1) 
    case "60" ' SITE 60
        Altiris_Depot = "PRIMARY-DS-SRV"
    case "70" ' SITE 70
        Altiris_Depot = "SITE-DS-SRV70"
    case "80" ' SITE 80
        Altiris_Depot = "SITE-DS-SRV80"
    case "90" ' SITE 90
        Altiris_Depot = "SITE-DS-SRV90"
        Select Case IPPart(2)
        case "24" ' SECONDARY SITE 24
            Altiris_Depot = "SITE-DS-SRV24"
        Case "25" ' SECONDARY SITE 25
            Altiris_Depot = "SITE-DS-SRV25"
        Case Else ' ALL OTHERS GO TO PRIMARY DS SERVER
            Altiris_Depot = "PRIMARY-DS-SRV"
        End Select   
    Case Else ' ALL OTHERS GO TO PRIMARY DS SERVER
        Altiris_Depot = "PRIMARY-DS-SRV"
    End Select
ElseIf IPPart(0) = "11" Then ' CHECK THEY ARE FROM A COMPANY SITE ON 11 NETWORK
	Select Case IPPart(1) 
    case "60" ' SITE 60
        Altiris_Depot = "PRIMARY-DS-SRV.diffdomain.com"
    case "70" ' SITE 70
        Altiris_Depot = "SITE-DS-SRV70.diffdomain.com"
    case "80" ' SITE 80
        Altiris_Depot = "SITE-DS-SRV80.diffdomain.com"
    Case Else
        Altiris_Depot = "PRIMARY-DS-SRV.diffdomain.com"
    End Select
Else  ' all others
    Altiris_Depot = "PRIMARY-DS-SRV"
End if


'*************************************************************************************
' CONNECT AND UPDATE DATABASE
'*************************************************************************************

Dim objConn, objAdmin 
Dim strTableName, strSQL, strDBName, strDBMachine, strDBUserPW, strDBUser, strConnection 
Dim objRecSet, strTabs, strDelete, strTableNumber, strHostType, strDummy, strComputer_Id 
Dim objRs, objTest, strAllComputers, intCountObjects, intStringLength, objDiskRs, strComputerNumber 
Dim gstrServer, gstrDatabase, gstrUser, gstrPwd, objWShell, strRegLocation, strUseCmdLine, strIBTxt, strInstruct 
strHostType = right(wscript.fullname,11) 
strHostType = lcase(left(strHostType,7)) 

'**************Connection to the database**************** 
Set objConn = CreateObject("ADODB.Connection") 
objConn.Open strConnection 
if err.number <> 0 then 
    'LogError "Error - doing SQL connection as the current logged on user.", err.number, err.description 
    'strDBUser = inputbox("Please enter a SQL user -" & vbCRLF & "(sa will always work if you have the password)" & vbCRLF & "The password will be asked for in the next box.", "SQL logon", "Enter SQL user") 
    'strDBUserPw = inputbox("Please enter the SQL user password", "SQL password", "Enter SQL user password") 
    strDBUser = "{USERNAME}"
    strDBUserPW = "{PASSWORD}"
    Err.clear 
    strConnection = strConnection & ";UID=" & strDBUser & ";PWD=" & strDBUserPw 
    objConn.Open strConnection 
   
   If err.number <> 0 then 
        'LogError "Error - doing SQL connection with new user and pw.", err.number, err.description 
        'strDBMachine = inputbox("Please enter the SQL server machine name", "SQL machine name", "Enter SQL machine name") 
        strDBMachine = "{DBSERVER}"
        strDBName = "{DBNAME}" 
        Err.clear 
        strConnection = "DRIVER={SQL Server};SERVER=" & strDBMachine & ";DATABASE=" &strDBName & ";UID=" & strDBUser & ";PWD=" & strDBUserPw 
        objConn.Open strConnection 
        
        If err.number <> 0 then 
            LogError "Error - doing SQL connection with new machine name, db, user and pw.", err.number, err.description 
            LogError left(strConnection, inStrRev(strconnection,"PW") - 1), err.number, err.description 
            Wscript.echo "The connection to SQL was not created." & vbCRLF & vbCRLF & "The script will halt now. Please resolve the SQL connection error." 
            wscript.quit
        Else 
            LogError "SQL connection with SQL user name, password, machine and db name.", err.number, err.description 
        End if 
    
    else 
        LogError "SQL connection with SQL user name and password.", err.number, err.description 
    End If
Else 
    LogError "SQL connection as the current logged on user.", err.number, err.description 
End If 

objConn.CommandTimeout = 600 

strSQL = "Update location SET [SITE] = '" & Altiris_Depot & "' WHERE computer_id = '%ID%' "
Set objRs = objConn.Execute(strSql, lntRowsUpdated)

If lntRowsUpdated = 0 Then
    strSQL = "Insert into location ([computer_id], [site]) Values (%ID%, '" & Altiris_Depot & "')"
    Set objRs = objConn.Execute(strSql)
End If

End Function 

Computer

Statistics
0 Favorited
0 Views
0 Files
0 Shares
0 Downloads

Tags and Keywords

Related Entries and Links

No Related Resource entered.