有人可以帮我指出为什么我的脚本没有在服务器列表中循环并且没有将所有数据插入sql表吗?
$SQLserverDB = @()
$SQLserverDB = get-content "D:\Temp\servers.txt"
foreach ($SQLserver in $SQLserverDB) {
$server = New-Object Microsoft.sqlserver.management.smo.server($SQLserver)
Write-Host "--Server List:"$server"---" -ForegroundColor Yellow
foreach ($db in $Server.Databases) {
$dbobj = New-Object PSObject -Property ([ordered]@{
Instance_Name = $db.Parent
Database_Name = $db.Name
Database_ID = $db.id
Active = $db.Status
DateStamp = $db.CreateDate
Owner = $db.Owner
Compatibility_Level = $db.compatibilitylevel
Recovery_Model = $db.recoverymodel
DB_Size_MB = [Math]::round($db.size, 2)
}
)
}
}
$dt = Out-DbaDataTable -InputObject $dbobj
Write-SqlTableData -ServerInstance localhost -DatabaseName DBA_Central -SchemaName dbo -TableName database_masters2 -InputData $dt