使用read-sqltabledata读取azsql表的同时,使用Azure AD帐户进行身份验证
连接到?
$srv = new-object ('Microsoft.SqlServer.Management.Smo.Server') "<>.database.windows.net"
$srv.ConnectionContext.LoginSecure = $false
$srv.ConnectionContext.Authentication = [Microsoft.SqlServer.Management.Common.SqlConnectionInfo+AuthenticationMethod]::ActiveDirectoryPassword
$srv.ConnectionContext.Login = "<>@<>.onmicrosoft.com"
$srv.ConnectionContext.Password = "<>"
$srv.ConnectionContext.Connect()
错误:
MethodInvocationException:异常调用“连接”使用“ 0”参数
: /lealen.microsoft.com/en-us/dotnet/api/microsoft.sqlserver.management.common.common.sqlconnectioninfo.authenticationmethod?view = sql-smo-160 。 I'm trying to run
Read-SqlTableData -InputObject $srv.Databases["TestDB"].Tables["TestTable"] -TopN 5
期望使用 read-Sqltabledata
在AZSQL上为Azad 用户 ID上的答案代码 ID。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
正如亲自讨论的,这只是因为 Read-SqlTableData 尚未更新以支持 -AccessToken 参数。
我已经收到了一些对其他 cmdlet 的请求...所以我会尽力尽快获取它。
As discussed in person, this is just because the Read-SqlTableData has not been updated (yet) to support an -AccessToken parameter.
I've already had a few requests for other cmdlets as well... so I'll try to get it as soon as I can.
请确保登录为管理员。用户必须具有Azure Ad Admin角色才能连接服务器。
并确保用户从Azure Portal iam 访问控制中具有 diveTory读者角色。
另外,请确保您已为SQL Server分配了AAD管理员。
尝试在Azure AD中创建服务主体(如果尚未存在),然后给予DB_READER或DB_WRITER或授予的DB_owner权限。
或如果需要(如果
需要)或所有者许可(如果需要
)或 使用服务主体在Azure SQL DB中使用服务主体创建Azure AD用户 -Azure SQL数据库| Microsoft Docs
请检查下面的参考文献:
使用Active Directory集成身份验证-Stack Overflow
PowerShell-堆叠溢出
Please make sure to login as administrator .The user must have azure ad admin role for server to connect.
And make sure the user has diretory readers role from azure portal IAM access control.
Also Ensure that you've assigned an AAD admin for the SQL Server.
Try to create a service principal in azure ad if not already present and then give db_reader or db_writer or db_owner permissions granted .
or write permission if required
Or owner permission if required
Or Create Azure AD users in azure sql DB using service principals - Azure SQL Database | Microsoft Docs
Please check below references:
using Active Directory Integrated Authentication - Stack Overflow
Powershell - Stack Overflow
参数已在中添加到cmdlet中模块/sqlserver/?view = sqlserver-ps“ rel =“ nofollow noreferrer”> sqlserver模块。
输出
An
AccessToken
parameter has been added to the cmdlet in version22.0.59
of the SqlServer Module.Output