2

When executing the following script (this is a part of the actual script), I'm getting the following error message in 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

Are there some requirements for Powershell that I need to install to be able to run the 'xsd' cmdlet first?

The output of $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>

An xsd.exe is available in the folders:

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

SeToY
  • 5,777
  • 12
  • 54
  • 94
  • Is XSD an exe file somewhere on your system? You can check `$env:Path` to see if that path is there. XSD is not a powershell cmdlet I am familiar with. – Matt Nov 01 '14 at 19:45
  • @Matt I've added the requested information into the post. – SeToY Nov 01 '14 at 19:51
  • `xsd` is not a cmdlet. Just exactly like the error message tells you. Try believing the error message. – John Saunders Nov 01 '14 at 19:55

1 Answers1

5

The paths you have listed are not part of your PATH environment variable. So that leaves you with two options. Add the directories to path or just reference the exe by its full path.

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

If you want to change your paths you could update them like this

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

If you need x64 paths just update the strings.

Matt
  • 45,022
  • 8
  • 78
  • 119