В этом разделе приведены примеры сценариев Visual Basic, которые можно использовать в качестве отправной точки для создания сценариев, необходимых для создания DVD-диска со сборкой для оптимизации процесса сборки сервера. Приведенные ниже процедуры можно изменить для создания сценариев, необходимых организации.

Чтобы приведенные ниже примеры сценариев работали в конкретной среде, их, возможно, придется изменить. Эти сценарии помогут автоматизировать многие действия, необходимые для развертывания сервера Exchange Server в среде.

Примеры сценариев Visual Basic

Важно!
Эти сценарии представляют собой примеры, поясняющие автоматизацию действий. Чтобы их можно было использовать в среде, их необходимо изменить соответствующим образом. Перед использованием в рабочей среде их необходимо проверить в лабораторных условиях.

Предварительная подготовка

Для выполнения описанных ниже действий используемой учетной записи необходимо делегировать членство в локальной группе администраторов.

Дополнительные сведения о разрешениях, делегировании ролей и правах, необходимых для администрирования сервера Exchange 2007, см. в разделе Вопросы, связанные с разрешениями.

LegacyEAS.vbs

Процедура

Создание сценария Visual Basic с помощью Блокнота для включения встроенной и обычной проверки подлинности Windows для виртуального каталога /Microsoft-Server-Activesync на серверах Exchange Server 2003 (в определенной группе администраторов).

  1. Откройте Блокнот или другой текстовый редактор.

  2. Скопируйте приведенный ниже код в файл и сохраните его с описательным именем и расширением .bat. Рекомендуется назвать файл legacyEAS.vbs.

    Копировать код
    #"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
    #"!!!!!!!  THIS IS NOT A MICROSOFT SUPPORTED SCRIPT.  !!!!!!!!"
    #"!!!!!!!	TEST IN A LAB FOR DESIRED OUTCOME	!!!!!!!!"
    #"!!!!!!!						!!!!!!!!!!"
    #"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
    #" "
    '======================================='legacyEAS.vbs
    '
    'Copyright (c) 2007, Microsoft Corporation.  All Rights Reserved.
    '
    'THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
    'KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
    'IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
    'PARTICULAR PURPOSE.
    '
    '   Description: This script will enable Windows Integrated Authentication and Basic Authentication
    '				on the /Microsoft-Server-Activesync virtual directory on Exchange 2003 servers
    '				within in a defined administrative group.
    '
    'Written by: Ross Smith IV (Microsoft)
    '
    'Version: 1.3
    'Last Updated: 2/26/06
    '=======================================
    
    
    '====================================================='Define Variables & Constants
    '=====================================================
    Option Explicit
    
    Dim oArg, cnADQuery, cmEASQuery, cmOrgQuery, rsOrgDN, rsEAS, oRootDSE, strConfigurationNC, objContainer
    Dim strAGName, strAttValue, strAttribute, strDomainController, strEASDN, strLDAPPath, strLDAPCNC, strOrgDN, strLDAPSDN
    Dim i, strRemoveVal
    
    Const ADS_SCOPE_BASE = 0
    Const ADS_SCOPE_ONELEVEL = 1
    Const ADS_SCOPE_SUBTREE = 2
    Const ADS_PROPERTY_CLEAR = 1
    Const ADS_PROPERTY_UPDATE = 2
    Const ADS_PROPERTY_APPEND = 3
    Const ADS_PROPERTY_DELETE = 4
    
    '====================================================='Determine if CSCRIPT must be used
    '=====================================================
    if InStr(1,wscript.fullname,"cscript.exe",1) = 0 then
    wscript.echo "This script should be run using 'cscript.exe <scriptfile>'.  Terminating script."
    wscript.quit
    end if
    
    '=====================================================' Clear and set string variables
    '=====================================================
    strAGName = ""
    strDomainController = ""
    strLDAPCNC = ""
    strLDAPSDN = ""
    strOrgDN = ""
    strEASDN = ""
    strConfigurationNC = ""
    
    strAttribute = "msExchAuthenticationFlags"
    strAttValue = "6"
    
    '=====================================================' Parse command-line arguments
    '=====================================================
    Set oArg = wscript.arguments
    if oArg.Count = 0 then  ' we need the arguments
    DisplayHelpMessage
    wscript.quit
    End If
    
    For i = 0 to oArg.Count - 1
    
    'Get Domain Contoller value
    If LCase(Left(oArg.Item(i),3)) = "-d:" then
    strDomainController = Mid(oArg.Item(i),4)
    'wscript.echo strDomainController 
    end if
    
    'Get Administrative Group Name value
    If LCase(Left(oArg.Item(i),3)) = "-a:" then
    strAGName = Mid(oArg.Item(i),4)
    'wscript.echo strAGName
    end if
    
    Next
    
    '=====================================================' Make sure AG argument has been passed
    '=====================================================
    If strAGName = "" then
    wscript.echo "A valid Administrative Group argument was not passed!"
    wscript.quit
    end if
    
    '=====================================================' Determine if Domain Controller argument was passed
    '=====================================================
    If strDomainController <> "" then
    strLDAPPath = "LDAP://" & strDomainController & "/"
    else
    strLDAPPath = "LDAP://"
    end if
    
    '=====================================================' Initialize any objects that need initialization
    '=====================================================
    Set cnADQuery = CreateObject("ADODB.Connection")
    Set cmEASQuery = CreateObject("ADODB.Command")
    Set cmOrgQuery = CreateObject("ADODB.Command")
    
    '=====================================================' Open the connection
    '=====================================================
    cnADQuery.Provider = "ADsDSOObject"  ' This is the ADSI OLE-DB provider name
    cnADQuery.Open "Active Directory Provider"
    
    '=====================================================' Create command objects for this connection
    '=====================================================
    Set cmOrgQuery.ActiveConnection = cnADQuery
    Set cmEASQuery.ActiveConnection = cnADQuery
    
    '=====================================================' Get Configuration Naming Context & Build LDAP Path
    '=====================================================
    Set oRootDSE = GetObject(strLDAPPath & "RootDSE")
    strConfigurationNC = oRootDSE.Get("configurationNamingContext")
    'wscript.echo strConfigurationNC 
    
    strLDAPCNC = strLDAPPath & strConfigurationNC
    
    '=====================================================' Compose Search string & set search order 
    ' for Exchange Organization Search
    '=====================================================
    cmOrgQuery.CommandText = "select distinguishedName from '" & strLDAPCNC & "' where objectCategory = 'msExchOrganizationContainer'"
    cmOrgQuery.Properties("searchscope") = ADS_SCOPE_SUBTREE
    
    'Verification of CommandText
    'wscript.echo "cmOrgQuery = " & cmOrgQuery.CommandText
    
    '=====================================================' Execute & Navigate Server Query
    '=====================================================
    Set rsOrgDN = cmOrgQuery.Execute
    
    if Err.Number <> 0 then
    wscript.echo "Could not locate the organization container!"
    wscript.quit
    end if
    
    while not rsOrgDN.EOF
    'wscript.echo rsOrgDN.Fields("distinguishedName").value
    strOrgDN = rsOrgDN.Fields("distinguishedName").value
    rsOrgDN.MoveNext
    wend
    
    '=====================================================' Compose Search string & set search order 
    ' for EAS vdir Search
    '=====================================================
    If strOrgDN = "" then
    wscript.echo "Could not locate the organization container!"
    wscript.quit
    else 
    strLDAPSDN = strLDAPPath & "cn=" & strAGName & ",cn=Administrative Groups," & strOrgDN
    end if
    
    cmEASQuery.CommandText = "select name, distinguishedName from '" & strLDAPSDN & "' where cn = 'Microsoft-Server-Activesync'"
    cmEASQuery.Properties("searchscope") = ADS_SCOPE_SUBTREE
    
    'Verification of CommandText
    'wscript.echo "cmEASQuery = " & cmEASQuery.CommandText
    
    '=====================================================' Execute & Navigate SG Query
    '=====================================================
    Set rsEAS = cmEASQuery.Execute
    
    if Err.Number <> 0 then
    wscript.echo "The failed query was..."
    wscript.echo cmEASQuery.CommandText
    wscript.quit
    end if
    
    while not rsEAS.EOF
    
    'wscript.echo rsEAS.Fields("distinguishedName").value
    'wscript.echo rsEAS.Fields("name").value
    
    strEASDN = rsEAS.Fields("distinguishedName").value
    
    Set objContainer = GetObject(strLDAPPath & strEASDN)
    
    objContainer.Put strAttribute, strAttValue
    objContainer.SetInfo
    
    wscript.echo "Exchange Server Container DN - " & strEASDN
    wscript.echo "Attribute Name & Value - " & strAttribute & ": " & strAttValue
    wscript.echo "Attribute set!!" 
    wscript.echo ""
    
    strEASDN = ""
    rsEAS.MoveNext
    wend
    
    '=====================================================' Closing & Clearing Connections
    '=====================================================
    rsEAS.Close
    Set rsEAS = Nothing
    rsOrgDN.close
    Set rsOrgDN = Nothing
    cnADQuery.Close
    Set cnADQuery = Nothing
    
    '=====================================================' Help Listing
    '=====================================================
    Sub DisplayHelpMessage()
    wscript.echo "Description: This script will enable Windows Integrated Authentication and Basic Authentication"
    wscript.echo "			 on the /Microsoft-Server-Activesync virtual directory on Exchange 2003 servers"
    wscript.echo "			 within in a defined administrative group."
    wscript.echo ""
    wscript.echo "Usage: legacyEAS.vbs -a:<AdministrativeGroupName> [-d:<DomainController>]"
    wscript.echo ""
    wscript.echo "Required Arguments:"
    wscript.echo ""
    wscript.echo "-a:<AdministrativeGroupName>"
    wscript.echo "Specify legacy Exchange Administrative Group Name"	 
    wscript.echo "Ex: NorthAmerica"
    wscript.echo ""
    wscript.echo "Optional Arguments:"
    wscript.echo ""
    wscript.echo "-d:<DomainController>"
    wscript.echo "Specify the domain controller to search"
    wscript.echo "Ex: W2K3-DC-01"
    wscript.echo ""
    wscript.echo "-remove"
    wscript.echo "Removes the specified attribute"
    wscript.echo ""
    wscript.echo "Example: legacyEAS.vbs -d:W2K3-DC-01 -a:NorthAmerica"
    End Sub
    

Debuginstall.vbs

Процедура

Создание сценария Visual Basic с помощью Блокнота для изменения реестра для отладочных приложений

  1. Откройте Блокнот или другой текстовый редактор.

  2. Скопируйте приведенный ниже код в файл и сохраните его с описательным именем и расширением .bat. Рекомендуется назвать файл debuginstall.vbs.

    Копировать код
    #"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
    #"!!!!!!!  THIS IS NOT A MICROSOFT SUPPORTED SCRIPT.  !!!!!!!!"
    #"!!!!!!!	TEST IN A LAB FOR DESIRED OUTCOME	!!!!!!!!"
    #"!!!!!!!						!!!!!!!!!!"
    #"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
    #" "
    '======================================='debuginstall.vbs
    '
    'Copyright (c) 2005, Microsoft Corporation.  All Rights Reserved.
    '
    'THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
    'KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
    'IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
    'PARTICULAR PURPOSE.
    '
    'Description: This script will modify the registry for debugging applications. 
    '
    'Written by: Ross Smith IV (Microsoft)
    '
    'Version: 1.0
    'Last Updated: 2/10/2005
    '=======================================
    
    '====================================================='Define Variables & Constants
    '=====================================================
    Option Explicit
    
    Dim objRegistry, oArg, i, strEnvKeyPath, strEnvPathName, strEnvPathValue, strServerName, strEnvSymbolName, strEnvSymbolValue
    
    Const HKEY_LOCAL_MACHINE = &H80000002 
    
    '====================================================='Determine if CSCRIPT must be used
    '=====================================================
    if InStr(1,wscript.fullname,"cscript.exe",1) = 0 then
    wscript.echo "This script should be run using 'cscript.exe <scriptfile>'.  Terminating script."
    wscript.quit
    end if
    
    '====================================================='Clear variables
    '=====================================================
    strEnvPathValue = ""
    strServerName = "."
    
    '=====================================================' Parse command-line arguments
    '=====================================================
    Set oArg = wscript.arguments
    
    For i = 0 to oArg.Count - 1
    
    'Help Arguments
    If LCase(Left(oArg.Item(i),2)) = "/h" then
    DisplayHelpMessage
    wscript.quit
    end if
    
    If LCase(Left(oArg.Item(i),2)) = "/?" then
    DisplayHelpMessage
    wscript.quit
    end if
    
    If LCase(Left(oArg.Item(i),5)) = "/help" then
    DisplayHelpMessage
    wscript.quit
    end if
    
    'Get Computer Name for Remote Registry Access
    If LCase(Left(oArg.Item(i),3)) = "-s:" then
    strServerName = Mid(oArg.Item(i),4)
    'wscript.echo strServerName
    end if
    
    Next
    
    '=====================================================' Open Registry
    '=====================================================
    Set objRegistry = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strServerName & "\root\default:StdRegProv")
    
    if Err.Number <> 0 then
    wscript.echo "ERROR: Unable to connect to remote registry on the local system (" & Err.Number & ", " & Err.Description & ").  Registry not updated."
    wscript.quit
    end if
    
    '=====================================================' Define Registry Variables & Edit the Registry
    '=====================================================
    strEnvKeyPath = "System\CurrentControlSet\Control\Session Manager\Environment"
    strEnvPathName = "Path"
    strEnvSymbolName = "_NT_SYMBOL_PATH"
    strEnvSymbolValue = "%SystemRoot%\Symbols"
    'wscript.echo strEnvPath
    
    'Get the Path statement
    objRegistry.GetExpandedStringValue HKEY_LOCAL_MACHINE, strEnvKeyPath, strEnvPathName, strEnvPathValue
    'wscript.echo "Before " & strEnvPathValue
    
    'Set Path
    strEnvPathValue = StrEnvPathValue & ";C:\Tools\Exchange" & ";C:\Tools\Debugging"
    'wscript.echo "After " & strEnvPathValue
    
    'Write new registry values
    objRegistry.SetExpandedStringValue HKEY_LOCAL_MACHINE, strEnvKeyPath, strEnvPathName, strEnvPathValue
    objRegistry.SetStringValue HKEY_LOCAL_MACHINE, strEnvKeyPath, strEnvSymbolName, strEnvSymbolValue
    
    If Err.Number = 0 Then
    wscript.echo "Registry Updated!"
    Else
    WScript.Echo "Registry was not updated!" & " Error = " & Err.Number
    End If
    
    '=====================================================' Closing & Clearing Connections
    '=====================================================
    Set objRegistry = Nothing
    
    '=====================================================' Help Listing
    '=====================================================
    Sub DisplayHelpMessage()
    wscript.echo "Description: This script will set several registry settings needed"
    wscript.echo "			 for debugging applications."
    wscript.echo ""
    wscript.echo "Usage: debuginstall.vbs [-s:<ServerName>] [/?] [/h] [/help]"
    wscript.echo ""
    wscript.echo "Optional Arguments"
    wscript.echo "-s:<ServerName>"
    wscript.echo "Specify the Server to modify"	 
    wscript.echo "Ex: E2K-PF-01"
    wscript.echo ""
    End Sub
    

Дополнительные сведения

Дополнительные сведения о документировании и автоматизации процесса сборки сервера Exchange Server см. в разделе Руководства по установке сервера и автоматизации.