控制台应用程序在Powershell中不起作用

我已经inheritance了Windows Server 2003 r2框。 我有一个Powershell脚本,我需要在机器上运行,但有些系统似乎非常错误。 例如,打开Powershell控制台并inputipconfig会得到以下响应:

 The term 'ipconfig' is not recognized as a cmdlet, function, operable program, or script file. Verify the term and try again. 

我的Powershell脚本正试图调用pscp.exe(来自putty项目),并得到与上面相同的错误。

我的第一个怀疑是这是一个path问题,果然,当我打开环境variables窗口时, PATHvariables甚至不存在。 所以我创build了它,并确保包含pscp的目录在那里列出。 还没有骰子。

在cmd.exe中运行相同的命令(ipconfig或pscp),只要向PATHvariables(%SystemRoot%\ system32;%SystemRoot%;%SystemRoot%\ System32 \ Wbem;)添加了一些基本条目,就可以按预期工作。

Powershell中的$env:path返回PATHvariables的值,但是powershell仍然不会执行那些目录中的程序。 get-host | select version get-host | select version返回1.0.0.0。

任何提示?

这听起来像你的环境有点混乱。 这里有几个额外的故障排除步骤,希望其中一个将提供更多有用的信息:

尝试使用完整path运行该命令:c:\ windows \ system32 \ ipconfig.exe

尝试invoke-expression cmdlet:

 invoke-expression -command "ipconfig" 

要么:

 invoke-expression -command "c:\windows\system32\ipconfig.exe" 

尝试使用.Net进程提供程序(您将无法看到调用的结果,但它会提供一些有用的信息):

 [System.Diagnostics.Process]::Start("c:\windows\system32\ipconfig.exe") 

尝试运行powershell -NoProfile ,看看是否powershell -NoProfile 。 如果是这样。 那么你的问题是configuration文件脚本,你可以用notepad $profile编辑。

尝试打开一个CMD窗口并在那里运行ipconfig 。 如果它在CMD中工作,但不在PowerShell中,那么比较每个中find的环境。 最简单的方法可能是在CMD中运行set ,并在PowerShell窗口中运行cmd.exe /C set ,并比较结果。

用其他环境variables来expression你的PATH是有点奇怪的。 我想知道这是否会让事情变得不可靠。

例如,下面是我期望在PATHvariables中看到的(假设C:是您的主要安装驱动器):

 PATH=C:\Windows\System32;C:\Windows;C:\Windows\System32\Wbem;