我尝试使用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
我真的不知道我在做什么错。 谢谢。
答案 0 :(得分:0)
我想我找到了解决方法。
$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