术语“xsd”未被识别为 cmdlet、函数、脚本文件或可运行程序的名称

SeT*_*ToY 1 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
Run Code Online (Sandbox Code Playgroud)

是否需要安装 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>
Run Code Online (Sandbox Code Playgroud)

一个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

Mat*_*att 5

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

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

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

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

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