首页 > 解决方案 > 使用 Powershell 比较两个 SQL 实例配置值

问题描述

我正在运行下面的两个 Powershell 脚本来比较两个 SQL Server 实例配置并返回差异。感谢原作者。我希望输出格式如下所示,仅显示配置值不同的配置值。现在,它显示来自 Instance1 的所有配置值,并且仅显示 Instance2 的配置值不同的地方。

#https://sqldbawithabeard.com/2017/02/
$WinSQl1 = 'SQLInstance1'
$WinSQl2 = 'SQLInstance2'
$Win1SPConfigure = Get-DbaSpConfigure -SqlInstance  $WinSQl1
$Win2SPConfigure = Get-DbaSpConfigure -SqlInstance  $WinSQl2
$propcompare = foreach ($prop in $Win1SPConfigure) {
[pscustomobject]@{
Config = $prop.DisplayName
$WinSQl1 = $prop.RunningValue
$WinSQl2 = $Win2SPConfigure | Where DisplayName -eq $prop.DisplayName | Where RunningValue -ne $prop.RunningValue | Select -ExpandProperty RunningValue
}
}
$propcompare | ogv


#https://therestisjustcode.wordpress.com/2017/09/12/t-sql-tuesday-94-automating-configuration-comparison/
$Server1 = Get-DbaSpConfigure -SqlInstance 'SQLInstance1'
$Server2 = Get-DbaSpConfigure -SqlInstance 'SQLInstance2'
Compare-Object -ReferenceObject $Server1 -DifferenceObject $Server2 -property ConfigName,RunningValue|Sort-Object ConfigName;

期望的输出

在此处输入图像描述

标签: compare

解决方案


推荐阅读