[英]issues with Invoke-Command in powershell
我在執行應用程序時遇到問題,需要將參數傳遞給該應用程序。 我相信問題與參數的值之一有關,但我不確定。
我在路徑中添加了“ 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
以下是我嘗試過的其他一些“變化”
$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
好的,在發帖前跳了槍。 應該已經考慮透了。 這有效
$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.