Powershell脚本远程Exchange Server 2013 CU 17升级
问题描述:
我正在创建一个脚本,它使用Powershell预制了从cu15到cu17的Exchange Server 2013的远程升级。Powershell脚本远程Exchange Server 2013 CU 17升级
它更新.Net Framework 4.6.2没有问题。
启动后会出现错误。\ setup.exe/mode:upgrade/IAcceptExchangeServerLicenseTerms。
安装日志表明它不能验证凭据,但我不确定是否管理安装.net框架没有问题。在Enterprise Admin(AD)中使用的帐户;组织管理(交换); &本地服务器管理员(在所有交换服务器上)。
Exchange安装日志文件
10/04/2017 09:06:27.0628] [0] **********************************************
[10/04/2017 09:06:28.0503] [0] Starting Microsoft Exchange Server 2013 Setup
[10/04/2017 09:06:28.0503] [0] **********************************************
[10/04/2017 09:06:28.0518] [0] Local time zone: (UTC+01:00) Amsterdam, Berlin, Bern, Rome, Stockholm, Vienna.
[10/04/2017 09:06:28.0518] [0] Operating system version: Microsoft Windows NT 6.2.9200.0.
[10/04/2017 09:06:28.0518] [0] Setup version: 15.0.1320.4.
[10/04/2017 09:06:28.0518] [0] Logged on user: Dev\exadmin.
[10/04/2017 09:06:30.0003] [0] Command Line Parameter Name='mode', Value='Upgrade'.
[10/04/2017 09:06:30.0003] [0] Command Line Parameter Name='iacceptexchangeserverlicenseterms', Value=''.
[10/04/2017 09:06:30.0003] [0] Command Line Parameter Name='sourcedir', Value='c:\temp\Exchange2013-x64-cu17'.
[10/04/2017 09:06:30.0081] [0] RuntimeAssembly was started with the following command: '***/mode:upgrade /IAcceptExchangeServerLicenseTerms*** /sourcedir:c:\temp\Exchange2013-x64-cu17'.
[10/04/2017 09:06:30.0081] [0] The registry key, HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Exchange\v8.0, wasn't found.
[10/04/2017 09:06:30.0081] [0] The registry key, HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\ExchangeServer\v14, wasn't found.
[10/04/2017 09:06:30.0081] [0] Copying Files...
[10/04/2017 09:06:30.0081] [0] Starting copy from c:\temp\Exchange2013-x64-cu17\Setup\ServerRoles\Common to C:\Windows\Temp\ExchangeSetup.
[10/04/2017 09:08:48.0113] [0] Finished copy from c:\temp\Exchange2013-x64-cu17\Setup\ServerRoles\Common to C:\Windows\Temp\ExchangeSetup.
[10/04/2017 09:08:48.0113] [0] File copy complete. Setup will now collect additional information needed for installation.
[10/04/2017 09:08:48.0129] [0] Assembly dll file location is C:\Windows\Temp\ExchangeSetup\Microsoft.Exchange.Setup.Console.dll
[10/04/2017 09:08:53.0832] [0] Setup is choosing the domain controller to use
[10/04/2017 09:09:00.0067] [0] Setup is choosing a local domain controller...
[10/04/2017 09:09:00.0473] [0] Setup encountered a problem while validating the state of Active Directory: Active Directory operation failed on . The supplied credential for 'Dev\exadmin' is invalid. See the Exchange setup log for more information on this error.
[10/04/2017 09:09:00.0473] [0] Active Directory operation failed on . The supplied credential for 'Dev\exadmin' is invalid.
[10/04/2017 09:09:00.0473] [0] The supplied credential is invalid.
[10/04/2017 09:09:00.0473] [0] Setup will use the domain controller ''.
[10/04/2017 09:09:00.0473] [0] Setup will use the global catalog ''.
脚本使用
enter code here
Add-PSSnapin Microsoft.Exchange*
Import-Module FailoverClusters
Set-ExecutionPolicy Unrestricted -Confirm:$false
$Path = Get-Location
$Path = $Path.ToString()
$Date = Get-Date -Format "yyyy-MM-dd-hh-mm-ss"
$FileNameFormat = "\" + (Get-Date -Format "yyyy-MM-dd-hh-mm-ss") + "-CU17-Upgrade.log"
$Log = $Path + $FilenameFormat
$Log = $Log.ToString()
Start-Transcript -Path $Log -NoClobber -IncludeInvocationHeader
#Exchange Servers
$CUReady = $False
$domain = (Get-WmiObject Win32_ComputerSystem).Domain
$Location = $env:computername
$Location = $Location.ToString()
$Location = $Location.SubString(0,2)
$Location
$DAGs = Get-DatabaseAvailabilityGroup $Location*
$DAGmenu = @{}
$EXServermenu = @{}
for ($i=1;$i -le $DAGs.count; $i++) {
Write-Host "$i. $($DAGs[$i-1].name)"
$DAGmenu.Add($i,($DAGs[$i-1].name))
}
[int]$Dans = Read-Host 'Choose DAG'
$DAGselection = $DAGmenu.Item($Dans)
$DAGName = Get-DatabaseAvailabilityGroup -identity $DAGselection | Select -exp Name
$DAGName = $DAGName.ToString()
#Write-Host -Fore Green $DAGName
$servers = Get-DatabaseAvailabilityGroup -identity $DAGName -status | Select -exp Servers
$servers = $servers.name
[System.Collections.ArrayList]$exchangeServers = $servers
for ($i=1;$i -le $exchangeServers.count; $i++) {
Write-Host "$i. $($exchangeServers[$i-1])"
$EXServermenu.Add($i,($exchangeServers[$i-1]))
}
[int]$Eans = Read-Host 'Choose DAG'
$EXSrvselection = $EXServermenu.Item($Eans)
Write-Host -Fore Green $DAGName
Write-Host -Fore White $EXSrvselection
$exserver = $EXSrvselection
IF (Test-Connection -ComputerName $exserver -Quiet) {
write-host -Fore Green "Success! Test connection to $exserver"
} ELSE {
write-host -Fore Red "Failed! Test connection to $exserver failed. Please confirm connection and retry upgrade
Script will exit - Line 41"
exit
}
#$s = New-Pssession -Computername $exserver
Invoke-Command -ComputerName $exserver -ScriptBlock {
$exserver = [STRING] $exserver
If ($env:COMPUTERNAME -ne $($args[0])){
write-host -Fore Green "Failed! Invoke Command to $($args[0]) could not be established. Please confirm connectivity and retry upgrade
Script will exit - Line 52"
Exit
} ELSE {
$Path = Get-Location
$Path = $Path.ToString()
Set-ExecutionPolicy Unrestricted -Force
Function Get-dotNetVersion {
$dotNetHashTable = New-Object HashTable
$dotNetHashTable.Add("4.5",378389)
$dotNetHashTable.Add("4.5.1",378675..378758)
$dotNetHashTable.Add("4.5.2",379893)
$dotNetHashTable.Add("4.6",393295..393297)
$dotNetHashTable.Add("4.6.1",394254..394271)
$dotNetHashTable.Add("4.6.2",394802..394806)
$dotNetHashTable.Add("4.7",460798)
$dotNetHashTable = $dotNetHashTable.GetEnumerator() | Sort-Object -Property Value
return $dotNetHashTable
}
$Server = $exserver
$reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey("LocalMachine",$($args[0]))
$keyname = 'SOFTWARE\\Microsoft\NET Framework Setup\NDP\v4\Full'
$key = $reg.OpenSubkey($keyname)
$value = $key.GetValue('Release')
$dotNetFramework = $value
#$dotNetFramework
$GetDotNetVersion = (Get-dotNetVersion | Where {$_.value -eq $dotNetFramework}) | Select -exp Name
IF ($GetDotNetVersion -ne "4.6.2") {
Write-host -ForegroundColor Yellow ".net version on server $($args[0]) is $GetDotNetVersion"
#$dotNetFramework462 = $Path + "\dotNetFramework4.6.2\NDP462-KB3151800-x86-x64-AllOS-ENU.exe"
$dotNetFramework462 = "c:\temp\Exchange2013-x64-cu17\'dotNetFramework4.6.2'\NDP462-KB3151800-x86-x64-AllOS-ENU.exe"
IF (Test-Path $dotNetFramework462){
write-host "Installing .NET 4.6..." -ForegroundColor Green
#$dotargs = "/quiet /norestart"
#$InstalldotNet = (Start-Process $dotNetFramework462 -ArgumentList $dotargs -Wait -PassThru).ExitCode
IF ($InstalldotNet -eq 0) {
write-host -Fore Green "Successfully installed .NET 4.6"
} ELSEIF ($InstalldotNet -ne 0) { write-host -Fore Red "Failed!
Script will exit, Please review/install .NetFramework 4.6.2, then upgrade"
Exit
}
} ELSE {
write-host -Fore Red "Failed! Script will exit, Please locate/install .NetFramework 4.6.2, then upgrade"
Exit
}
} ELSEIF ($GetDotNetVersion -eq "4.6.2") {
Write-host -ForegroundColor Green ".net version on server $($args[0]) is $GetDotNetVersion"
$reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey("LocalMachine",$($args[0]))
$keyname = 'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\{4934D1EA-BE46-48B1-8847-F1AF20E892C1}'
$key = $reg.OpenSubkey($keyname)
$value = $key.GetValue('DisplayVersion')
$ExVersion = $value
IF ($ExVersion -eq '15.0.1263.5') {
Write-host "Upgrading Exchange Server 2013 - $($args[0]) to CU17..." -ForegroundColor Green
#$excu17 = $Path + "\setup.exe"
$excu17 = "c:\temp\Exchange2013-x64-cu17\setup.exe"
IF (Test-Path $excu17){
$exargs = "/mode:upgrade /IAcceptExchangeServerLicenseTerms"
$Installexcu17 = (Start-Process $excu17 -ArgumentList $exargs -Wait -PassThru).ExitCode
IF ($Installexcu17 -eq 0) {
write-host -Fore Green "Successfully upgraded Exchange Server 2013 - $($args[0]) to CU17..."
} ELSEIF ($Installexcu17 -ne 0) {
write-host -Fore Red "Failed!to upgraded Exchange Server 2013 - $($args[0]) to CU17...
Script will exit. Please review exchange upgrade logs then upgrade"
Exit
}
} ELSE {
write-host -Fore Red "Failed!
Script will exit, Please locate exchange install files on Exchange Server 2013 - $($args[0]); review errors"
Exit
}
} ELSE {
write-host -Fore Red "Failed!
Script will exit, Exchange server version on server - $($args[0]) is not CU15"
Exit
}
}
}
} -ArgumentList $exserver
Stop-Transcript -ErrorAction Ignore
如果使用下面的参数似乎工作,通过传入输入凭据,文提示输入密码。什么使用用户当前登录凭证和绕过输入密码的开放? $ s = New-PSSession -Computername“Server1” - 身份验证CredSSP -cred域\用户 - 任意 – Maverick