Search code examples
powershellpowershell-remotinginvoke-command

Invoke-Command error when I try to run a script on a remote computer


I am trying to run a script which is located on my local computer on a remote computer and I have to problems:

first: it is trying to run the script on my local computer and I don't want it to do that

second: the script doesn't run on the remote computer

This is the command I run and the error message in question:

PS C:\Users\administrator> Invoke-Command -ComputerName UKBTH05TSV08 -FilePath "C:\TaskSchedulerEventViewerSetup.ps1"

The "ICSweep Script" source is already registered on the "localhost" computer.

    + CategoryInfo          : InvalidOperation: (:) [New-EventLog], InvalidOperationException

    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.NewEventLogCommand



ERROR: The system cannot find the file specified.

    + CategoryInfo          : NotSpecified: (ERROR: The syst...file specified.:String) [], RemoteException

    + FullyQualifiedErrorId : NativeCommandError

And this is the content of the C:\TaskSchedulerEventViewerSetup.ps1 script:

New-EventLog –LogName Application –Source “ICSweep Script” schtasks /Create /XML "ICSweepscripttaskscheduler.xml" /TN ICSweepscript /RU SYSTEM


Solution

  • this file ICSweepscripttaskscheduler.xml should exist on the remote computer.

    also Please specify a path such as :

    c:\temp\xmlfile

    so that schtasks dosent look in the windows folder for that file. The evntlog source is probably also registered on the remote computer