powershell

时间:2015-07-02 16:13:35

标签: powershell powershell-v3.0

我在执行应用时遇到问题,我需要将参数传递给。我认为问题与参数的一个值有关,但我不确定。

我已经添加了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 

这是我得到的错误

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}

如果我复制

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

并执行它完美无缺地

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

以下是&#34;一些&#34;我试过的其他变种

$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

还有一些

& 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

1 个答案:

答案 0 :(得分:0)

好的,在张贴之前跳了一下枪。本来应该考虑一下。这工作

  $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