简体   繁体   English

Powershell中Invoke-Command的问题

[英]issues with Invoke-Command in powershell

I'm having issues executing an app, that I need to pass parameters to. 我在执行应用程序时遇到问题,需要将参数传递给该应用程序。 I believe the problem has to do with one of the values for the parameter, but i'm not sure. 我相信问题与参数的值之一有关,但我不确定。

I've added 'C:\\Program Files\\OmniBack\\bin\\omnir.exe' to the path, which is where omnir resides 我在路径中添加了“ C:\\ Program Files \\ OmniBack \\ bin \\ omnir.exe”,omnir所在的路径

$cmd = 'omnir.exe'
$arg1 = "-winfs"
$source = "server.domain.domain:/F `"server.domain.domain [/F]`""
$arg2 = "-session"
$session = "2015/07/01-56"
$arg3 = "-tree"
$tree = "/folder1/folder2/folder3/test1.txt"

& $cmd $arg1 $source $arg2 $session $arg3 $tree 

This is the error I get 这是我得到的错误

PS C:\Windows\system32> $error[0] | fl * -force

writeErrorStream      : True
PSMessageDetails      : 
Exception             : System.Management.Automation.RemoteException: Object not found.
TargetObject          : Object not found.
CategoryInfo          : NotSpecified: (Object not found.:String) [], RemoteException
FullyQualifiedErrorId : NativeCommandError
ErrorDetails          : 
InvocationInfo        : System.Management.Automation.InvocationInfo
ScriptStackTrace      : at <ScriptBlock>, <No file>: line 33
PipelineIterationInfo : {0, 0}

If I copy the output of 如果我复制输出

Write-Host "$cmd $arg1 $source $arg2 $session $arg3 $tree"

and execute it works flawlessly 并完美执行

omnir.exe -winfs server.domain.domain:/F "server.domain.domain [/F]" -session 2015/07/01-56 -tree /folder1/folder2/folder3/test1.txt  

Below are "some" of the other variations I have tried 以下是我尝试过的其他一些“变化”

$arg1 = "-winfs server.domain.domain:/F `"server.domain.domain:[/F]`""  # tried with or without quotes, but app requires dbl qoutes
$arg2 = "-session 2015/07/01-56"
$arg3 = "-tree /folder1/folder2/folder3/test1.txt"


& omnir.exe $arg1 $arg2 $arg3

$arg1 = "-winfs server.domain.domain:/F"
$arg2 = "-session 2015/07/01-56"
$arg3 = "-tree /folder1/folder2/folder3/test1.txt"
$arg4 = "`"server.domain.domain:[/F]`""  

& omnir.exe $arg1 $arg4 $arg2 $arg3

And some more 还有更多

& omnir.exe -winfs $source -session $session -tree $tree 
Invoke-Command -ScriptBlock {param($1, $2, $3, $4, $5, $6) omnir.exe $1, $2, $3, $4, $5, $6;} -ArgumentList $arg1, $source, $arg2, $session, $arg3, $tree
Invoke-Command -FilePath 'C:\Program Files\OmniBack\bin\omnir.exe' -ArgumentList "-winfs $source", "-session $session", "-tree $tree" 
Start-Process omnir.exe -ArgumentList $arg1 $source $arg2 $session $arg3 $tree -Wait

Okay, jumped the gun before posting. 好的,在发帖前跳了枪。 Should have thought it through. 应该已经考虑透了。 This works 这有效

  $cmd = 'C:\Program Files\OmniBack\bin\omnir.exe'
  $arg1 = "-winfs"
  $sourcea = "server.domain:/$($drive)"
  $sourceb = "server.domain [/$($drive)]"
  $arg2 = "-session"
  $session = $f.FileSession -replace "_[a-zA-Z]+", "" -replace "_", "/" 
  $arg3 = "-tree"
  $tree = "$($f.FileName)"

  & $cmd $arg1 $sourcea $sourceb $arg2 $session $arg3 $tree

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM