簡體   English   中英

如何使用Power-Shell將Power-Shell遠程更新到5.1?

[英]How to update power-shell to 5.1 remotely using power-shell?

最近,我被分配了一個任務,以將我們的Power-shell更新到我們所有平台上的版本5。 我已經能夠檢測到哪些服務器需要更新,但是目前我仍然無法真正更新它。 我可以運行無提示安裝程序,但不會執行任何操作。

If($PSVersionTable.PSVersion.Major -lt 5){
    LogError "The following **** shall be updated: $($Global:setupConfiguration["GENERAL SETTINGS"]["CASINO_LOCATOR_NAME"])"

    $fileName = "Win8.1AndW2K12R2-KB3191564-x64.msu"
    $filePath = "C:\Temp\"
    $remoteFilePath = "$($Global:globalVariables.executionPath)\$fileName"
    LogMessage $filePath
    LogMessage $remoteFilePath

    if(!(Test-Path -Path $filePath )){
        New-Item -ItemType directory -Path $filePath
    }

    Copy-Item -Path $remoteFilePath  -Destination $filePath


    Start-Process "C:\Temp\Win8.1AndW2K12R2-KB3191564-x64.msu" "/q /norestart" -Wait
}

注意我嘗試使用dism.exe。

Invoke-Command{
    dism.exe /online /add-package /PackagePath:C:\Temp\KB3191564-x64.cab /norestart
    #Remove-Item c:\temp\KB3191564-x64.cab
}

這是我得到的錯誤:

Deployment Image Servicing and Management tool Version: 6.3.9600.17031
Error: 11
You cannot service a running 64-bit operating system with a 32-bit version of DISM. 
Please use the version of DISM that corresponds to your computer's architecture.

更新決議以解決我的問題如下:

If($PSVersionTable.PSVersion.Major -lt 5) {
LogError "The following casino shall be updated: 
$($Global:setupConfiguration["GENERAL SETTINGS"]["CASINO_LOCATOR_NAME"])"

$fileName = "KB3191564-x64.cab"
$filePath = "C:\Temp\"
$remoteFilePath = "$($Global:globalVariables.executionPath)\$fileName"
LogMessage $filePath
LogMessage $remoteFilePath

  if(!(Test-Path -Path $filePath )){
New-Item -ItemType directory -Path $filePath }

Copy-Item -Path $remoteFilePath  -Destination $filePath  

#Start-Process "C:\Temp\Win8.1AndW2K12R2-KB3191564-x64.msu" "/q /norestart" 
-Wait

$architecture=gwmi win32_processor | select -first 1 | select addresswidth  
if 
($architecture.addresswidth -eq "64") { Invoke-Command  {
dism.exe /online /add-package /PackagePath:C:\Temp\KB3191564-x64.cab 
/norestart
#Remove-Item c:\temp\KB3191564-x64.cab


 } } elseif 
 ($architecture.addresswidth -eq "32"){ throw "Error Message" }

}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM