diff --git a/.github/workflows/Release.yml b/.github/workflows/Release.yml index fa7a814..7cfe12e 100644 --- a/.github/workflows/Release.yml +++ b/.github/workflows/Release.yml @@ -13,6 +13,10 @@ jobs: shell: pwsh run: | Set-PSRepository -Name PSGallery -InstallationPolicy Trusted + - name: Install DBAtools module + shell: pwsh + run: | + Install-Module -Name dbatools -Repository PSGallery -Force - name: Install AsBuiltReport.Core module shell: pwsh run: | diff --git a/AsBuiltReport.Microsoft.Windows.json b/AsBuiltReport.Microsoft.Windows.json index b284937..e9e6ec6 100644 --- a/AsBuiltReport.Microsoft.Windows.json +++ b/AsBuiltReport.Microsoft.Windows.json @@ -8,7 +8,9 @@ "ShowHeaderFooter": true, "ShowTableCaptions": true }, - "Options": {}, + "Options": { + "Instance": "MSSQLSERVER" + }, "InfoLevel": { "_comment_": "Please refer to the AsBuiltReport project contributing guide for information about how to define InfoLevels.", "_comment_": "0 = Disabled, 1 = Enabled, 2 = Adv Summary, 3 = Detailed, 4 = Adv Detailed, 5 = Comprehensive", @@ -22,7 +24,8 @@ "SMB": 1, "DHCP": 1, "DNS": 1, - "FailOverCluster": 1 + "FailOverCluster": 1, + "SQLServer": 1 }, "HealthCheck": { "Networking": { @@ -52,6 +55,9 @@ }, "SMB": { "BP": true + }, + "SQLServer": { + "Firewall": true } } } \ No newline at end of file diff --git a/AsBuiltReport.Microsoft.Windows.psd1 b/AsBuiltReport.Microsoft.Windows.psd1 index 6a79fa4..0ef3fb2 100644 --- a/AsBuiltReport.Microsoft.Windows.psd1 +++ b/AsBuiltReport.Microsoft.Windows.psd1 @@ -12,7 +12,7 @@ RootModule = 'AsBuiltReport.Microsoft.Windows.psm1' # Version number of this module. - ModuleVersion = '0.5.2' + ModuleVersion = '0.5.3' # Supported PSEditions # CompatiblePSEditions = @() @@ -55,6 +55,10 @@ @{ ModuleName = 'AsBuiltReport.Core'; ModuleVersion = '1.3.0' + }, + @{ + ModuleName = 'dbatools'; + ModuleVersion = '2.1.7' } ) diff --git a/CHANGELOG.md b/CHANGELOG.md index c79c564..96b864b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,21 @@ 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-?? + +### Added + +- Add SQL Server support + - General Information + - Security + - Login + - Roles + - Databases + - User + - System + - Server Objects + - Backup Devices + ## [0.5.2] - 2024-02-18 ### Added diff --git a/README.md b/README.md index c1efe6f..3693996 100644 --- a/README.md +++ b/README.md @@ -72,6 +72,8 @@ PowerShell 5.1 and the following PowerShell modules are required for generating - [DhcpServer Module](https://docs.microsoft.com/en-us/powershell/module/dhcpserver/?view=windowsserver2019-ps) - [DnsServer Module](https://docs.microsoft.com/en-us/powershell/module/dnsserver/?view=windowsserver2019-ps) - [FailoverClusters Module](https://learn.microsoft.com/en-us/powershell/module/failoverclusters/?view=windowsserver2022-ps) +- [DBATools Module](https://dbatools.io/) + ### Linux & macOS @@ -97,13 +99,15 @@ Install-WindowsFeature -Name RSAT-DHCP # Hyper-V Server powershell modules Install-WindowsFeature -Name Hyper-V-PowerShell -#IIS Server powershell modules +# IIS Server powershell modules Install-WindowsFeature -Name web-mgmt-console Install-WindowsFeature -Name Web-Scripting-Tools -#FailOver Cluster powershell modules +# FailOver Cluster powershell modules Install-WindowsFeature -Name RSAT-Clustering-PowerShell +# DBATools for SQL +Install-Module dbatools ``` ### PowerShell v5.x running on Windows client computer (Target) @@ -126,6 +130,8 @@ Enable-WindowsOptionalFeature -Online -FeatureName IIS-WebServerRole Enable-WindowsOptionalFeature -Online -FeatureName IIS-WebServerManagementTools Enable-WindowsOptionalFeature -Online -FeatureName IIS-ManagementScriptingTools +# DBATools for SQL +Install-Module dbatools ``` ### GitHub @@ -179,6 +185,10 @@ 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. | + ### InfoLevel The **InfoLevel** schema allows configuration of each section of the report at a granular level. The following sections can be set. diff --git a/Src/Private/Get-AbrWinSQLBackupDevice.ps1 b/Src/Private/Get-AbrWinSQLBackupDevice.ps1 new file mode 100644 index 0000000..582cdb8 --- /dev/null +++ b/Src/Private/Get-AbrWinSQLBackupDevice.ps1 @@ -0,0 +1,83 @@ +function Get-AbrWinSQLBackupDevice { + <# + .SYNOPSIS + Used by As Built Report to retrieve Windows SQL Server backup device information. + .DESCRIPTION + Documents the configuration of Microsoft Windows Server in Word/HTML/Text formats using PScribo. + .NOTES + Version: 0.5.3 + Author: Jonathan Colon + Twitter: @rebelinux + Github: AsBuiltReport + Credits: Iain Brighton (@iainbrighton) - PScribo module + + .LINK + https://github.com/AsBuiltReport/AsBuiltReport.Microsoft.Windows + #> + [CmdletBinding()] + param ( + ) + + begin { + Write-PScriboMessage "SQL Server Backup Device InfoLevel set at $($InfoLevel.SQLServer)." + } + + process { + try { + Write-PScriboMessage "Collecting SQL Server Backup Device information." + $SQLBackUpDevices = Get-DbaBackupDevice -SqlInstance $SQLServer | Sort-Object -Property Name + if ($SQLBackUpDevices) { + Write-PScriboMessage "Collecting SQL Server Backup Device information." + Section -Style Heading4 'Backup Device' { + $ItemInfo = @() + foreach ($Item in $SQLBackUpDevices) { + try { + $InObj = [Ordered]@{ + 'Name' = $Item.Name + 'Backup Device Type' = $Item.BackupDeviceType + 'Physical Location' = $Item.PhysicalLocation + 'Skip Tape Label' = ConvertTo-TextYN $Item.SkipTapeLabel + } + $ItemInfo += [PSCustomObject]$InObj + } catch { + Write-PScriboMessage -IsWarning "SQL Server System Backup Device Section: $($_.Exception.Message)" + } + } + + if ($InfoLevel.SQLServer -ge 2) { + Paragraph "The following sections detail the configuration of the backup device $($SQLServer.Name)." + foreach ($Item in $ItemInfo) { + Section -Style NOTOCHeading5 -ExcludeFromTOC "$($Item.Name)" { + $TableParams = @{ + Name = "Backup Device - $($Item.Name)" + List = $true + ColumnWidths = 50, 50 + } + if ($Report.ShowTableCaptions) { + $TableParams['Caption'] = "- $($TableParams.Name)" + } + $Item | Table @TableParams + } + } + } else { + Paragraph "The following table summarises the configuration of the backup device within $($SQLServer.Name)." + BlankLine + $TableParams = @{ + Name = "Backup Devices" + List = $false + Columns = 'Name', 'Backup Device Type', 'Physical Location' + ColumnWidths = 25, 25, 50 + } + if ($Report.ShowTableCaptions) { + $TableParams['Caption'] = "- $($TableParams.Name)" + } + $ItemInfo | Table @TableParams + } + } + } + } catch { + Write-PScriboMessage -IsWarning "SQL Server Backup Device Section: $($_.Exception.Message)" + } + } + end {} +} \ No newline at end of file diff --git a/Src/Private/Get-AbrWinSQLBuild.ps1 b/Src/Private/Get-AbrWinSQLBuild.ps1 new file mode 100644 index 0000000..93f105b --- /dev/null +++ b/Src/Private/Get-AbrWinSQLBuild.ps1 @@ -0,0 +1,84 @@ +function Get-AbrWinSQLBuild { + <# + .SYNOPSIS + Used by As Built Report to retrieve Windows SQL Server Properties information. + .DESCRIPTION + Documents the configuration of Microsoft Windows Server in Word/HTML/Text formats using PScribo. + .NOTES + Version: 0.5.2 + Author: Andrew Ramsay + Editor: Jonathan Colon + Twitter: @asbuiltreport + Github: AsBuiltReport + Credits: Iain Brighton (@iainbrighton) - PScribo module + + .LINK + https://github.com/AsBuiltReport/AsBuiltReport.Microsoft.Windows + #> + [CmdletBinding()] + param ( + ) + + begin { + Write-PScriboMessage "SQL Server InfoLevel set at $($InfoLevel.SQLServer)." + Write-PScriboMessage "Collecting SQL Server Properties information." + } + + process { + if ($InfoLevel.SQLServer -ge 1) { + try { + $Properties = Get-DbaInstanceProperty -SqlInstance $SQLServer | ForEach-Object { @{$_.Name = $_.Value } } + $Build = Get-DbaBuild -SqlInstance $SQLServer + if ($Properties) { + Section -Style Heading3 'General Information' { + Paragraph 'The following table details sql server Properties information' + BlankLine + [array]$SQLServerObjt = @() + $TempSQLServerObjt = [PSCustomObject]@{ + 'Instance Name' = $Build.SqlInstance + 'Fully Qualified Net Name' = $Properties.FullyQualifiedNetName + 'Supported Until' = $Build.SupportedUntil.ToShortDateString() + 'Edition' = $Properties.Edition + 'Level' = "Microsoft SQL Server $($Build.NameLevel)" + 'Build' = $Properties.VersionString + 'Service Pack' = $Properties.ProductLevel + 'Comulative Update' = ConvertTo-EmptyToFiller $Build.CULevel + 'KB Level' = $Build.KBLevel + 'Case Sensitive' = ConvertTo-TextYN $Properties.IsCaseSensitive + 'Full Text Installed' = ConvertTo-TextYN $Properties.IsFullTextInstalled + 'XTP Supported' = ConvertTo-TextYN $Properties.IsXTPSupported + 'Clustered' = ConvertTo-TextYN $Properties.IsClustered + 'Single User' = ConvertTo-TextYN $Properties.IsSingleUser + 'Language' = $Properties.Language + 'Collation' = $Properties.Collation + 'Sql CharSet Name' = $Properties.SqlCharSetName + 'Root Directory' = $Properties.RootDirectory + 'Master DB Path' = $Properties.MasterDBPath + 'Master DB Log Path' = $Properties.MasterDBLogPath + 'Backup Directory' = $Properties.BackupDirectory + 'Default File' = $Properties.DefaultFile + 'Default Log' = $Properties.DefaultLog + 'Login Mode' = $Properties.LoginMode + 'Mail Profile' = ConvertTo-EmptyToFiller $Properties.MailProfile + 'Warning' = ConvertTo-EmptyToFiller $Build.Warning + } + $SQLServerObjt += $TempSQLServerObjt + + $TableParams = @{ + Name = "General Information" + List = $True + ColumnWidths = 40, 60 + } + if ($Report.ShowTableCaptions) { + $TableParams['Caption'] = "- $($TableParams.Name)" + } + $SQLServerObjt | Table @TableParams + } + } + } catch { + Write-PScriboMessage -IsWarning $_.Exception.Message + } + } + } + end {} +} \ No newline at end of file diff --git a/Src/Private/Get-AbrWinSQLDatabase.ps1 b/Src/Private/Get-AbrWinSQLDatabase.ps1 new file mode 100644 index 0000000..7617d36 --- /dev/null +++ b/Src/Private/Get-AbrWinSQLDatabase.ps1 @@ -0,0 +1,192 @@ +function Get-AbrWinSQLDatabase { + <# + .SYNOPSIS + Used by As Built Report to retrieve Windows SQL Server database information. + .DESCRIPTION + Documents the configuration of Microsoft Windows Server in Word/HTML/Text formats using PScribo. + .NOTES + Version: 0.5.3 + Author: Jonathan Colon + Twitter: @rebelinux + Github: AsBuiltReport + Credits: Iain Brighton (@iainbrighton) - PScribo module + + .LINK + https://github.com/AsBuiltReport/AsBuiltReport.Microsoft.Windows + #> + [CmdletBinding()] + param ( + ) + + begin { + Write-PScriboMessage "SQL Server Dstabases InfoLevel set at $($InfoLevel.SQLServer)." + } + + process { + Section -Style Heading3 'Databases' { + $CompatibilityHash = @{ + 'Version60' = 'SQL Server 6.0' + 'Version65' = 'SQL Server 6.5' + 'Version70' = 'SQL Server 7.0' + 'Version80' = 'SQL Server 2000' + 'Version90' = 'SQL Server 2005' + 'Version100' = 'SQL Server 2008' + 'Version110' = 'SQL Server 2012' + 'Version120' = 'SQL Server 2014' + 'Version130' = 'SQL Server 2016' + 'Version140' = 'SQL Server 2017' + 'Version150' = 'SQL Server 2019' + 'Version160' = 'SQL Server 2022' + + } + try { + Write-PScriboMessage "Collecting SQL Server databases information." + $SQLDBs = Get-DbaDatabase -SqlInstance $SQLServer -ExcludeUser | Sort-Object -Property Name + if ($SQLDBs) { + Write-PScriboMessage "Collecting SQL Server system databases information." + Section -Style Heading4 'System Databases' { + $SQLDBInfo = @() + foreach ($SQLDB in $SQLDBs) { + try { + $InObj = [Ordered]@{ + 'Name' = $SQLDB.Name + 'Status' = $SQLDB.Status + 'Is Accessible?' = ConvertTo-TextYN $SQLDB.IsAccessible + 'Recovery Model' = $SQLDB.RecoveryModel + 'Size' = Switch ([string]::IsNullOrEmpty($SQLDB.SizeM)) { + $true { '--' } + $false { "$($SQLDB.SizeMB) MB" } + default { 'Unknown' } + } + 'Compatibility' = $CompatibilityHash[[string]$SQLDB.Compatibility] + 'Collation' = $SQLDB.Collation + 'Encrypted' = ConvertTo-TextYN $SQLDB.Encrypted + 'Last Full Backup' = Switch ($SQLDB.LastFullBackup) { + '01/01/0001 00:00:00' { "Never" } + $null { '--' } + default { $SQLDB.LastFullBackup } + } + 'Last Log Backup' = Switch ($SQLDB.LastLogBackup) { + '01/01/0001 00:00:00' { "Never" } + $null { '--' } + default { $SQLDB.LastLogBackup } + } + 'Owner' = $SQLDB.Owner + } + $SQLDBInfo += [PSCustomObject]$InObj + } catch { + Write-PScriboMessage -IsWarning "SQL Server System Database table: $($_.Exception.Message)" + } + } + + if ($InfoLevel.SQLServer -ge 2) { + Paragraph "The following sections detail the configuration of the system databases within $($SQLServer.Name)." + foreach ($SQLDB in $SQLDBInfo) { + Section -Style NOTOCHeading5 -ExcludeFromTOC "$($SQLDB.Name)" { + $TableParams = @{ + Name = "System Database - $($SQLDB.Name)" + List = $true + ColumnWidths = 50, 50 + } + if ($Report.ShowTableCaptions) { + $TableParams['Caption'] = "- $($TableParams.Name)" + } + $SQLDB | Table @TableParams + } + } + } else { + Paragraph "The following table summarises the configuration of the system databases within $($SQLServer.Name)." + BlankLine + $TableParams = @{ + Name = "System Databases" + List = $false + Columns = 'Name', 'Owner', 'Status', 'Recovery Model', 'Size' + ColumnWidths = 32, 32, 12, 12, 12 + } + if ($Report.ShowTableCaptions) { + $TableParams['Caption'] = "- $($TableParams.Name)" + } + $SQLDBInfo | Table @TableParams + } + } + } + } catch { + Write-PScriboMessage -IsWarning "SQL Server System Database Section: $($_.Exception.Message)" + } + try { + $SQLDBs = Get-DbaDatabase -SqlInstance $SQLServer -ExcludeSystem | Sort-Object -Property Name + if ($SQLDBs) { + Write-PScriboMessage "Collecting SQL Server user databases information." + Section -Style Heading4 'User Databases' { + $SQLDBInfo = @() + foreach ($SQLDB in $SQLDBs) { + try { + $InObj = [Ordered]@{ + 'Name' = $SQLDB.Name + 'Status' = $SQLDB.Status + 'Is Accessible?' = ConvertTo-TextYN $SQLDB.IsAccessible + 'Recovery Model' = $SQLDB.RecoveryModel + 'Size' = Switch ([string]::IsNullOrEmpty($SQLDB.SizeM)) { + $true { '--' } + $false { "$($SQLDB.SizeMB) MB" } + default { 'Unknown' } + } + 'Compatibility' = $CompatibilityHash[[string]$SQLDB.Compatibility] + 'Collation' = $SQLDB.Collation + 'Encrypted' = ConvertTo-TextYN $SQLDB.Encrypted + 'Last Full Backup' = Switch ($SQLDB.LastFullBackup) { + '01/01/0001 00:00:00' { "Never" } + $null { '--' } + default { $SQLDB.LastFullBackup } + } + 'Last Log Backup' = Switch ($SQLDB.LastLogBackup) { + '01/01/0001 00:00:00' { "Never" } + $null { '--' } + default { $SQLDB.LastLogBackup } + } + 'Owner' = $SQLDB.Owner + } + $SQLDBInfo += [PSCustomObject]$InObj + } catch { + Write-PScriboMessage -IsWarning "SQL Server User Database table: $($_.Exception.Message)" + } + } + + if ($InfoLevel.SQLServer -ge 2) { + Paragraph "The following sections detail the configuration of the user databases within $($SQLServer.Name)." + foreach ($SQLDB in $SQLDBInfo) { + Section -Style NOTOCHeading5 -ExcludeFromTOC "$($SQLDB.Name)" { + $TableParams = @{ + Name = "User Database - $($SQLDB.Name)" + List = $true + ColumnWidths = 50, 50 + } + if ($Report.ShowTableCaptions) { + $TableParams['Caption'] = "- $($TableParams.Name)" + } + $SQLDB | Table @TableParams + } + } + } else { + Paragraph "The following table summarises the configuration of the databases within $($SQLServer.Name)." + BlankLine + $TableParams = @{ + Name = "User Databases" + List = $false + Columns = 'Name', 'Owner', 'Status', 'Recovery Model', 'Size' + ColumnWidths = 32, 32, 12, 12, 12 + } + if ($Report.ShowTableCaptions) { + $TableParams['Caption'] = "- $($TableParams.Name)" + } + $SQLDBInfo | Table @TableParams + } + } + } + } catch { + Write-PScriboMessage -IsWarning "SQL Server User Database Section: $($_.Exception.Message)" + } + } + } + end {} +} \ No newline at end of file diff --git a/Src/Private/Get-AbrWinSQLLogin.ps1 b/Src/Private/Get-AbrWinSQLLogin.ps1 new file mode 100644 index 0000000..6086e57 --- /dev/null +++ b/Src/Private/Get-AbrWinSQLLogin.ps1 @@ -0,0 +1,107 @@ +function Get-AbrWinSQLLogin { + <# + .SYNOPSIS + Used by As Built Report to retrieve Windows SQL Server login information. + .DESCRIPTION + Documents the configuration of Microsoft Windows Server in Word/HTML/Text formats using PScribo. + .NOTES + Version: 0.5.3 + Author: Jonathan Colon + Twitter: @rebelinux + Github: AsBuiltReport + Credits: Iain Brighton (@iainbrighton) - PScribo module + + .LINK + https://github.com/AsBuiltReport/AsBuiltReport.Microsoft.Windows + #> + [CmdletBinding()] + param ( + ) + + begin { + Write-PScriboMessage "SQL Server Logins InfoLevel set at $($InfoLevel.SQLServer)." + } + + process { + try { + Write-PScriboMessage "Collecting SQL Server logins information." + $SQLLogins = Get-DbaLogin -SqlInstance $SQLServer | Sort-Object -Property Name + if ($SQLLogins) { + Write-PScriboMessage "Collecting SQL Server logins information." + Section -Style Heading4 'Logins' { + $ItemInfo = @() + foreach ($Item in $SQLLogins) { + $ServerRoles = try {Get-DbaServerRoleMember -SqlInstance $SQLServer -Login $Item.Name} catch {Out-Null} + try { + $InObj = [Ordered]@{ + 'Name' = $Item.Name + 'Login Type' = $Item.LoginType -creplace '(?<=\w)([A-Z])', ' $1' + 'Server Roles' = Switch ([string]::IsNullOrEmpty($ServerRoles.Role)) { + $true { '--' } + $false { $ServerRoles.Role } + default { 'Unknown' } + } + 'Create Date' = $Item.CreateDate + 'Last Login' = Switch ([string]::IsNullOrEmpty($Item.LastLogin)) { + $true { 'Never' } + $false { $Item.LastLogin } + default { 'Unknown' } + } + 'Has Access?' = ConvertTo-TextYN $Item.HasAccess + 'Is Locked?' = Switch ([string]::IsNullOrEmpty($Item.IsLocked)) { + $true { 'No' } + $false { ConvertTo-TextYN $Item.IsLocked } + default { 'Unknown' } + } + 'Is Disabled?' = ConvertTo-TextYN $Item.IsDisabled + 'Must Change Password' = Switch ([string]::IsNullOrEmpty($Item.MustChangePassword)) { + $true { 'No' } + $false { ConvertTo-TextYN $Item.MustChangePassword } + default { 'Unknown' } + } + + + } + $ItemInfo += [PSCustomObject]$InObj + } catch { + Write-PScriboMessage -IsWarning "SQL Server System Login Section: $($_.Exception.Message)" + } + } + + if ($InfoLevel.SQLServer -ge 2) { + Paragraph "The following sections detail the configuration of the security login $($SQLServer.Name)." + foreach ($Item in $ItemInfo) { + Section -Style NOTOCHeading5 -ExcludeFromTOC "$($Item.Name)" { + $TableParams = @{ + Name = "Login - $($Item.Name)" + List = $true + ColumnWidths = 50, 50 + } + if ($Report.ShowTableCaptions) { + $TableParams['Caption'] = "- $($TableParams.Name)" + } + $Item | Table @TableParams + } + } + } else { + Paragraph "The following table summarises the configuration of the security login within $($SQLServer.Name)." + BlankLine + $TableParams = @{ + Name = "Logins" + List = $false + Columns = 'Name', 'Login Type', 'Server Roles', 'Has Access?', 'Is Locked?', 'Is Disabled?' + ColumnWidths = 30, 17, 17, 12, 12, 12 + } + if ($Report.ShowTableCaptions) { + $TableParams['Caption'] = "- $($TableParams.Name)" + } + $ItemInfo | Table @TableParams + } + } + } + } catch { + Write-PScriboMessage -IsWarning "SQL Server System Security Login Section: $($_.Exception.Message)" + } + } + end {} +} \ No newline at end of file diff --git a/Src/Private/Get-AbrWinSQLRole.ps1 b/Src/Private/Get-AbrWinSQLRole.ps1 new file mode 100644 index 0000000..b016bdb --- /dev/null +++ b/Src/Private/Get-AbrWinSQLRole.ps1 @@ -0,0 +1,88 @@ +function Get-AbrWinSQLRole { + <# + .SYNOPSIS + Used by As Built Report to retrieve Windows SQL Server roles information. + .DESCRIPTION + Documents the configuration of Microsoft Windows Server in Word/HTML/Text formats using PScribo. + .NOTES + Version: 0.5.3 + Author: Jonathan Colon + Twitter: @rebelinux + Github: AsBuiltReport + Credits: Iain Brighton (@iainbrighton) - PScribo module + + .LINK + https://github.com/AsBuiltReport/AsBuiltReport.Microsoft.Windows + #> + [CmdletBinding()] + param ( + ) + + begin { + Write-PScriboMessage "SQL Server Roles InfoLevel set at $($InfoLevel.SQLServer)." + } + + process { + try { + Write-PScriboMessage "Collecting SQL Server roles information." + $SQLRoles = Get-DbaServerRole -SqlInstance $SQLServer | Sort-Object -Property Role + if ($SQLRoles) { + Write-PScriboMessage "Collecting SQL Server roles information." + Section -Style Heading4 'Roles' { + $ItemInfo = @() + foreach ($Item in $SQLRoles) { + try { + $InObj = [Ordered]@{ + 'Name' = $Item.Role + 'Owner' = $Item.Owner + 'Login' = Switch ([string]::IsNullOrEmpty($Item.Login)) { + $true { '--' } + $false { $Item.Login } + default { 'Unknown' } + } + 'Fixed Role' = ConvertTo-TextYN $Item.IsFixedRole + 'Create Date' = $Item.DateCreated + } + $ItemInfo += [PSCustomObject]$InObj + } catch { + Write-PScriboMessage -IsWarning "SQL Server System Roles Section: $($_.Exception.Message)" + } + } + + if ($InfoLevel.SQLServer -ge 2) { + Paragraph "The following sections detail the configuration of the security roles $($SQLServer.Name)." + foreach ($Item in $ItemInfo) { + Section -Style NOTOCHeading5 -ExcludeFromTOC "$($Item.Name)" { + $TableParams = @{ + Name = "Role - $($Item.Name)" + List = $true + ColumnWidths = 50, 50 + } + if ($Report.ShowTableCaptions) { + $TableParams['Caption'] = "- $($TableParams.Name)" + } + $Item | Table @TableParams + } + } + } else { + Paragraph "The following table summarises the configuration of the security role within $($SQLServer.Name)." + BlankLine + $TableParams = @{ + Name = "Roles" + List = $false + Columns = 'Name', 'Owner', 'Login' + ColumnWidths = 25, 25, 50 + } + if ($Report.ShowTableCaptions) { + $TableParams['Caption'] = "- $($TableParams.Name)" + } + $ItemInfo | Table @TableParams + } + } + } + } catch { + Write-PScriboMessage -IsWarning "SQL Server Role Section: $($_.Exception.Message)" + } + } + end {} +} \ No newline at end of file diff --git a/Src/Private/Get-RequiredFeature.ps1 b/Src/Private/Get-RequiredFeature.ps1 index e18bb85..94d4029 100644 --- a/Src/Private/Get-RequiredFeature.ps1 +++ b/Src/Private/Get-RequiredFeature.ps1 @@ -88,8 +88,9 @@ function Get-RequiredFeature { Write-PScriboMessage -IsWarning "$Name module is required to be installed on $System to be able to document $Service service. Run 'Install-WindowsFeature -Name '$($Name)'' to install the required modules." } } - } else { - throw "Unable to validate if $Name is installed. https://github.com/AsBuiltReport/AsBuiltReport.Microsoft.AD" + } + else { + throw "Unable to validate if $Name is installed. https://github.com/AsBuiltReport/AsBuiltReport.Microsoft.Windows" } } end {} diff --git a/Src/Public/Invoke-AsBuiltReport.Microsoft.Windows.ps1 b/Src/Public/Invoke-AsBuiltReport.Microsoft.Windows.ps1 index 1fc6105..4df8e61 100644 --- a/Src/Public/Invoke-AsBuiltReport.Microsoft.Windows.ps1 +++ b/Src/Public/Invoke-AsBuiltReport.Microsoft.Windows.ps1 @@ -5,7 +5,7 @@ function Invoke-AsBuiltReport.Microsoft.Windows { .DESCRIPTION Documents the configuration of Microsoft Windows Server in Word/HTML/Text formats using PScribo. .NOTES - Version: 0.5.2 + Version: 0.5.3 Author: Andrew Ramsay Editor: Jonathan Colon Twitter: @asbuiltreport @@ -235,7 +235,7 @@ function Invoke-AsBuiltReport.Microsoft.Windows { if ($SMBShares) { Section -Style Heading2 "File Server Configuration" { Paragraph 'The following table details the File Server settings' - BlankLine + BlankLine # SMB Server Configuration Get-AbrWinSMBSummary # SMB Server Network Interface @@ -341,6 +341,53 @@ 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 } + if ($Status.Status -eq "Running") { + try { + $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' + BlankLine + # SQL Server Build Information + Get-AbrWinSQLBuild + # SQL Server Security Information + Section -Style Heading3 "Security" { + Paragraph 'The following table details the SQL Server security settings' + BlankLine + # SQL Server Roles Information + Get-AbrWinSQLRole + # SQL Server Logins Information + Get-AbrWinSQLLogin + } + # SQL Server Database Information + Get-AbrWinSQLDatabase + # SQL Server Server Objects Information + $BackupDevices = Get-AbrWinSQLBackupDevice + if ($BackupDevices) { + Section -Style Heading3 "Server Objects" { + Paragraph 'The following table details the SQL Server server objects settings' + BlankLine + # SQL Server Backup Devices Information + $BackupDevices + } + } + } + # Disconnect SQL Instance + Write-PScriboMessage "Disconnecting SQL Instance $($Options.Instance)" + $SQLServer | Disconnect-DbaInstance | Out-Null + } else { + Write-PScriboMessage -IsWarning "Unable to connect to SQL Instance $($Options.Instance)" + } + } catch { + Write-PScriboMessage -IsWarning $_.Exception.Message + } + } else { + Write-PScriboMessage "No SQL Server service detected. Disabling SQL Server section" + } + } + } Remove-PSSession $TempPssSession Remove-CimSession $TempCimSession