Skip to content

Commit

Permalink
some testing of AllInstanceInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
SQLDBAWithABeard committed Apr 25, 2022
1 parent 34f2ca1 commit 756d2ff
Show file tree
Hide file tree
Showing 3 changed files with 852 additions and 0 deletions.
44 changes: 44 additions & 0 deletions Get-AllInstanceInfo testing.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Get-AllInstanceInfo testing

# so the initial load doesnt skew the figures
ipmo dbatools
function prompt { Write-Host "pwsh >" -NoNewline; ' '}

# load the original function
. .\originalGet-AllInstanceInfo.ps1
. .\NewGet-AllInstance.ps1

# Lets check just the spconfigure ones :D
$originalCode = {
$password = ConvertTo-SecureString "dbatools.IO" -AsPlainText -Force
$cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList "sqladmin", $password

$Sqlinstances = 'localhost,7401', 'localhost,7402', 'localhost,7403'
$smos = Connect-DbaInstance -SqlInstance $Sqlinstances -SqlCredential $cred

foreach($smo in $smos){
Get-AllInstanceInfo -Instance $smo -Tags 'DefaultTrace','OleAutomationProceduresDisabled','CrossDBOwnershipChaining','ScanForStartupProceduresDisabled','RemoteAccessDisabled','SQLMailXPsDisabled' -There $true
}
}

# Lets check just the spconfigure ones :D
$NewCode = {
$password = ConvertTo-SecureString "dbatools.IO" -AsPlainText -Force
$cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList "sqladmin", $password

$Sqlinstances = 'localhost,7401', 'localhost,7402', 'localhost,7403'
$smos = Connect-DbaInstance -SqlInstance $Sqlinstances -SqlCredential $cred

foreach($smo in $smos){
NewGet-AllInstanceInfo -Instance $smo -Tags 'DefaultTrace','OleAutomationProceduresDisabled','CrossDBOwnershipChaining','ScanForStartupProceduresDisabled','RemoteAccessDisabled','SQLMailXPsDisabled' -There $true
}
}

$originalCodetrace = Trace-Script -ScriptBlock $originalCode
$NewCodetrace = Trace-Script -ScriptBlock $NewCode

$originalCodeMessage = "With original Code it takes {0} MilliSeconds" -f $originalCodetrace.StopwatchDuration.TotalMilliseconds
$NewCodeMessage = "With New Code it takes {0} MilliSeconds" -f $NewCodetrace.StopwatchDuration.TotalMilliseconds

Write-PSFMessage -Message $originalCodeMessage -Level Significant
Write-PSFMessage -Message $NewCodeMessage -Level Significant
49 changes: 49 additions & 0 deletions NewGet-AllInstance.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
function NewGet-AllInstanceInfo {
# Using the unique tags gather the information required
Param($Instance, $Tags)

#clear out the default initialised fields
$smo.SetDefaultInitFields([Microsoft.SqlServer.Management.Smo.Server], $false)
$smo.SetDefaultInitFields([Microsoft.SqlServer.Management.Smo.Database], $false)
$smo.SetDefaultInitFields([Microsoft.SqlServer.Management.Smo.Login], $false)
$smo.SetDefaultInitFields([Microsoft.SqlServer.Management.Smo.Agent.Job], $false)

# COnfiguration cannot have default init fields :-)
$configurations = $false

# Using there so that if the instance is not contactable, no point carrying on with gathering more information
switch ($tags) {

'DefaultTrace' {
$configurations = $true
}
'OleAutomationProceduresDisabled' {
$configurations = $true
}
'CrossDBOwnershipChaining' {
$configurations = $true
}
'ScanForStartupProceduresDisabled' {
$configurations = $true
}
'RemoteAccessDisabled' {
$configurations = $true
}
'SQLMailXPsDisabled' {
$configurations = $true
}

Default { }
}

# set the default init fields for all the tags

#build the object

$testInstanceObject = [PSCustomObject]@{
ComputerName = $smo.ComputerName
InstanceName = $smo.DbaInstanceName
Configuration = if ($configurations) { $Smo.Configuration }else { $null }
}
return $testInstanceObject
}
Loading

0 comments on commit 756d2ff

Please sign in to comment.