Skip to content

Commit

Permalink
Improved SQL Server support
Browse files Browse the repository at this point in the history
  • Loading branch information
rebelinux committed Mar 6, 2024
1 parent f631830 commit 27e226a
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 28 deletions.
6 changes: 4 additions & 2 deletions AsBuiltReport.Microsoft.Windows.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
"ShowTableCaptions": true
},
"Options": {
"Instance": "MSSQLSERVER"
"SQLLogin": false,
"SQLUserName": "",
"SQLSecurePassword": ""
},
"InfoLevel": {
"_comment_": "Please refer to the AsBuiltReport project contributing guide for information about how to define InfoLevels.",
Expand Down Expand Up @@ -57,7 +59,7 @@
"BP": true
},
"SQLServer": {
"Firewall": true
"BP": true
}
}
}
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.5.3] - 2024-02-??
## [0.5.3] - 2024-03-06

### Added

Expand Down
19 changes: 16 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,22 @@ The **Report** schema provides configuration of the Microsoft Windows report inf

The **Options** schema allows certain options within the report to be toggled on or off.

| Sub-Schema | Setting | Default | Description |
| ---------- | ------------------- | ----------- | ------------------------------------------ |
| Instance | SQL Server Instance | MSSQLSERVER | Set the sql server instance to connect to. |
| Sub-Schema | Setting | Default | Description |
| ----------------- | ------------ | ------- | ---------------------------------------- |
| SQLLogin | true / false | false | Enable sql server login authentication . |
| SQLUserName | User defined | empty | Sql server login Username . |
| SQLSecurePassword | User defined | empty | Sql server login SecureString Password . |

#### Generating a SecureString

```powershell
PS C:\> "SecurePassword" | ConvertTo-SecureString -AsPlainText -Force | ConvertFrom-SecureString
01000000d08c9ddf0115d1118c7a00c04fc297eb01000000b3605317d738c346801fbff6596b0d130000
PS C:\>
```
Copy/Paste the output text to the variable SQLSecurePassword

##### Note: Storing any credential in a file can pose a security risk. Use this option at your own risk!

### InfoLevel

Expand Down
4 changes: 2 additions & 2 deletions Src/Private/Get-AbrWinSQLBackupDevice.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function Get-AbrWinSQLBackupDevice {
}

if ($InfoLevel.SQLServer -ge 2) {
Paragraph "The following sections detail the configuration of the backup device $($SQLServer.Name)."
Paragraph "The following sections detail the configuration of the backup device."
foreach ($Item in $ItemInfo) {
Section -Style NOTOCHeading5 -ExcludeFromTOC "$($Item.Name)" {
$TableParams = @{
Expand All @@ -60,7 +60,7 @@ function Get-AbrWinSQLBackupDevice {
}
}
} else {
Paragraph "The following table summarises the configuration of the backup device within $($SQLServer.Name)."
Paragraph "The following table summarises the configuration of the backup device."
BlankLine
$TableParams = @{
Name = "Backup Devices"
Expand Down
2 changes: 1 addition & 1 deletion Src/Private/Get-AbrWinSQLBuild.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function Get-AbrWinSQLBuild {
if ($InfoLevel.SQLServer -ge 1) {
try {
$Properties = Get-DbaInstanceProperty -SqlInstance $SQLServer | ForEach-Object { @{$_.Name = $_.Value } }
$Build = Get-DbaBuild -SqlInstance $SQLServer
$Build = Get-DbaBuild -SqlInstance $SQLServer -WarningAction SilentlyContinue
if ($Properties) {
Section -Style Heading3 'General Information' {
Paragraph 'The following table details sql server Properties information'
Expand Down
8 changes: 4 additions & 4 deletions Src/Private/Get-AbrWinSQLDatabase.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function Get-AbrWinSQLDatabase {
'Status' = $SQLDB.Status
'Is Accessible?' = ConvertTo-TextYN $SQLDB.IsAccessible
'Recovery Model' = $SQLDB.RecoveryModel
'Size' = Switch ([string]::IsNullOrEmpty($SQLDB.SizeM)) {
'Size' = Switch ([string]::IsNullOrEmpty($SQLDB.SizeMB)) {
$true { '--' }
$false { "$($SQLDB.SizeMB) MB" }
default { 'Unknown' }
Expand All @@ -80,7 +80,7 @@ function Get-AbrWinSQLDatabase {
}

if ($InfoLevel.SQLServer -ge 2) {
Paragraph "The following sections detail the configuration of the system databases within $($SQLServer.Name)."
Paragraph "The following sections detail the configuration of the system databases."
foreach ($SQLDB in $SQLDBInfo) {
Section -Style NOTOCHeading5 -ExcludeFromTOC "$($SQLDB.Name)" {
$TableParams = @{
Expand All @@ -95,7 +95,7 @@ function Get-AbrWinSQLDatabase {
}
}
} else {
Paragraph "The following table summarises the configuration of the system databases within $($SQLServer.Name)."
Paragraph "The following table summarises the configuration of the system databases."
BlankLine
$TableParams = @{
Name = "System Databases"
Expand Down Expand Up @@ -126,7 +126,7 @@ function Get-AbrWinSQLDatabase {
'Status' = $SQLDB.Status
'Is Accessible?' = ConvertTo-TextYN $SQLDB.IsAccessible
'Recovery Model' = $SQLDB.RecoveryModel
'Size' = Switch ([string]::IsNullOrEmpty($SQLDB.SizeM)) {
'Size' = Switch ([string]::IsNullOrEmpty($SQLDB.SizeMB)) {
$true { '--' }
$false { "$($SQLDB.SizeMB) MB" }
default { 'Unknown' }
Expand Down
6 changes: 3 additions & 3 deletions Src/Private/Get-AbrWinSQLLogin.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function Get-AbrWinSQLLogin {
Section -Style Heading4 'Logins' {
$ItemInfo = @()
foreach ($Item in $SQLLogins) {
$ServerRoles = try {Get-DbaServerRoleMember -SqlInstance $SQLServer -Login $Item.Name} catch {Out-Null}
$ServerRoles = try { Get-DbaServerRoleMember -SqlInstance $SQLServer -Login $Item.Name } catch { Out-Null }
try {
$InObj = [Ordered]@{
'Name' = $Item.Name
Expand Down Expand Up @@ -69,7 +69,7 @@ function Get-AbrWinSQLLogin {
}

if ($InfoLevel.SQLServer -ge 2) {
Paragraph "The following sections detail the configuration of the security login $($SQLServer.Name)."
Paragraph "The following sections detail the configuration of the security login."
foreach ($Item in $ItemInfo) {
Section -Style NOTOCHeading5 -ExcludeFromTOC "$($Item.Name)" {
$TableParams = @{
Expand All @@ -84,7 +84,7 @@ function Get-AbrWinSQLLogin {
}
}
} else {
Paragraph "The following table summarises the configuration of the security login within $($SQLServer.Name)."
Paragraph "The following table summarises the configuration of the security login."
BlankLine
$TableParams = @{
Name = "Logins"
Expand Down
4 changes: 2 additions & 2 deletions Src/Private/Get-AbrWinSQLRole.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function Get-AbrWinSQLRole {
}

if ($InfoLevel.SQLServer -ge 2) {
Paragraph "The following sections detail the configuration of the security roles $($SQLServer.Name)."
Paragraph "The following sections detail the configuration of the security roles."
foreach ($Item in $ItemInfo) {
Section -Style NOTOCHeading5 -ExcludeFromTOC "$($Item.Name)" {
$TableParams = @{
Expand All @@ -65,7 +65,7 @@ function Get-AbrWinSQLRole {
}
}
} else {
Paragraph "The following table summarises the configuration of the security role within $($SQLServer.Name)."
Paragraph "The following table summarises the configuration of the security role."
BlankLine
$TableParams = @{
Name = "Roles"
Expand Down
25 changes: 15 additions & 10 deletions Src/Public/Invoke-AsBuiltReport.Microsoft.Windows.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,20 @@ function Invoke-AsBuiltReport.Microsoft.Windows {
[PSCredential] $Credential
)

Write-PScriboMessage -IsWarning "Please refer to the AsBuiltReport.Microsoft.Windows github website for more detailed information about this project."
Write-PScriboMessage -IsWarning "Do not forget to update your report configuration file after each new release."
Write-PScriboMessage -IsWarning "Documentation: https://github.com/AsBuiltReport/AsBuiltReport.Microsoft.Windows"
Write-PScriboMessage -IsWarning "Issues or bug reporting: https://github.com/AsBuiltReport/AsBuiltReport.Microsoft.Windows/issues"
Write-PScriboMessage -Plugin "Module" -IsWarning "Please refer to the AsBuiltReport.Microsoft.Windows github website for more detailed information about this project."
Write-PScriboMessage -Plugin "Module" -IsWarning "Do not forget to update your report configuration file after each new release."
Write-PScriboMessage -Plugin "Module" -IsWarning "Documentation: https://github.com/AsBuiltReport/AsBuiltReport.Microsoft.Windows"
Write-PScriboMessage -Plugin "Module" -IsWarning "Issues or bug reporting: https://github.com/AsBuiltReport/AsBuiltReport.Microsoft.Windows/issues"

Try {
$InstalledVersion = Get-Module -ListAvailable -Name AsBuiltReport.Microsoft.Windows -ErrorAction SilentlyContinue | Sort-Object -Property Version -Descending | Select-Object -First 1 -ExpandProperty Version

if ($InstalledVersion) {
Write-PScriboMessage -IsWarning "AsBuiltReport.Microsoft.Windows $($InstalledVersion.ToString()) is currently installed."
Write-PScriboMessage -Plugin "Module" -IsWarning "AsBuiltReport.Microsoft.Windows $($InstalledVersion.ToString()) is currently installed."
$LatestVersion = Find-Module -Name AsBuiltReport.Microsoft.Windows -Repository PSGallery -ErrorAction SilentlyContinue | Select-Object -ExpandProperty Version
if ($LatestVersion -gt $InstalledVersion) {
Write-PScriboMessage -IsWarning "AsBuiltReport.Microsoft.Windows $($LatestVersion.ToString()) is available."
Write-PScriboMessage -IsWarning "Run 'Update-Module -Name AsBuiltReport.Microsoft.Windows -Force' to install the latest version."
Write-PScriboMessage -Plugin "Module" -IsWarning "AsBuiltReport.Microsoft.Windows $($LatestVersion.ToString()) is available."
Write-PScriboMessage -Plugin "Module" -IsWarning "Run 'Update-Module -Name AsBuiltReport.Microsoft.Windows -Force' to install the latest version."
}
}
} Catch {
Expand Down Expand Up @@ -342,13 +342,18 @@ function Invoke-AsBuiltReport.Microsoft.Windows {
}

if ($InfoLevel.SQLServer -ge 1 -and $OSType.Value -ne 'WorkStation') {
$Status = Invoke-Command -Session $TempPssSession -ScriptBlock { Get-Service 'MSSQLSERVER' -ErrorAction SilentlyContinue }
$Status = Invoke-Command -Session $TempPssSession -ScriptBlock { Get-Service 'MSSQL*' -ErrorAction SilentlyContinue }
if ($Status.Status -eq "Running") {
try {
$script:SQLServer = Connect-DbaInstance -SqlInstance $System -TrustServerCertificate -SqlCredential $Credential
if ($Options.SQLLogin) {
$SQLCredential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $Options.SQLUserName, (ConvertTo-SecureString -Force $Options.SQLSecurePassword)
$script:SQLServer = Connect-DbaInstance -SqlInstance $System -TrustServerCertificate -SqlCredential $SQLCredential
} else {
$script:SQLServer = Connect-DbaInstance -SqlInstance $System -TrustServerCertificate -SqlCredential $Credential
}
if ($SQLServer) {
Section -Style Heading2 "SQL Server Configuration" {
Paragraph 'The following table details the SQL Server settings'
Paragraph "The following table details the SQL Server configuration from $($SQLServer.Name)."
BlankLine
# SQL Server Build Information
Get-AbrWinSQLBuild
Expand Down

0 comments on commit 27e226a

Please sign in to comment.