Установите / обновите инструменты сборки Microsoft Visual Studio 15 или 16 с помощью WinRM на множестве компьютеров - PullRequest
1 голос
/ 07 июня 2019

Я пытаюсь обновить автоматически msbuil tools версия 15.xx и 16.xx, используя WinRM, но безуспешно.Я перепробовал много вариантов, но все еще ничего не установлено или не обновлено.

# create credentials for WinRM
$password = ConvertTo-SecureString 'pwd' -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential ('domain\user', $password)

# create command which will be executed on set of computers
$command = {
    # define and create path to store installer
    $path= 'C:\WinRM'
    If(!(test-path $path))
    {
        New-Item -ItemType Directory -Force -Path $path
    }

# download installers
    Invoke-webrequest -uri 'https://aka.ms/vs/15/release/vs_buildtools.exe' -OutFile 'C:\WinRM\vs_buildtools2017.exe'
    Invoke-webrequest -uri 'https://aka.ms/vs/16/release/vs_buildtools.exe' -OutFile 'C:\WinRM\vs_buildtools2019.exe'

# attempts to update .... noone worked 

    # Start-Process 'C:\WinRM\vs_buildtools2017.exe' -ArgumentList '--update --quiet --wait'
    # Start-Process 'C:\WinRM\vs_buildtools2019.exe' -NoNewWindow -ArgumentList 'install --wait --passive --norestart --installPath "C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools"'
    # Start-Process 'C:\WinRM\vs_buildtools2017.exe' -ArgumentList 'update --wait --quiet --norestart --installPath "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools"' }
    # Start-Process 'C:\WinRM\vs_buildtools2019.exe'  -ArgumentList '--add Microsoft.VisualStudio.Workload.MSBuildTools --quiet'
    # Start-Process 'C:\WinRM\vs_buildtools2019.exe'
}
 Invoke-Command -ComputerName (Get-Content .\Machines.txt) -ScriptBlock $command -Credential $cred

Я действительно не знаю, что я делаю неправильно.Спасибо.

1 Ответ

0 голосов
/ 07 июня 2019

Я думаю, что нашел решение.

$password = ConvertTo-SecureString 'pwd' -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential ('domain\user', $password)

$command = {
    $path= 'C:\WinRM'

    If(!(test-path $path))
    {
        New-Item -ItemType Directory -Force -Path $path
    }

   $pc = $env:computername

   # download configuration file with exported config
    net use '\\share.domain.local\something' /user:'domain\user' 'pwd'
    Copy-Item -Path '\\share.domain.local\fromPath\.vsconfig' -Recurse -Destination 'C:\WinRM\.vsconfig' -Container -Force
    Write-host "["$pc" ] =>>" "File '.vsconfig' written"

    # Download build tools installer for MSBuild 2017
    Invoke-webrequest -uri 'https://aka.ms/vs/15/release/vs_buildtools.exe' -OutFile 'C:\WinRM\vs_buildtools2017.exe'
    Write-host "["$pc" ] =>>" "File 'vs_buildtools2017' written"

    # Download build tools installer for MSBuild 2019
    Invoke-webrequest -uri 'https://aka.ms/vs/16/release/vs_buildtools.exe' -OutFile 'C:\WinRM\vs_buildtools2019.exe'
    Write-host "["$pc" ] =>>" "File 'vs_buildtools2019' written"

    Write-host "["$pc" ] =>>" "Build Tools ->  'vs_buildtools2019' -> Installing"
    $exitCode =  Start-Process 'C:\WinRM\vs_buildtools2019.exe' -ArgumentList "--config", "C:\WinRM\.vsconfig", "--quiet", "--norestart", "--wait" -Wait -PassThru
    # Write-host $exitCode | Select-Object
    Write-host "["$pc" ] =>>" "Build Tools ->  'vs_buildtools2019' -> installed"

    Write-host "["$pc" ] =>>" "Build Tools ->  'vs_buildtools2017' -> Updating"
    $exitCode =  Start-Process 'C:\WinRM\vs_buildtools2017.exe' -ArgumentList "update", "--quiet", "--norestart", "--wait" -Wait -PassThru
    # Write-host $exitCode | Select-Object
    Write-host "["$pc" ] =>>" "Build Tools ->  'vs_buildtools2017' -> updated"

    Write-host "["$pc" ] =>>" "Build Tools ->  'vs_buildtools2019' -> Updating"
    $exitCode =  Start-Process 'C:\WinRM\vs_buildtools2019.exe' -ArgumentList "update", "--quiet", "--norestart", "--wait" -Wait -PassThru
    # Write-host $exitCode | Select-Object
    Write-host "["$pc" ] =>>" "Build Tools ->  'vs_buildtools2019' -> updated"

    Write-host "["$pc" ] =>>" "<<= *** Restarting *** =>>"
    Restart-Computer -ComputerName $pc -Force
 }

 Invoke-Command -ComputerName (Get-Content .\Machines_all.txt) -ScriptBlock $command -Credential $cred
...