Powershell - 不接受外部命令的参数

时间:2013-06-13 10:33:17

标签: powershell dfs

这似乎是一个简单的问题,但我无法修复它: 在shell中运行命令返回结果


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.

尝试在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"

为什么抱怨链接选项?

2 个答案:

答案 0 :(得分:1)

尝试呼叫操作员(e,g'&'):

& $dfsutil $option $path

& $dfsutil "$option" "$path"

答案 1 :(得分:0)

看起来像我的Windows 7 PS3安装的安装问题。命令在带有PS2的Windows 2008 R2主机上正常工作