我是编程新手,我有这样的代码,
select-azuresubscription -SubscriptionName "Pay-As-You-Go"
$Sqldatabaseserver=Get-AzureSqlDatabaseServer
$ServerName=@($Sqldatabaseserver|select -ExpandProperty ServerName)
$ServerName
for($y = 0; $y -le $ServerName.Length -1; $y++){
$PayAsYouGoServerNames = $ServerName[$y]
Get-AzureSqlDatabase -ServerName $PayAsYouGoServerNames|select *,@{Name='ServerName';Expression={$PayAsYouGoServerNames}}
}
output1是
dog
cat
Bird
Id : 1
Name : Taro
ServerName : dog
Id : 2
Name : Hello
ServerName : dog
Id : 3
Name : World
ServerName : Cat
Id : 4
Name : Hanako
ServerName : Bird
Id : 5
Name : Yuto
ServerName : Bird
当我改为喜欢这个时
select-azuresubscription -SubscriptionName "Pay-As-You-Go"
$Sqldatabaseserver=Get-AzureSqlDatabaseServer
$ServerName=@($Sqldatabaseserver|select -ExpandProperty ServerName)
$ServerName
for($y = 0; $y -le $ServerName.Length -1; $y++){
$PayAsYouGoServerNames = $ServerName[$y]
$s = Get-AzureSqlDatabase -ServerName $PayAsYouGoServerNames|select *,@{Name='ServerName';Expression={$PayAsYouGoServerNames}}
}
$s
显示
Id : 4
Name : Hanako
ServerName : Bird
Id : 5
Name : Yuto
ServerName : Bird
这只显示最后一个数组元素= Bird
我想在{}之外使用$ s,但我希望显示整个$ s,如output1
我该如何解决这个问题?
非常感谢