从powershell中的fileshare运行程序

时间:2014-10-24 15:17:39

标签: powershell powershell-v1.0 fileshare

我需要做的是在PowerShell内的远程文件共享上执行程序。示例路径是:

\ myCompany中\ filesharename \文件夹\的Program.exe

该程序采用命令行参数,字符串并对其进行解密。问题是我需要从不同计算机上的不同文件中解密和加密数千行。通过那件事一次做一件事让我很生气。我已经开始了:

clear-host
([string]$step='this') 

$value = Invoke-Command '\\mycompany\fileshare\folder\software\program.exe' $step

write-host $value

这是一个错误:

The term '\\mycompany\fileshare\folder\software\program.exe' is not re
cognized as the name of a cmdlet, function, script file, or operable program. Check the 
spelling of the name, or if a path was included, verify that the path is correct and try
again.
     At C:\Users\Me\Documents\Scripts\test.ps1:3 char:77
+ $value = \\mycompany\fileshare\folder\software\program.exe <<<<  $st
ep
    + CategoryInfo          : ObjectNotFound: (\\mycompany\fileshare...\program.exe:String 
   ) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

最终计划是编写一个gui,让脚本从文件中获取我需要的字符串,然后将它们打印在本地文件夹中。现在我需要弄清楚如何在我的脚本中使用该程序。有什么帮助吗?

1 个答案:

答案 0 :(得分:0)

使用Invoke-Expression代替Invoke-Command

$step='this'
$value = Invoke-Expression "\\mycompany\fileshare\folder\software\program.exe $step"
write-host $value