1
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)
+                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1
  • Maybe post just a little more than two error messages Commented Aug 4, 2016 at 11:22

2 Answers 2

1

Well, the error saying enough. It can't recognize "Get-SqlInstances" function.

Perhaps it's something in your ISE host profile that imports proper module for that function.

You have to check it first. While beingh in ISE host execute following commands:

Get-Content $($profile.AllUsersCurrentHost)

or

Get-Content $($profile.CurrentUserCurrentHost)
Sign up to request clarification or add additional context in comments.

Comments

0

I have similar issue. My Powershell script does a quick check to test a connection to a SQL Server database. It uses Invoke-sqlcmd. It works from the command prompt regularly. In fact it just now worked 3 times at the command prompt, then it just stopped. There have been no changes and code is referenced below. Yet it still works in ISE. I can't figure out why it just stopped. Any suggestions would be welcome.-

The code for the Powershell script is very simple. #================================================================================== #== The script code is:

param(
 [Parameter(Mandatory=$true)][string]$csvFileName
,[Parameter(Mandatory=$true)][string]$SQLServer
,[Parameter(Mandatory=$true)][string]$SQLDBName
,[Parameter(Mandatory=$true)][string]$Username
,[Parameter(Mandatory=$true)][String]$Password
)
$ConnectTest = 'SELECT DBName = DB_NAME()'

Invoke-Sqlcmd -ServerInstance $SQLServer -Database $SQLDBName -Username $Username -Password $Password -Query $ConnectTest -Verbose

#================================================================================== #== When I use Powershell ISE, the script works:

.\ArgTest01.ps1 -csvFileName 'test.csv' -SQLServer '<MyServer>' -SQLDBName 'test' -Username 'test' -Password 'T35t3r_MCT3st3rFac3'

DBName
------
test

#================================================================================== #== However when I use the the following at the command shell I get a set of errors:

powershell.exe -File ArgTest01.ps1 -csvFileName 'test.csv' -SQLServer '<MyServer>' -SQLDBName 'test' -Username 'test' -Password 'T35t3r_MCT3st3rFac3'

#================================================================================== #== The Errors:

Invoke-Sqlcmd : A network-related or instance-specific error occurred while establishing a connection to SQL Server.
The server was not found or was not accessible.
Verify that the instance name is correct and that SQL Server is configured to allow remote connections.
(provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)

At C:\Apps\Dropbox\Code\Powershell\CsvSqlimport\ArgTest.ps1:22 char:1
+ Invoke-Sqlcmd -ServerInstance $SQLServer -Database $SQLDBName -Userna ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Invoke-Sqlcmd], SqlException
    + FullyQualifiedErrorId : SqlExectionError,Microsoft.SqlServer.Management.PowerShell.GetScriptCommand

Invoke-Sqlcmd :
At C:\Apps\Dropbox\Code\Powershell\CsvSqlimport\ArgTest.ps1:22 char:1
+ Invoke-Sqlcmd -ServerInstance $SQLServer -Database $SQLDBName -Userna ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ParserError: (:) [Invoke-Sqlcmd], ParserException
    + FullyQualifiedErrorId : ExecutionFailureException,Microsoft.SqlServer.Management.PowerShell.GetScriptCommand

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.