I am looking to keep all the computers on my network up to date with the Defender Anti-Virus definitions by setting up a PowerShell script that will automatically download them from the Microsoft website. The script will then transfer the the .exe file from my computer to all the computers in a text file.
What I want it to do now is to run the .exe on the remote computer but I am not getting it to work somehow. Below is my code.
$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
}
The error message that I receive when it tries to run the script on the remote computer
Invoke-Command : Parameter set cannot be resolved using the specified named
parameters.
At C:\PSScripts\AVDownload.ps1:16 char:9
+ Invoke-Command ./RunAV.ps1
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Invoke-Command], ParameterBindingException
+ FullyQualifiedErrorId : AmbiguousParameterSet,Microsoft.PowerShell.Commands.InvokeCommandCommand
Enter-PSSessionandExit-PSSessionare for interactive use. Don't use them in non-interactive contexts.