Reputation: 215
I am new to Powershell and I want to get all the usernames in a Datatable in Powershell. I am trying to execute the below two lines but I am getting the error below:
$query = "select * from sys.database_principals"
$databases = invoke-Sqlcmd -Query $query -ServerInstance "ServerName\dbName" -SuppressProviderContextWarning
Error:
+ ... databases = invoke-Sqlcmd -Query $query -ServerInstance
+
+ CategoryInfo : NotSpecified: (:) [Invoke-Sqlcmd], FileNotFoundException
+ FullyQualifiedErrorId : System.IO.FileNotFoundException,Microsoft.SqlServer.Management.PowerShell.GetScriptCommand
Can anyone please help me out?
Upvotes: 1
Views: 93
Reputation: 394
If you are running this on the same server as the Instance, Then Run it this way:
$query = "select * from sys.database_principals"
$databases = invoke-Sqlcmd -Query $query -SuppressProviderContextWarning
$databases
Upvotes: 1