March 5, 2015 at 12:18 pm
Add-PSSnapin : No snap-ins have been registered for Windows PowerShell version
2.
At line:1 char:13
+ add-pssnapin <<<< SqlServerCmdletSnapin100;
+ CategoryInfo : InvalidArgument: (SqlServerCmdletSnapin100:Strin
g) [Add-PSSnapin], PSArgumentException
+ FullyQualifiedErrorId : AddPSSnapInRead,Microsoft.PowerShell.Commands.Ad
dPSSnapinCommand
Thanks.
March 5, 2015 at 11:49 pm
Please could you add the command that you are attempting to execute along with the output.
Gaz
-- Stop your grinnin' and drop your linen...they're everywhere!!!
March 6, 2015 at 10:41 am
Thanks for your response.
My query is:
$instanceNameList = Get-Content "C:\Powershell\serverlist.txt"
$results = @()
foreach($instanceName in $instanceNameList)
{
$results += Invoke-Sqlcmd `
-Query "select SERVERPROPERTY('ServerName') as Server, count(*) as 'DB Count' from sys.databases" `
-ServerInstance $instanceName
}
# print results
$results | Format-Table -autosize
Also, I have the below environment path setup in my system:
%SystemRoot%\system32\WindowsPowerShell\v1.0\Modules\;C:\Program Files (x86)\Microsoft SQL Server\110\Tools\PowerShell\Modules
Error Message:
The term 'Invoke-Sqlcmd' 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:6 char:34
+ $results += Invoke-Sqlcmd <<<< `
+ CategoryInfo : ObjectNotFound: (Invoke-Sqlcmd:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Thanks.
March 6, 2015 at 12:20 pm
For earlier versions of PowerShell you needed to manually add snap-ins. There is the SQL Server PowerShell command line where you don't have to (memory fails me what it is called - if I remember I'll post again).
Gaz
-- Stop your grinnin' and drop your linen...they're everywhere!!!
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply