Skip to content

Commit 80c8fdd

Browse files
DbaDeprecatedFeature - Refactor Get- and remove Test- (#9719)
1 parent 986946f commit 80c8fdd

7 files changed

+20
-158
lines changed

bin/dbatools-index.json

-9.2 KB
Binary file not shown.

dbatools.psd1

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,6 @@
679679
'Test-DbaDbOwner',
680680
'Test-DbaDbQueryStore',
681681
'Test-DbaDbRecoveryModel',
682-
'Test-DbaDeprecatedFeature',
683682
'Test-DbaDiskAlignment',
684683
'Test-DbaDiskAllocation',
685684
'Test-DbaDiskSpeed',

dbatools.psm1

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,6 @@ if ($PSVersionTable.PSVersion.Major -lt 5) {
659659
'Invoke-DbatoolsRenameHelper',
660660
'Measure-DbatoolsImport',
661661
'Get-DbaDeprecatedFeature',
662-
'Test-DbaDeprecatedFeature'
663662
'Get-DbaDbFeatureUsage',
664663
'Stop-DbaEndpoint',
665664
'Start-DbaEndpoint',

public/Get-DbaDeprecatedFeature.ps1

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
function Get-DbaDeprecatedFeature {
22
<#
33
.SYNOPSIS
4-
Displays information relating to deprecated features for SQL Server 2005 and above.
4+
Displays usage information relating to deprecated features for SQL Server 2005 and above.
55
66
.DESCRIPTION
7-
Displays information relating to deprecated features for SQL Server 2005 and above.
7+
Displays usage information relating to deprecated features for SQL Server 2005 and above.
8+
More information: https://learn.microsoft.com/en-us/sql/relational-databases/performance-monitor/sql-server-deprecated-features-object
89
910
.PARAMETER SqlInstance
1011
The target SQL Server instance
@@ -35,12 +36,12 @@ function Get-DbaDeprecatedFeature {
3536
.EXAMPLE
3637
PS C:\> Get-DbaDeprecatedFeature -SqlInstance sql2008, sqlserver2012
3738
38-
Check deprecated features for all databases on the servers sql2008 and sqlserver2012.
39+
Get usage information relating to deprecated features on the servers sql2008 and sqlserver2012.
3940
4041
.EXAMPLE
4142
PS C:\> Get-DbaDeprecatedFeature -SqlInstance sql2008
4243
43-
Check deprecated features on server sql2008.
44+
Get usage information relating to deprecated features on server sql2008.
4445
4546
#>
4647
[CmdletBinding()]
@@ -51,14 +52,6 @@ function Get-DbaDeprecatedFeature {
5152
[switch]$EnableException
5253
)
5354

54-
begin {
55-
$sql = "SELECT SERVERPROPERTY('MachineName') AS ComputerName,
56-
ISNULL(SERVERPROPERTY('InstanceName'), 'MSSQLSERVER') AS InstanceName,
57-
SERVERPROPERTY('ServerName') AS SqlInstance, object_name, instance_name as DeprecatedFeature, object_name as ObjectName, instance_name as deprecated_feature, cntr_value as UsageCount
58-
FROM sys.dm_os_performance_counters WHERE object_name like '%Deprecated%'
59-
and cntr_value > 0 ORDER BY deprecated_feature"
60-
}
61-
6255
process {
6356
foreach ($instance in $SqlInstance) {
6457
try {
@@ -67,12 +60,16 @@ function Get-DbaDeprecatedFeature {
6760
Stop-Function -Message "Failure" -Category ConnectionError -ErrorRecord $_ -Target $instance -Continue
6861
}
6962

70-
try {
71-
$server.Query($sql) | Select-DefaultView -Property ComputerName, InstanceName, SqlInstance, ObjectName, DeprecatedFeature, UsageCount
72-
} catch {
73-
Stop-Function -Message "Failure" -ErrorRecord $_ -Target $instance -Continue
63+
$usedDeprecatedFeatures = $server.Query("SELECT LTRIM(RTRIM(instance_name)) AS DeprecatedFeature, cntr_value AS UsageCount FROM sys.dm_os_performance_counters WHERE object_name LIKE '%SQL%Deprecated Features%' AND cntr_value > 0")
64+
foreach ($feature in $usedDeprecatedFeatures) {
65+
[PSCustomObject]@{
66+
ComputerName = $server.ComputerName
67+
InstanceName = $server.ServiceName
68+
SqlInstance = $server.DomainInstanceName
69+
DeprecatedFeature = $feature.DeprecatedFeature
70+
UsageCount = $feature.UsageCount
71+
}
7472
}
75-
7673
}
7774
}
7875
}

public/Test-DbaDeprecatedFeature.ps1

Lines changed: 0 additions & 110 deletions
This file was deleted.

tests/Get-DbaDeprecatedFeature.Tests.ps1

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,15 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' {
1414
}
1515

1616
Describe "$commandname Integration Tests" -Tags "IntegrationTests" {
17+
BeforeAll {
18+
# Use a deprecated feature
19+
$null = Invoke-DbaQuery -SqlInstance $TestConfig.instance1 -Query 'SELECT * FROM sys.sysdatabases' -EnableException
20+
}
21+
1722
Context "Gets Deprecated Features" {
1823
$results = Get-DbaDeprecatedFeature -SqlInstance $TestConfig.instance1
1924
It "Gets results" {
20-
$results | Should Not Be $null
25+
$results.DeprecatedFeature | Should -Contain 'sysdatabases'
2126
}
2227
}
2328
}

tests/Test-DbaDeprecatedFeature.Tests.ps1

Lines changed: 0 additions & 28 deletions
This file was deleted.

0 commit comments

Comments
 (0)