Skip to content

Commit

Permalink
Fix for PSScriptAnalyzer issues
Browse files Browse the repository at this point in the history
  • Loading branch information
rebelinux committed Jun 8, 2024
1 parent a5a81e4 commit c11c0d3
Show file tree
Hide file tree
Showing 12 changed files with 68 additions and 55 deletions.
17 changes: 12 additions & 5 deletions .github/workflows/PSScriptAnalyzerSettings.psd1
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
@{
ExcludeRules = @(
'PSUseBOMForUnicodeEncodedFile',
'PSUseToExportFieldsInManifest',
'PSReviewUnusedParameter',
'PSUseDeclaredVarsMoreThanAssignments',
'PSAvoidGlobalVars',
'PSAvoidUsingEmptyCatchBlock'
'PSUseToExportFieldsInManifest'
)
Rules = @{
PSAvoidExclaimOperator = @{
Enable = $true
}
AvoidUsingDoubleQuotesForConstantString = @{
Enable = $true
}
UseCorrectCasing = @{
Enable = $true
}
}
}
2 changes: 1 addition & 1 deletion AsBuiltReport.Microsoft.AD.Style.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ if ($ReportConfig.Report.ShowHeaderFooter) {
}

# Set position of report titles and information based on page orientation
if (!($ReportConfig.Report.ShowCoverPageImage)) {
if (-Not ($ReportConfig.Report.ShowCoverPageImage)) {
$LineCount = 5
}
if ($Orientation -eq 'Portrait') {
Expand Down
9 changes: 5 additions & 4 deletions Src/Private/Get-AbrADDCRoleFeature.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,13 @@ function Get-AbrADDCRoleFeature {

process {
try {
$DCPssSession = New-PSSession $DC -Credential $Credential -Authentication $Options.PSDefaultAuthentication -Name 'ADDCRoleFeature'
if ($DCPssSession) {
if ($DCPssSession = New-PSSession $DC -Credential $Credential -Authentication $Options.PSDefaultAuthentication -Name 'ADDCRoleFeature') {
$Features = Invoke-Command -Session $DCPssSession -ScriptBlock { Get-WindowsFeature | Where-Object { $_.installed -eq "True" -and $_.FeatureType -eq 'Role' } }
Remove-PSSession -Session $DCPssSession
}
if ($Features) {
Section -ExcludeFromTOC -Style NOTOCHeading5 $($DC.ToString().ToUpper().Split(".")[0]) {
$OutObj = @()
$Features = Invoke-Command -Session $DCPssSession -ScriptBlock { Get-WindowsFeature | Where-Object { $_.installed -eq "True" -and $_.FeatureType -eq 'Role' } }
Remove-PSSession -Session $DCPssSession
foreach ($Feature in $Features) {
try {
$inObj = [ordered] @{
Expand Down
4 changes: 2 additions & 2 deletions Src/Private/Get-AbrADDomainController.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ function Get-AbrADDomainController {
try {
$OutObj = @()
$inObj = [ordered] @{
'Domain Controller' = $DomainController.Count
'Global Catalog' = $GC.Count
'Domain Controller' = ($DomainController | Measure-Object).Count
'Global Catalog' = ($GC | Measure-Object).Count
}
$OutObj += [pscustomobject]$inobj

Expand Down
10 changes: 5 additions & 5 deletions Src/Private/Get-AbrADDomainObject.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -524,8 +524,8 @@ function Get-AbrADDomainObject {
try {
$OutObj = @()
$inObj = [ordered] @{
'Computers' = $Computers.Count
'Servers' = $Servers.Count
'Computers' = ($Computers | Measure-Object).Count
'Servers' = ($Servers | Measure-Object).Count
}
$OutObj += [pscustomobject]$inobj

Expand Down Expand Up @@ -692,9 +692,9 @@ function Get-AbrADDomainObject {
'DNS HostName' = ConvertTo-EmptyToFiller $Computer.DNSHostName
'Operating System' = ConvertTo-EmptyToFiller $Computer.operatingSystem
'Status' = Switch ($Computer.Enabled) {
'True' {'Enabled'}
'False' {'Disabled'}
default {'Unknown'}
'True' { 'Enabled' }
'False' { 'Disabled' }
default { 'Unknown' }
}
}
$OutObj += [pscustomobject]$inobj
Expand Down
2 changes: 1 addition & 1 deletion Src/Private/Get-AbrADForest.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ function Get-AbrADForest {
Paragraph 'In cryptography, a certificate authority or certification authority (CA) is an entity that issues digital certificates. A digital certificate certifies the ownership of a public key by the named subject of the certificate. This allows others (relying parties) to rely upon signatures or on assertions made about the private key that corresponds to the certified public key. A CA acts as a trusted third party trusted both by the subject (owner) of the certificate and by the party relying upon the certificate. The format of these certificates is specified by the X.509 or EMV standard.'
BlankLine
}
if (!$Options.ShowDefinitionInfo) {
if (-Not $Options.ShowDefinitionInfo) {
Paragraph "The following section provides a summary of the Active Directory PKI Infrastructure Information."
BlankLine
}
Expand Down
48 changes: 25 additions & 23 deletions Src/Private/Get-AbrADInfrastructureService.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -30,41 +30,43 @@ function Get-AbrADInfrastructureService {
process {
try {
$DCPssSession = New-PSSession $DC -Credential $Credential -Authentication $Options.PSDefaultAuthentication -Name 'DomainControllerInfrastructureServices'
$Available = Invoke-Command -Session $DCPssSession -ScriptBlock { Get-Service "W32Time" | Select-Object DisplayName, Name, Status }
if ($Available) {
Section -ExcludeFromTOC -Style NOTOCHeading5 $($DC.ToString().ToUpper().Split(".")[0]) {
$OutObj = @()
if ($DC) {
$Services = @('CertSvc', 'DHCPServer', 'DNS', 'DFS Replication', 'Intersite Messaging', 'Kerberos Key Distribution Center', 'NetLogon', 'Active Directory Domain Services', 'W32Time', 'ADWS', 'RPCSS', 'EVENTSYSTEM', 'DNSCACHE', 'SAMSS', 'WORKSTATION', 'Spooler')
foreach ($Service in $Services) {
try {
$Status = Invoke-Command -Session $DCPssSession -ScriptBlock { Get-Service $using:Service -ErrorAction SilentlyContinue | Select-Object DisplayName, Name, Status }
if ($Status) {
$inObj = [ordered] @{
'Display Name' = $Status.DisplayName
'Short Name' = $Status.Name
'Status' = $Status.Status
}
$OutObj += [pscustomobject]$inobj
}
} catch {
Write-PScriboMessage -IsWarning "$($_.Exception.Message) (Domain Controller Infrastructure Services Item)"
if ($DCPssSession -and ($Available = Invoke-Command -Session $DCPssSession -ScriptBlock { Get-Service "W32Time" | Select-Object DisplayName, Name, Status })) {
$OutObj = @()
$Services = @('CertSvc', 'DHCPServer', 'DNS', 'DFS Replication', 'Intersite Messaging', 'Kerberos Key Distribution Center', 'NetLogon', 'Active Directory Domain Services', 'W32Time', 'ADWS', 'RPCSS', 'EVENTSYSTEM', 'DNSCACHE', 'SAMSS', 'WORKSTATION', 'Spooler')
foreach ($Service in $Services) {
try {
$Status = Invoke-Command -Session $DCPssSession -ScriptBlock { Get-Service $using:Service -ErrorAction SilentlyContinue | Select-Object DisplayName, Name, Status }
if ($Status) {
$inObj = [ordered] @{
'Display Name' = $Status.DisplayName
'Short Name' = $Status.Name
'Status' = $Status.Status
}
$OutObj += [pscustomobject]$inobj
}
} catch {
Write-PScriboMessage -IsWarning "$($_.Exception.Message) (Domain Controller Infrastructure Services Item)"
}
}

if ($HealthCheck.DomainController.Services) {
$OutObj | Where-Object { $_.'Status' -notlike 'Running' -and $_.'Short Name' -notlike 'Spooler' } | Set-Style -Style Warning -Property 'Status'
$OutObj | Where-Object { $_.'Short Name' -eq 'Spooler' } | Set-Style -Style Critical
}
if ($HealthCheck.DomainController.Services) {
$OutObj | Where-Object { $_.'Status' -notlike 'Running' -and $_.'Short Name' -notlike 'Spooler' } | Set-Style -Style Warning -Property 'Status'
$OutObj | Where-Object { $_.'Short Name' -eq 'Spooler' } | Set-Style -Style Critical
}

if ($OutObj) {
Section -ExcludeFromTOC -Style NOTOCHeading5 $($DC.ToString().ToUpper().Split(".")[0]) {

$TableParams = @{
Name = "Infrastructure Services Status - $($DC.ToString().ToUpper().Split(".")[0])"
List = $false
ColumnWidths = 40, 40, 20
}

if ($Report.ShowTableCaptions) {
$TableParams['Caption'] = "- $($TableParams.Name)"
}

$OutObj | Sort-Object -Property 'Display Name' | Table @TableParams
if ($HealthCheck.DomainController.Services -and ($OutObj | Where-Object { $_.'Short Name' -eq 'Spooler' -and $_.'Status' -like 'Running' })) {
Paragraph "Health Check:" -Bold -Underline
Expand Down
4 changes: 2 additions & 2 deletions Src/Private/Get-AbrADTrust.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ function Get-AbrADTrust {
16 { "Cross-Organizational Trust (Selective Authentication)" }
32 { "Intra-Forest Trust (trust within the forest)" }
64 { "Inter-Forest Trust (trust with another forest)" }
default {$Trust.TrustAttributes}
default { $Trust.TrustAttributes }
}
'Trust Direction' = Switch ($Trust.TrustDirection) {
0 { "Disabled (The trust relationship exists but has been disabled)" }
1 { "Inbound (TrustING domain)" }
2 { "Outbound (TrustED domain)" }
3 { "Bidirectional (two-way trust)" }
default {$Trust.TrustDirection}
default { $Trust.TrustDirection }
}
'IntraForest' = ConvertTo-TextYN $Trust.IntraForest
'Selective Authentication' = ConvertTo-TextYN $Trust.SelectiveAuthentication
Expand Down
2 changes: 1 addition & 1 deletion Src/Private/Get-AbrDNSSection.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function Get-AbrDNSSection {
Paragraph "The Domain Name System (DNS) is a hierarchical and decentralized naming system for computers, services, or other resources connected to the Internet or a private network. It associates various information with domain names assigned to each of the participating entities. Most prominently, it translates more readily memorized domain names to the numerical IP addresses needed for locating and identifying computer services and devices with the underlying network protocols."
BlankLine
}
if (!$Options.ShowDefinitionInfo) {
if (-Not $Options.ShowDefinitionInfo) {
Paragraph "The following section provides a summary of the Active Directory DNS Infrastructure Information."
BlankLine
}
Expand Down
21 changes: 12 additions & 9 deletions Src/Private/Get-AbrDomainSection.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function Get-AbrDomainSection {
Paragraph "An Active Directory domain is a collection of objects within a Microsoft Active Directory network. An object can be a single user or a group or it can be a hardware component, such as a computer or printer.Each domain holds a database containing object identity information. Active Directory domains can be identified using a DNS name, which can be the same as an organization's public domain name, a sub-domain or an alternate version (which may end in .local)."
BlankLine
}
if (!$Options.ShowDefinitionInfo) {
if (-Not $Options.ShowDefinitionInfo) {
Paragraph "The following section provides a summary of the Active Directory Domain Information."
BlankLine
}
Expand Down Expand Up @@ -69,7 +69,7 @@ function Get-AbrDomainSection {
Paragraph "A domain controller (DC) is a server computer that responds to security authentication requests within a computer network domain. It is a network server that is responsible for allowing host access to domain resources. It authenticates users, stores user account information and enforces security policy for a domain."
BlankLine
}
if (!$Options.ShowDefinitionInfo) {
if (-Not $Options.ShowDefinitionInfo) {
if ($InfoLevel.Domain -ge 2) {
Paragraph "The following section provides detailed information about Active Directory domain controllers."
BlankLine
Expand All @@ -89,7 +89,7 @@ function Get-AbrDomainSection {
Paragraph "The following section provides a summary of installed role & features on $Domain DCs."
foreach ($DC in $DCs) {
$DCStatus = Test-Connection -ComputerName $DC -Quiet -Count 2
if ($DCStatus -eq $false) {
if (-Not $DCStatus) {
Write-PScriboMessage -IsWarning "Unable to connect to $DC. Removing it from the $Domain report"
}
if ($DCStatus) {
Expand All @@ -115,12 +115,15 @@ function Get-AbrDomainSection {
}
}
try {
Section -Style Heading4 "Infrastructure Services" {
Paragraph "The following section provides a summary of the Domain Controller Infrastructure services status."
foreach ($DC in $DCs) {
if (Test-Connection -ComputerName $DC -Quiet -Count 2) {
Get-AbrADInfrastructureService -DC $DC
}
$ADInfraServices = foreach ($DC in $DCs) {
if (Test-Connection -ComputerName $DC -Quiet -Count 2) {
Get-AbrADInfrastructureService -DC $DC
}
}
if ($ADInfraServices) {
Section -Style Heading4 "Infrastructure Services" {
Paragraph "The following section provides a summary of the Domain Controller Infrastructure services status."
$ADInfraServices
}
}
} catch {
Expand Down
2 changes: 1 addition & 1 deletion Src/Private/Get-AbrForestSection.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function Get-AbrForestSection {
Paragraph "The Active Directory framework that holds the objects can be viewed at a number of levels. The forest, tree, and domain are the logical divisions in an Active Directory network. At the top of the structure is the forest. A forest is a collection of trees that share a common global catalog, directory schema, logical structure, and directory configuration. The forest represents the security boundary within which users, computers, groups, and other objects are accessible."
BlankLine
}
if (!$Options.ShowDefinitionInfo) {
if (-Not $Options.ShowDefinitionInfo) {
Paragraph "The following section provides a summary of the Active Directory Forest Information."
BlankLine
}
Expand Down
2 changes: 1 addition & 1 deletion Src/Private/Get-AbrPKISection.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function Get-AbrPKISection {
Paragraph 'In cryptography, a certificate authority or certification authority (CA) is an entity that issues digital certificates. A digital certificate certifies the ownership of a public key by the named subject of the certificate. This allows others (relying parties) to rely upon signatures or on assertions made about the private key that corresponds to the certified public key. A CA acts as a trusted third party trusted both by the subject (owner) of the certificate and by the party relying upon the certificate. The format of these certificates is specified by the X.509 or EMV standard.'
BlankLine
}
if (!$Options.ShowDefinitionInfo) {
if (-Not $Options.ShowDefinitionInfo) {
Paragraph "The following section provides a summary of the Active Directory PKI Infrastructure Information."
BlankLine
}
Expand Down

0 comments on commit c11c0d3

Please sign in to comment.