Public/Get-IndexCompare.ps1
<#
.SYNOPSIS Executes the collector process .DESCRIPTION Invoke-TheKraken is the main process which collects metadata information and stores it into the repository database .PARAMETER Environment Must match values set on the column environment on the sql_instances table. It executes the process against target sql servers that meet the environment criteria .PARAMETER Name Must match instance_name column values on the sql_instances table. It executes the process against specific target sql servers pass in this comma separated list. SQL Instance must exist in the sql_instances table .PARAMETER All If this Switch is used, the process is executed against all Active SQL Server Instances listed on the sql_instances table .PARAMETER Credential Credential [PSCredential] - If not specified it uses Trusted Authentication, else it will SQL Authentication .PARAMETER Throttle Number of concurrent running runspace jobs which are allowed at a time. .INPUTS Credential [PSCredential] .OUTPUTS None .EXAMPLE Executes the process just against DEV Target Servers Invoke-TheKraken -Environment "DEV" .EXAMPLE Executes the process just against All Target Servers Invoke-TheKraken -All .LINK https://github.com/dokier/Kraken #> function Get-IndexCompare { param ( <#[Parameter(Mandatory = $true)] [string[]]$Server, [Parameter(Mandatory = $true)] [string[]]$Database, #> [Parameter(Mandatory = $true)] [string[]]$runCount, [System.Management.Automation.Credential()] [PSCredential] $Credential = [System.Management.Automation.PSCredential]::Empty ) begin { <#$script:PSConfigPath = (Get-Item $PSScriptRoot).Parent.FullName $json = Get-Content -Path $script:PSConfigPath\dbidx.config.json -Raw | ConvertFrom-Json $connDetails = @{ Server = $json.dbsettings.server Database = $json.dbsettings.database }#> $connDetails = Get-ConnectionString $ModulePath = (Split-Path $PSScriptRoot) $GetIndexInfo = "$ModulePath\Private\SQLScripts\Get-IndexCompare.sql" $credSplat = @{} if ($Credential -ne [System.Management.Automation.PSCredential]::Empty) { #$credSplat['Credential'] = $Credential $credSplat.Credential = $Credential } } process { #[string]$serverList = $null #[string]$databaseList = $null #$serverList = "'$($Server -join "','")'" #$databaseList = "'$($Database -join "','")'" #$sqlParameters = "serverList=$($serverList)", "databaseList=$($databaseList)", "runCount=$($runCount)" $sqlParameters = "runCount=$($runCount)" $QResult = Invoke-Sqlcmd @credSplat -ServerInstance $connDetails.Server -Database $connDetails.Database -InputFile $GetIndexInfo -Variable $sqlParameters $QResult = $QResult | Select-Object * -ExcludeProperty RowError, RowState, Table, ItemArray, HasErrors $htmldoc = ConvertTo-Html2 -objArray $QResult -headermsg "Index Comparison" -begindoc -enddoc $htmldoc | Out-File indexes.html return $htmldoc } # Process } |