微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

将System.Object []'转换为类型'System.String

如何解决将System.Object []'转换为类型'System.String

我正在尝试创建一个脚本,该脚本显示Azure sql服务器的防火墙中的IP设置,为此,我正在使用以下代码

$sqlservers = Get-AzsqlServer 

foreach ($server in $sqlservers)
{

 $sqlserver = $sqlservers.ServerName
 $sqlRg = $sqlservers.ResourceGroupName
 $firewallIP = Get-AzsqlServerFirewallRule -ServerName $sqlserver -ResourceGroupName $sqlRg
  
}

但是我收到此错误

Get-AzsqlServerFirewallRule : Cannot convert 'System.Object[]' to the type 'System.String' required by parameter 'ServerName'. Specified method is not supported.
At line:11 char:56
+ ... rewallIP = Get-AzsqlServerFirewallRule -ServerName $sqlserver -Resour ...
+                                                        ~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Get-AzsqlServerFirewallRule],ParameterBindingException
    + FullyQualifiedErrorId : CannotConvertArgument,Microsoft.Azure.Commands.sql.FirewallRule.Cmdlet.GetAzuresqlServerFirewallRule



Get-AzsqlServerFirewallRule : Cannot convert 'System.Object[]' to the type 'System.String' required by parameter 'ServerName'. Specified method is not supported.
At line:11 char:56
+ ... rewallIP = Get-AzsqlServerFirewallRule -ServerName $sqlserver -Resour ...
+                                                        ~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Get-AzsqlServerFirewallRule],Microsoft.Azure.Commands.sql.FirewallRule.Cmdlet.GetAzuresqlServerFirewallRule

家里有人可以帮助我

预先感谢

解决方法

您使用服务器数组($ sqlservers)分配了$ sqlserver和$ sqlRg,需要将其更改为$ server

$sqlservers = Get-AzSqlServer 

foreach ($server in $sqlservers)
{

 $sqlserver = $server.ServerName
 $sqlRg = $server.ResourceGroupName
 $firewallIP = Get-AzSqlServerFirewallRule -ServerName $sqlserver -ResourceGroupName $sqlRg
  
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。