【发布时间】:2021-05-14 08:21:48
【问题描述】:
大家好,在我的代码的某个地方我犯了一个错误,而不是在远程安装它尝试在本地安装
## Get list of servers
#$servers = Get-Content C:\listOfServer.txt
$servers = ('test','test2')
$url = "https:/microsoft.com/dotnetcore/5.0/Runtime/5.0.2/win/$file"
$file = "dotnet-hosting-5.0.2-win.exe"
$args = @("/install", "/quiet", "/norestart")
$path = ("c:\tmp")
$sourcefile = "$path\$file"
$remotefile = "$destinationPath\$file"
#download file on a local machine
Invoke-WebRequest -Uri $url -OutFile $sourcefile
Write-Verbose "Downloading [$url]`nSaving at [$sourcefile]" -Verbose
#connecting to remote machine and checking for dir existed
foreach($server in $servers) {
# Destination UNC path changes based on server name
$destinationPath = "\\$server\D$\tmp\"
# Check that full folder structure exists and create if it doesn't
if(!(Test-Path $destinationPath)) {
# -Force will create any intermediate folders
New-Item -ItemType Directory -Force -Path $destinationPath
}
# Copy the file across
Copy-Item $sourcefile $destinationPath
}
#PART WHICH IS NOT WORKING: It installs on a local machine
foreach($server in $servers) {
$p = Start-Process -FilePath $remotefile -ArgumentList $args -Wait
if($p -eq 0)
{
Write-Host "installation finished sucessfuly"
}
Write-Host "installation failed"
}
Remove-Item $remotefile
您能帮我找出我在代码中造成的错误吗
【问题讨论】:
-
您正在本地运行安装命令。您需要在远程设备上运行它。查看调用命令。这个命令有一个远程机器的参数。注意双跳,在调用命令中使用本地文件路径而不是 unc 路径。
标签: powershell installation remote-access