我正在尝试使用powershell脚本将.net4.6.2安装到远程服务器上。我将文件本地下载到我的机器上然后我使用powershell脚本将文件从本地机器复制到虚拟机并安装软件,但是它失败或从任务管理器中途消失。复制工作正常。我遇到问题的部分实际上是开始并完成了这个过程。 下面的脚本就是我正在使用的脚本:
#Variables
$computername = Get-Content C:\PSdeploy\list.txt
$sourcefile = "C:\temp\NET462.exe"
#This section will install the software
foreach ($computer in $computername)
{
$destinationFolder = "\\$computer\C$\Temp"
#This section will copy the $sourcefile to the $destinationfolder. If the Folder does not exist it will create it.
if (!(Test-Path -path $destinationFolder))
{
New-Item $destinationFolder -Type Directory
}
Copy-Item -Path $sourcefile -Destination $destinationFolder
Invoke-Command -ComputerName $computer -ScriptBlock {Start-Process -FilePath "C:\temp\NET462.exe" -Wait -Verb RunAs -PassThr}
}
Read-Host