May 17, 2026, 11:40 PM

This commit is contained in:
Paweł Domański
2026-05-18 06:40:19 +00:00
commit 64944cf004
896 changed files with 310709 additions and 0 deletions
@@ -0,0 +1,37 @@
Param(
[parameter(Mandatory=$true)]
[ValidateSet('CH','PL','SE','NL','DK','NO','DE')]
[String] $envCountry
)
try{
Set-DbatoolsInsecureConnection -SessionOnly
. .\..\.env\dbadmin.ps1
if($envCountry -eq 'CH'){
Write-Output "Loading Switzerland Environment Settings"
. .\..\.env\Import-envCH.ps1
$country = 'Switzerland'
}
if($envCountry -eq 'SE'){
Write-Output "Loading Swidish Environment Settings"
. .\.env\Import-envSE.ps1
$country = 'Sweden'
}
if($envCountry -eq 'PL'){
Write-Output "Loading Swidish Environment Settings"
. .\.env\Import-envPL.ps1
$country = 'Poland'
}
if($envCountry -eq 'NO'){
Write-Output "Loading Swidish Environment Settings"
. .\.env\Import-envNO.ps1
$country = 'Norway'
}
if($envCountry -eq 'DE'){
Write-Output "Loading Germany Environment Settings"
. .\.env\Import-envDE.ps1
$country = 'Germany'
}
}
catch{
Write-Error $_
}
@@ -0,0 +1,39 @@
$envCountry = 'CH'
#identity to connect to environment
$DBActiveDirectoryDomain= '%doimain name%'
$DBADAccount='%username'
$DBAsvcPassword = ConvertTo-SecureString -String '%password ' -AsPlainText -Force
$DBACredential = New-Object System.Management.Automation.PSCredential("$DBActiveDirectoryDomain\$DBADAccount", $DBAsvcPassword)
$linPassword = ConvertTo-SecureString -String '1' -AsPlainText -Force
$Credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $linAccount, $linPassword
# Instances list
$servers = @(
# Green - test environement
@("tpiccard","10.146.11.71","tpiccard","green"),
@("bisw12ponldb01","10.41.70.65","bisw12ponldb01","green"),
@("CHREPRTDB1NPW01","10.213.64.25","CHREPRTDB1NPW01","blue"),
#dev @("BISW19TSQLCLU2","10.41.70.238","BISW19TSQLCLU2","green"),
#dev @("BISW19TSQLCLU1","10.213.64.130","BISW19TSQLCLU1","green"),
#wait for install SQL@("CHSHAB0DB0PRW01","10.41.70.230","CHSHAB0DB0PRW01","green"),
# @("BISW19TMast1","10.213.64.132","BISW19TMast1","green"),brak sql
# @("BISW19TMIGR01","10.41.70.122","BISW19TMIGR01","green"),brak sql
#decommisioned @("BISW19TTRADE01","10.213.2.200","BISW19TTRADE01","green"),
@("CHLOOKUDB0PRW01","10.146.11.11","CHLOOKUDB0PRW01","green"),
# Orange - production environement
@("CHREPRTDB1PRW01","10.213.2.81","CHREPRTDB1PRW01","orange"),
@("BISW12PSQLWC01","10.41.70.205","BISW12PSQLWC01","orange"),
@("BISW12PMISDB01.bisnodech.local","10.41.70.32","BISW12PMISDB01","orange"),
@("BISW19PNAVDB01.bisnodech.local","10.146.11.103","BISW19PNAVDB01,","orange")
@("CHURSHAB.bisnodech.local","10.146.11.60","CHURSHAB","orange"),
@("bisw12pbccdb01.bisnodech.local","10.41.70.38","bisw12pbccdb01","orange"),
@("bisw12ponldb01.bisnodech.local","10.41.70.65","bisw12ponldb01","orange"),
@("bisw12prpsdb01.bisnodech.local","10.146.11.158","bisw12prpsdb01","orange"),
@("bisw12psqldb01.bisnodech.local","10.146.11.248","bisw12psqldb01","orange"),
@("bisw12psqldb02.bisnodech.local","10.146.11.190","bisw12psqldb02","orange"),
@("bisw12pxmldb01.bisnodech.local","10.146.11.194","bisw12pxmldb01","orange"),
@("dnbw08plookup1.dnb.bisnodech.local ","10.146.11.11","bisw12pxmldb01","orange"),
@("piccard.dnbswitzerland.ch","10.146.11.213","piccard","orange")
)
@@ -0,0 +1,5 @@
$ActiveDirectoryDomain= '%domain name%'
$ADAccount='%username%'
$svcPassword = ConvertTo-SecureString -String '%password to DBAmin instance%' -AsPlainText -Force #Muszę to zmienić ponieważ nie jest bezpiecznie trzymać te informacje w pliku płaskim
$ADCredential = New-Object System.Management.Automation.PSCredential("$ActiveDirectoryDomain\$ADAccount", $svcPassword)
View File
@@ -0,0 +1,5 @@
//with rebuild system databases - users and databases are dropped so better to detach user databases before
[installation folder]\setup.exe /QUIET /ACTION=REBUILDDATABASE /INSTANCENAME=BIS_SQL /SQLSYSADMINACCOUNTS=INFRABIS\administrator /SQLCOLLATION=Polish_CI_AS /SAPWD=StrongPassword
//without rebuilding system databases - users and user databases stay but it's advised to detach user databases to speed up process
sqlservr -m -T4022 -T3659 -s"BIS_SQL" -q"Polish_CI_AS"
@@ -0,0 +1,88 @@
$envCountry = 'CH'
#import Country settings
. .\..\.env\Import-EnvironmentSettings.ps1 -envCountry $envCountry
# This is minimal dane witch can be inserted to database
$minDatedte = Get-Date "1777/01/01"
$svcPassword = ConvertTo-SecureString -String $ADPassword -AsPlainText -Force
$ADCredential = New-Object System.Management.Automation.PSCredential("$ActiveDirectoryDomain\$ADAccount", $svcPassword)
Write-host 'Processing country ... ' $country
foreach($server in $servers){
$serverName = $server[0]
$serverEnv = $server[3]
$instanceIp = $server[1]
# jeśli jest na jednym IP wiele instancji należy zbudować odpowiedni connection string i dopiero potem można się podłączyć do bazy
if($server[4]) {
$instance = $server[1] + '\' + $server[4]
} else {
$instance = $server[1]
}
$tmpVerInstance = test-DbaBuild -SqlInstance $instance -Latest -SqlCredential $ADCredential -update
$System_name = (Get-WmiObject -comp $instanceIp -Credential $ADCredential -class Win32_OperatingSystem ).caption #Version # #caption
$System_Version = (Get-WmiObject -comp $instanceIp -Credential $ADCredential -class Win32_OperatingSystem ).Version
# $IP_Address = $HostNames[$i]
# $ServerName = 'Server ' + $serverName
$Instance_Name = $tmpVerInstance.SqlInstance
Write-host '=> Processing server ... ' $serverName
$dba_info = Invoke-DbaQuery -SqlInstance $instanceIp -Query "EXEC sp_server_info" -SqlCredential $ADCredential
$Database_Type = $dba_info[0].attribute_value
$Build = $tmpVerInstance.Build
$Server_Name = (Get-WmiObject -comp $instanceIp -Credential $ADCredential -class Win32_OperatingSystem ).CSName
$Build = $tmpVerInstance.Build
$KBLevel = $tmpVerInstance.KBLevel
$Compliant = $tmpVerInstance.Compliant
$SPLevel = $tmpVerInstance.SPLevel
$SupportedUntil = $tmpVerInstance.SupportedUntil
$instanceid = Invoke-DbaQuery -SqlInstance $dbadminServer -Database "DBAdmin" -Query "EXEC dbaInstance '$Instance_Name', '$country', '$System_name', '$System_Version', '$instanceIp', '$Database_Type', '$Build', '$KBLevel', '$Compliant', '$SPLevel', '$SupportedUntil', '$serverEnv', '$serverName'" -SqlCredential $DBACredential
$InsID = $instanceid['InstanceID']
$DatabaseInfo = Get-DbaDatabase -SqlInstance $instance -SqlCredential $ADCredential
foreach($db in $DatabaseInfo){
if ($db.LastFullBackup -lt $minDatedte) {
$LastFullBackup = $null
}
else {
$LastFullBackup = $db.LastFullBackup
}
if ($db.LastDiffBackup -lt $minDatedte ) {
$LastDiffBackup = $null
}
else {
$LastDiffBackup = $db.LastDiffBackup
}
if ($db.LastLogBackup -lt $minDatedte) {
$LastLogBackup = $null
}
else {
$LastLogBackup = $db.LastLogBackup
}
$sqlParams = @{
_instanceID = $InsID
_DatabaseName = $db.Name
_DatabaseStatus = $db.Status
_IsAccessible = $db.IsAccessible
_RecoveryModel = $db.RecoveryModel
_LogReuseWaitStatus = $db.LogReuseWaitStatus
_Compatibility = $db.Compatibility
_Collation = $db.Collation
_DBOwner = $db.Owner
_IsEncrypted = $db.Encrypted
_LastFullBackup = $LastFullBackup
_LastDiffBackup = $LastDiffBackup
_LastLogBackup = $LastLogBackup
}
Write-host '==> Processing database ... ' $db.Name
Invoke-DbaQuery -SqlInstance $dbadminServer -Database "DBAdmin" -Query 'exec dbaDatabase @_instanceID, @_DatabaseName, @_DatabaseStatus, @_IsAccessible, @_RecoveryModel, @_LogReuseWaitStatus, @_Compatibility, @_Collation, @_DBOwner, @_IsEncrypted, @_LastFullBackup, @_LastDiffBackup, @_LastLogBackup ' -SqlParameter $sqlParams -SqlCredential $DBACredential
}
}
@@ -0,0 +1,86 @@
$envCountry = 'CH'
#import Country settings
. .\..\.env\Import-EnvironmentSettings.ps1 -envCountry $envCountry
$svcPassword = ConvertTo-SecureString -String $ADPassword -AsPlainText -Force #Muszę to zmienić ponieważ nie jest bezpiecznie trzymać te informacje w pliku płaskim
$ADCredential = New-Object System.Management.Automation.PSCredential("$ActiveDirectoryDomain\$ADAccount", $svcPassword)
function Get-Instance {
foreach ($instance in $servers) {
if($instance[4]) {
[array]$sqlinstances += $instance[1] + '\' + $instance[4]
} else {
[array]$sqlinstances += $instance[1]
}
}
if ($null -ne $sqlinstances) {
return [array]$sqlinstances
}
if ($sqlinstances.Length -eq 0) {
Write-PSFMessage -Level Warning -Message "You must specify a list of servers"
return
}
else {
[array]$sqlinstances
}
}
@(Get-Instance).ForEach{
$instance = $psitem
try {
$InstanceSMO = Connect-DbaInstance -SqlInstance $instance -SqlCredential $ADCredential -ErrorAction SilentlyContinue -ErrorVariable errorvar
} catch {
$NotContactable += $instance
}
if ($NotContactable -contains $instance) {
Context "Checking for failed enabled jobs on $instance" {
It "Can't Connect to $instance" {
$false | Should -BeTrue -Because 'The instance should be available to be connected to!'
}
}
}
if ($NotContactable -notcontains $instance) {
if ($null -eq $InstanceSMO.version) {
$NotContactable += $instance
} elseif (($InstanceSMO).Edition -like 'Express Edition*') { }
else {
BeforeAll {
}
Describe "Failed Jobs" -Tags FailedJob {
$maxdays = 100
$startdate = (Get-Date).AddDays( - $maxdays)
$excludecancelled = $true
Context "Checking for failed enabled jobs since $startdate on $instance -> " {
@(Get-DbaAgentJob -SqlInstance $instance -SqlCredential $ADCredential | Where-Object Category -eq "Database Maintenance" ).ForEach{
if ($_.LastRunOutcome -eq 'Unknown') {
It -Skip "1. We chose to skip this as $psitem's last run outcome is unknown on $($_.SqlInstance)" {
$_.LastRunOutcome | Should -Be 'Succeeded' -Because 'All Agent Jobs should have succeed this one is unknown - you need to investigate the failed jobs'
}
} elseif (($_.LastRunOutcome -eq 'Cancelled') -and ($excludecancelled -eq $true)) {
It -Skip "2. We chose to skip this as $psitem's last run outcome is cancelled on $($_.SqlInstance)" {
$_.LastRunOutcome | Should -Be 'Succeeded' -Because 'All Agent Jobs should have succeed this one is unknown - you need to investigate the failed jobs'
}
} elseif ($_.LastRunOutcome -eq 'Succeeded'){
# $a = $_.LastRunOutcome
It "$_.LastRunOutcome's last run outcome is $($_.LastRunOutcome) on $($_.SqlInstance)" {
$a = 'Succeeded'
$a | Should -Be 'Succeeded'
}
} else {
It "$_.LastRunOutcome's last run outcome is $($_.LastRunOutcome) on $($_.SqlInstance)" {
$a = 'Failed'
$a | Should -Be 'Succeeded'
}
}
}
}
}
}
}
$NotContactable
}