From f63915e178d4387433f2137c6e3ee07d37ed462a Mon Sep 17 00:00:00 2001 From: Andreas Jordan <66946165+andreasjordan@users.noreply.github.com> Date: Thu, 6 Jan 2022 11:40:14 +0100 Subject: [PATCH] Use ClearAndInitialize to improve performance (#8042) --- functions/Get-DbaDbView.ps1 | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/functions/Get-DbaDbView.ps1 b/functions/Get-DbaDbView.ps1 index 52e14ebd79..060cf46d64 100644 --- a/functions/Get-DbaDbView.ps1 +++ b/functions/Get-DbaDbView.ps1 @@ -131,6 +131,11 @@ function Get-DbaDbView { foreach ($db in $InputObject) { Write-Message -Level Verbose -Message "processing $db" + + # Let the SMO read all properties referenced in this command for all views in the database in one query. + # Downside: If some other properties were already read outside of this command in the used SMO, they are cleared. + $db.Views.ClearAndInitialize('', [string[]]('Name', 'Schema', 'IsSystemObject', 'CreateDate', 'DateLastModified')) + if ($fqtns) { $views = @() foreach ($fqtn in $fqtns) {