I run the following query in SQL Server 2014:
SELECT
dp.class_desc, dp.permission_name, dp.state_desc,
ObjectName = OBJECT_NAME(major_id),
GranteeName = grantee.name, GrantorName = grantor.name
FROM
sys.database_permissions dp
JOIN
sys.database_principals grantee ON dp.grantee_principal_id = grantee.principal_id
JOIN
sys.database_principals grantor ON dp.grantor_principal_id = grantor.principal_id
And I get all the rows that I expect. I created test database users and roles and I see them.
When I run it in powershell:
(invoke-sqlcmd 'select dp.class_desc, dp.permission_name, dp.state_desc,
ObjectName = OBJECT_NAME(major_id), GranteeName = grantee.name, GrantorName = grantor.name
FROM sys.database_permissions dp
JOIN sys.database_principals grantee on dp.grantee_principal_id = grantee.principal_id
JOIN sys.database_principals grantor on dp.grantor_principal_id = grantor.principal_id -ServerInstance Blah\blah)
I don't see my test database users/roles in the output. I'm using Windows authentication. Same user is running the PowerShell command and connecting via SSMS. Also, in my PowerShell output, I see disabled accounts. I don't see when I run the query in the SSMS.
Any suggestions on how I can get the same results from PowerShell as I get from SSMS?