0

This seems like a simple problem but I am unable to fix it: Running command in shell returns result


C:\Windows\system32>dfsutil link "\\server.domain.com\DFSRootname\Sharename"

Link Name="Sharename" State="OK" Timeout="1800"
        Target="\\server1\sharename" State="ONLINE"  [Site: site1]
        Target="\\server2\sharename" State="OFFLINE"  [Site: site2]

Done processing this command.

Trying to do the same in powershell

PS>
$path = "\\server.domain.com\DFSRootname\Sharename"
$dfsutil = "dfsutil"
$option = "link"
PS C:\Windows\system32> Invoke-Expression "$dfsutil $option $path"

DFS Utility Version 5.2 (built on 5.2.3790.3959)
Copyright (c) Microsoft Corporation. All rights reserved.

Unrecognized option "ink"

Why does it complain about link option?

Sergei
  • 387
  • 1
  • 6
  • 16
  • Why are you using `Invoke-Expression` which just evaluates PowerShell expressions? Did `dfsutil link $path` all by itself not work? – jpmc26 Jun 13 '13 at 10:40
  • yes. It yields same error – Sergei Jun 13 '13 at 10:43
  • Sorry, not sure what did you mean 'just evaluates'? Technet says 'The Invoke-Expression cmdlet provides one way to run a script from within Windows PowerShell': http://technet.microsoft.com/en-us/library/ee176880.aspx – Sergei Jun 13 '13 at 10:49
  • `Invoke-Expression` invokes *PowerShell* expressions. SS64 puts it more simply: http://ss64.com/ps/invoke-expression.html. So there's no difference between `Invoke-Expression "dfsutil link $path"` and `dfsutil link $path`, except for maybe some quoting issues that could be created in the `Invoke-Expression` way if `$path` has spaces. – jpmc26 Jun 13 '13 at 11:04
  • Thank you for your comment.I may have misunderstood you. From your first comment that had 'just evaluates' phrase it looked like Invoke-Expression does just that - only evaluates expression and does not executes the script. Hopefuly someone will come up with a solution soon. – Sergei Jun 13 '13 at 13:02

2 Answers2

2

Try the call operator (e,g '&'):

& $dfsutil $option $path

or

& $dfsutil "$option" "$path"
Shay Levy
  • 121,444
  • 32
  • 184
  • 206
0

Seems like installation problem with my Windows 7 PS3 install. Command works fine on Windows 2008 R2 host with PS2

Sergei
  • 387
  • 1
  • 6
  • 16