【发布时间】:2015-10-02 19:39:38
【问题描述】:
我正在尝试在远程计算机上运行位于本地计算机上的脚本,但我遇到了问题:
首先:它试图在我的本地计算机上运行脚本,我不希望它这样做
第二个:脚本不在远程计算机上运行
这是我运行的命令和有问题的错误消息:
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
这是 C:\TaskSchedulerEventViewerSetup.ps1 脚本的内容:
New-EventLog –LogName Application –Source “ICSweep Script” schtasks /创建 /XML "ICSweepscripttaskscheduler.xml" /TN ICSweepscript /RU 系统
【问题讨论】:
-
如果您需要添加问题,请编辑您的问题。 cmets 不适合这样做。
-
据我了解
Invoke-Command,您要求它在远程计算机上执行位于 您的 计算机上的脚本。将脚本移动到您的计算机或执行类似Invoke-Command -ComputerName UKBT -ScriptBlock {this get's executed on the remove computer }的脚本块 -
脚本已经位于我的本地计算机上并且在正确的路径中。我不明白的是为什么它不在远程计算机上运行它,为什么它在我的本地计算机上运行它
-
此文件
ICSweepscripttaskscheduler.xml应该存在于远程计算机上。还请指定一个路径,例如c:\temp\xmlfile,以便 schtasks 在 windows 文件夹中查找该文件。 evntlog 源可能也在远程计算机上注册了 -
基兰,当机立断。感谢您的解决方案。一旦我将其更改为 C:\ICSweepscripttaskscheduler.xml,它就可以工作了。我完全失明了。谢谢各位
标签: powershell powershell-remoting invoke-command