术语' xsd'不被识别为cmdlet,函数,脚本文件或可操作程序的名称

时间:2014-11-01 19:30:14

标签: powershell xsd cmdlet

执行以下脚本时(这是实际脚本的一部分),我在powershell中收到以下错误消息:

The term 'xsd' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:10 char:3

$xsds = ls *.xsd | %{ $_.Name }

if ($xsds.Count -eq 0) { exit }

# Add '.\' to last file name, see http://stackoverflow.com/questions/906093/xsd-exe-output-filename
$last = $xsds | select -last 1
$last = '.\' + $last
$xsds[$xsds.Count - 1] = $last

& xsd $xsds /c /n:OutputFolder

我是否需要安装Powershell以便能够先运行'xsd'cmdlet?

$env:Path的输出:

PS C:\Users\Administrator\Desktop\New> $env:Path
C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Mi
crosoft\Web Platform Installer\;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\110\Tools\Binn\;C:\Program Files
(x86)\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files\Micro
soft SQL Server\120\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\120\Tools\Binn\ManagementStudio\;C:\Program F
iles (x86)\Microsoft SQL Server\120\DTS\Binn\;C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit\
PS C:\Users\Administrator\Desktop\New>

文件夹中提供了xsd.exe

C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 Tools

C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 Tools\x64

1 个答案:

答案 0 :(得分:3)

您列出的路径不是PATH环境变量的一部分。所以这给你留下了两个选择。将目录添加到路径或仅通过其完整路径引用exe。

& "C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 Tools\xsd.exe" $xsds /c /n:OutputFolder

如果您想更改路径,可以像这样更新它们

$env:Path += ";C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 Tools"

如果您需要x64路径,只需更新字符串。