【发布时间】:2019-12-03 11:15:50
【问题描述】:
我希望通过设置将自动从 Microsoft 网站下载它们的 PowerShell 脚本,使我网络上的所有计算机与 Defender Anti-Virus 定义保持同步。然后,该脚本会将 .exe 文件从我的计算机传输到文本文件中的所有计算机。
我现在想要它做的是在远程计算机上运行 .exe,但我无法让它以某种方式工作。下面是我的代码。
$File = "https://go.microsoft.com/fwlink/?LinkID=121721&arch=x64"
$Location = "C:\temp\mpam-fe.exe"
$Client = New-Object System.Net.WebClient
$Client.DownloadFile($File, $Location)
Write-Host "Downloading file..."
$Computers = Get-Content "C:\temp\Computers.txt"
foreach ($Computer in $Computers) {
$Session = New-PSSession -ComputerName $Computer
Copy-Item -Path C:\temp\mpam-fe.exe C:\temp\ -ToSession $Session -Recurse -Force
Write-Host "Transferring file to $Computer"
Enter-PSSession $Computer
Set-Location "C:\temp\"
Invoke-Command ./RunAV.ps1
Exit-PSSession
}
尝试在远程计算机上运行脚本时收到的错误消息
调用命令:无法使用指定的命名解析参数集 参数。 在 C:\PSScripts\AVDownload.ps1:16 char:9 + 调用命令 ./RunAV.ps1 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (:) [Invoke-Command], ParameterBindingException + FullyQualifiedErrorId : AmbiguousParameterSet,Microsoft.PowerShell.Commands.InvokeCommandCommand【问题讨论】:
-
Enter-PSSession和Exit-PSSession用于交互使用。不要在非交互式环境中使用它们。
标签: windows powershell