我在 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
我得到了我期望的所有行。我创建了测试数据库用户和角色,我看到了它们。
当我在 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)
我在输出中看不到我的测试数据库用户/角色。我正在使用 Windows 身份验证。同一用户正在运行 PowerShell 命令并通过 SSMS 进行连接。此外,在我的 PowerShell 输出中,我看到禁用的帐户。当我在 SSMS 中运行查询时,我没有看到。
关于如何从 PowerShell 获得与从 SSMS 获得的结果相同的任何建议?