Я думаю, что нашел решение.
$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