PowerShell脚本在ISE中正常工作,但在PowerShell命令提示符下失败?

问题描述:

Get-SqlInstances : The term 'Get-SqlInstances' 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 C:\Users\amitk.yadav\desktop\BLDiscover_check_SQLInvtInfo.ps1:88 char:1 
+ Get-SqlInstances $server >> $OUTPUT_DIR\InstanceList.txt # listing all sql inst ... 
+ ~~~~~~~~~~~~~~~~ 
    + CategoryInfo   : ObjectNotFound: (Get-SqlInstances:String) [], CommandNotFoundException 
    + FullyQualifiedErrorId : CommandNotFoundException 

Get-Content : Cannot find path 'C:\Temp\InstanceList.txt' because it does not exist. 
At C:\Users\amitk.yadav\desktop\BLDiscover_check_SQLInvtInfo.ps1:110 char:23 
+ ForEach ($instance in Get-Content $OUTPUT_DIR\InstanceList.txt) 
+      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
+0

也许只是张贴多一点的两个错误消息 –

那么,错误说够了。它无法识别“Get-SqlInstances”函数。

也许这是在您的ISE主机配置文件中为该功能导入适当的模块。

你必须先检查它。虽然beingh在ISE主机执行以下命令:

Get-Content $($profile.AllUsersCurrentHost) 

Get-Content $($profile.CurrentUserCurrentHost)