简体   繁体   English

如何使用Power-Shell将Power-Shell远程更新到5.1?

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

I have been assigned a task recently to update our power-shell to version 5 on all our platform. 最近,我被分配了一个任务,以将我们的Power-shell更新到我们所有平台上的版本5。 I have been able to detect which servers need to be updated but at the moment I am stuck with actually updating it. 我已经能够检测到哪些服务器需要更新,但是目前我仍然无法真正更新它。 I can run the silent installer but it doesn't do anything. 我可以运行无提示安装程序,但不会执行任何操作。

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
}

Note i tried using dism.exe. 注意我尝试使用dism.exe。

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

This is the error I got: 这是我得到的错误:

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.

To update the resolution to my question was as following : 更新决议以解决我的问题如下:

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