0

我有这个 PowerShell 脚本:

$QUERY = "SELECT name FROM sys.databases";    
$Databases = invoke-sqlcmd -serverinstance "SQLInstanceName" -database "master" -Query $QUERY

foreach ($dbname in $Databases)
{
    $dbname
}  

假设我想要数据库的恢复模型如下,我如何将它们放入 PowerShell 变量中?

$QUERY = "SELECT name, recovery_model_desc FROM sys.databases";
4

1 回答 1

0

可能是你在寻找

$QUERY = "SELECT * from sys.databases";    
$Databases = invoke-sqlcmd -serverinstance "SQLInstanceName" -database "master" -Query $QUERY

# This is just to print the individual value of column (name and recovery_model)
$Databases | ForEach {
    Write-Host '----------------------------------------'
    Write-Host 'Database :' $_.name
    Write-Host 'Recovery model :' $_.recovery_model
    Write-Host '----------------------------------------'
    Write-Host
}

# This will give you name and recovery_model of database
$Databases | Select name, recovery_model
于 2020-07-01T22:57:30.873 回答