Skip to content

Commit

Permalink
Merge pull request #600 from microsoft/main
Browse files Browse the repository at this point in the history
Release 5-25
  • Loading branch information
dpaulson45 authored May 26, 2021
2 parents 7109a6c + 9d53864 commit 9bcd3c5
Show file tree
Hide file tree
Showing 26 changed files with 570 additions and 218 deletions.
14 changes: 13 additions & 1 deletion .build/CodeFormatter.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,9 @@ foreach ($file in $scriptFiles) {
}
}

$reloadFile = $false
$before = Get-Content $file -Raw
$after = Invoke-Formatter -ScriptDefinition (Get-Content $file -Raw) -Settings $repoRoot\PSScriptAnalyzerSettings.psd1
$after = Invoke-Formatter -ScriptDefinition $before -Settings $repoRoot\PSScriptAnalyzerSettings.psd1

if ($before -ne $after) {
Write-Warning ("{0}:" -f $file)
Expand All @@ -71,6 +72,7 @@ foreach ($file in $scriptFiles) {
try {
Set-Content -Path $file -Value $after -Encoding utf8NoBOM
Write-Information "Saved $file with formatting corrections."
$reloadFile = $true
} catch {
$filesFailed = $true
Write-Warning "Failed to save $file with formatting corrections."
Expand All @@ -81,6 +83,16 @@ foreach ($file in $scriptFiles) {
}
}

if ($reloadFile) {
$before = Get-Content -Path $file -Raw
}

if (-not ([string]::IsNullOrWhiteSpace($before[-1]))) {
Write-Warning $file
Write-Warning "Failed to have a whitespace at the end of the file"
$filesFailed = $true
}

$analyzerResults = Invoke-ScriptAnalyzer -Path $file -Settings $repoRoot\PSScriptAnalyzerSettings.psd1
if ($null -ne $analyzerResults) {
$filesFailed = $true
Expand Down
5 changes: 4 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,8 @@
"files.encoding": "utf8",
"[powershell]": {
"files.encoding": "utf8bom"
}
},
"cSpell.words": [
"cmdlet"
]
}
200 changes: 200 additions & 0 deletions Admin/Get-SimpleAuditLogReport.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
<#
.SYNOPSIS
Parses the output of Search-AdminAuditlog to produce more readable results.
.DESCRIPTION
Takes the output of the Search-AdminAuditlog as an input and reconstructs the
results into a more easily read structure.
Results can be stored in a variable and sent to the script with -searchresults
or taken directly off of a pipeline and converted.
Output should generally contain commands that can be copied and pasted into
an Exchange/Exchange Online Shell and run directly with little to no
Modification.
.PARAMETER SeachResults
Output of the Search-AdminAuditLog. Either stored in a variable or pipelined
into the script.
.PARAMETER ResolveCaller
Attempts to resolve the alias of the person who ran the command into the
primary SMTP address.
.PARAMETER Agree
Verifies you have read and agree to the disclaimer at the top of the script file
.OUTPUTS
Creates an output that contains the following information:
Caller : Person who ran the command
Cmdlet : Cmdlet that was run
FullCommand : Reconstructed full command that was run
RunDate : Date and Time command was run
ObjectModified : Object that was modified by the command
.EXAMPLE
$Search = Search-AdminAuditLog
$search | C:\Scripts\Get-SimpleAuditLogReport.ps1 -agree
Converts the results of Search-AdminAuditLog and sends the output to the screen
.EXAMPLE
Search-AdminAuditLog | C:\Scripts\Get-SimpleAuditlogReport.ps1 -agree | Export-CSV -path C:\temp\auditlog.csv
Converts the restuls of Search-AdminAuditLog and sends the output to a CSV file
.EXAMPLE
$MySearch = Search-AdminAuditLog -cmdlet set-mailbox
C:\Script\C:\Scripts\Get-SimpleAuditLogReport.ps1 -agree -searchresults $MySearch
Finds all instances of set-mailbox
Converts them by passing in the results to the switch searchresults
Outputs to the screen
#>

Param (
[Parameter(Position = 0, Mandatory = $true, ValueFromPipelinepeline = $true, ValueFromPipelineByPropertyName = $true)]
$SearchResults,
[switch]$ResolveCaller,
[switch]$Agree
)

# Setup to process incomming results
Begin {

# Statement to ensure that you have looked at the disclaimer or that you have removed this line so you don't have too
If ($Agree -ne $true) { Write-Error "Please run the script with -Agree to indicate that you have read and agreed to the sample script disclaimer at the top of the script file" -ErrorAction Stop }

# Make sure the array is null
[array]$ResultSet = $null

# Set the counter to 1
$i = 1

# If resolveCaller is called it can take much longer to run so notify the user of that
if ($ResolveCaller) { Write-Warning "ResolveCaller specified; Script will take significantly longer to run as it attemps to resolve the primary SMTP address of each calling user. Progress updates will be provided every 25 entries." }
}

# Process thru what ever is comming into the script
Process {

# Deal with each object in the input
$searchresults | ForEach-Object {

# Reset the result object
$Result = New-Object PSObject

# Get the alias of the User that ran the command
$user = ($_.caller.split("/"))[-1]

# If we used resolve caller then try to resolve the primary SMTP address of the calling user
if ($ResolveCaller) {

# attempt to resolve the recipient
[string]$Recipient = (get-recipient $user -ErrorAction silentlycontinue).primarysmtpaddress

# if we get a result then put that in the output otherwise do nothing
If (!([string]::IsNullOrEmpty($Recipient))) { $user = $Recipient }

# Since this is going to take longer to run provide status every 25 entries
if ($i % 25 -eq 0) { Write-Host "Processed 25 Results" }
$i++
}

# Build the command that was run
$switches = $_.cmdletparameters
[string]$FullCommand = $_.cmdletname

# Get all of the switchs and add them in "human" form to the output
foreach ($parameter in $switches) {

# Format our values depending on what they are so that they are as close
# a match as possible for what would have been entered
switch -regex ($parameter.value) {

# If we have a multi value array put in then we need to break it out and add quotes as needed
'[;]' {

# Reset the formatted value string
$FormattedValue = $null

# Split it into an array
$valuearray = $switch.current.split(";")

# For each entry in the array add quotes if needed and add it to the formatted value string
$valuearray | ForEach-Object {
if ($_ -match "[ \t]") { $FormattedValue = $FormattedValue + "`"" + $_ + "`";" }
else { $FormattedValue = $FormattedValue + $_ + ";" }
}

# Clean up the trailing ;
$FormattedValue = $FormattedValue.trimend(";")

# Add our switch + cleaned up value to the command string
$FullCommand = $FullCommand + " -" + $parameter.name + " " + $FormattedValue
}

# If we have a value with spaces add quotes
'[ \t]' { $FullCommand = $FullCommand + " -" + $parameter.name + " `"" + $switch.current + "`"" }

# If we have a true or false format them with :$ in front ( -allow:$true )
'^True$|^False$' { $FullCommand = $FullCommand + " -" + $parameter.name + ":`$" + $switch.current }

# Otherwise just put the switch and the value
default { $FullCommand = $FullCommand + " -" + $parameter.name + " " + $switch.current }
}
}
}

# Pull out the Modified properties
$ModifiedProperties = $_.modifiedproperties

# Make sure our holding variable are nulled out
$Property = $null
$Oldvalue = $null
$NewValue = $null

# Push each property set into a seperate string
$ModifiedProperties | ForEach-Object {
[string]$Property = $Property + $_.name + ";"
[string]$OldValue = $OldValue + $_.oldvalue + ";"
[string]$NewValue = $NewValue + $_.newvalue + ";"
}

# Trim off the last ;
$Property = $Property.TrimEnd(";")
$Oldvalue = $Oldvalue.TrimEnd(";")
$NewValue = $NewValue.TrimEnd(";")

# Format our modified object
if ([string]::IsNullOrEmpty($_.objectModified)) {
$ObjModified = ""
} else {
$ObjModified = ($_.objectmodified.split("/"))[-1]
$ObjModified = ($ObjModified.split("\"))[-1]
}

# Get just the name of the cmdlet that was run
[string]$cmdlet = $_.CmdletName

# Build the result object to return our values
$Result | Add-Member -MemberType NoteProperty -Value $user -Name Caller
$Result | Add-Member -MemberType NoteProperty -Value $cmdlet -Name Cmdlet
$Result | Add-Member -MemberType NoteProperty -Value $FullCommand -Name FullCommand
$Result | Add-Member -MemberType NoteProperty -Value $_.rundate -Name RunDate
$Result | Add-Member -MemberType NoteProperty -Value $ObjModified -Name ObjectModified
$Result | Add-Member -MemberType NoteProperty -Value $Property -Name ModifiedProperties
$Result | Add-Member -MemberType NoteProperty -Value $Oldvalue -Name OldValue
$Result | Add-Member -MemberType NoteProperty -Value $NewValue -Name NewValue

# Add the object to the array to be returned
$ResultSet = $ResultSet + $Result
}
# Final steps
End {
# Return the array set
Return $ResultSet
}
30 changes: 27 additions & 3 deletions Diagnostics/HealthChecker/Analyzer/Invoke-AnalyzerEngine.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -1257,15 +1257,13 @@
}

if ($certificate.PublicKeySize -lt 2048) {
$additionalDisplayValue = "It's recommended to use a key size of at least 2048 bit."

$analyzedResults = Add-AnalyzedResultInformation -Name "Key size" -Details $certificate.PublicKeySize `
-DisplayGroupingKey $keySecuritySettings `
-DisplayCustomTabNumber 2 `
-DisplayWriteType "Red" `
-AnalyzedInformation $analyzedResults

$analyzedResults = Add-AnalyzedResultInformation -Details $additionalDisplayValue `
$analyzedResults = Add-AnalyzedResultInformation -Details "It's recommended to use a key size of at least 2048 bit" `
-DisplayGroupingKey $keySecuritySettings `
-DisplayCustomTabNumber 2 `
-DisplayWriteType "Red" `
Expand All @@ -1277,6 +1275,32 @@
-AnalyzedInformation $analyzedResults
}

if ($certificate.SignatureHashAlgorithmSecure -eq 1) {
$shaDisplayWriteType = "Yellow"
} else {
$shaDisplayWriteType = "Grey"
}

$analyzedResults = Add-AnalyzedResultInformation -Name "Signature Algorithm" -Details $certificate.SignatureAlgorithm `
-DisplayGroupingKey $keySecuritySettings `
-DisplayCustomTabNumber 2 `
-DisplayWriteType $shaDisplayWriteType `
-AnalyzedInformation $analyzedResults

$analyzedResultsults = Add-AnalyzedResultInformation -Name "Signature Hash Algorithm" -Details $certificate.SignatureHashAlgorithm `
-DisplayGroupingKey $keySecuritySettings `
-DisplayCustomTabNumber 2 `
-DisplayWriteType $shaDisplayWriteType `
-AnalyzedInformation $analyzedResults

if ($shaDisplayWriteType -eq "Yellow") {
$analyzedResults = Add-AnalyzedResultInformation -Details "It's recommended to use a hash algorithm from the SHA-2 family `r`n`t`tMore information: https://techcommunity.microsoft.com/t5/exchange-team-blog/exchange-tls-038-ssl-best-practices/ba-p/603798" `
-DisplayGroupingKey $keySecuritySettings `
-DisplayCustomTabNumber 2 `
-DisplayWriteType $shaDisplayWriteType `
-AnalyzedInformation $analyzedResults
}

if ($null -ne $certificate.Services) {
$analyzedResults = Add-AnalyzedResultInformation -Name "Bound to services" -Details $certificate.Services `
-DisplayGroupingKey $keySecuritySettings `
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,59 @@
$certStatus = ($cert.Status).ToString()
}

if ([String]::IsNullOrEmpty($cert.SignatureAlgorithm.FriendlyName)) {
$certSignatureAlgorithm = "Unknown"
$certSignatureHashAlgorithm = "Unknown"
$certSignatureHashAlgorithmSecure = 0
} else {
$certSignatureAlgorithm = $cert.SignatureAlgorithm.FriendlyName
<#
OID Table
https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-gpnap/a48b02b2-2a10-4eb0-bed4-1807a6d2f5ad
SignatureHashAlgorithmSecure = Unknown 0
SignatureHashAlgorithmSecure = Insecure/Weak 1
SignatureHashAlgorithmSecure = Secure 2
#>
switch ($cert.SignatureAlgorithm.Value) {
"1.2.840.113549.1.1.5" { $certSignatureHashAlgorithm = "sha1"; $certSignatureHashAlgorithmSecure = 1 }
"1.2.840.113549.1.1.4" { $certSignatureHashAlgorithm = "md5"; $certSignatureHashAlgorithmSecure = 1 }
"1.2.840.10040.4.3" { $certSignatureHashAlgorithm = "sha1"; $certSignatureHashAlgorithmSecure = 1 }
"1.3.14.3.2.29" { $certSignatureHashAlgorithm = "sha1"; $certSignatureHashAlgorithmSecure = 1 }
"1.3.14.3.2.15" { $certSignatureHashAlgorithm = "sha1"; $certSignatureHashAlgorithmSecure = 1 }
"1.3.14.3.2.3" { $certSignatureHashAlgorithm = "md5"; $certSignatureHashAlgorithmSecure = 1 }
"1.2.840.113549.1.1.2" { $certSignatureHashAlgorithm = "md2"; $certSignatureHashAlgorithmSecure = 1 }
"1.2.840.113549.1.1.3" { $certSignatureHashAlgorithm = "md4"; $certSignatureHashAlgorithmSecure = 1 }
"1.3.14.3.2.2" { $certSignatureHashAlgorithm = "md4"; $certSignatureHashAlgorithmSecure = 1 }
"1.3.14.3.2.4" { $certSignatureHashAlgorithm = "md4"; $certSignatureHashAlgorithmSecure = 1 }
"1.3.14.7.2.3.1" { $certSignatureHashAlgorithm = "md2"; $certSignatureHashAlgorithmSecure = 1 }
"1.3.14.3.2.13" { $certSignatureHashAlgorithm = "sha1"; $certSignatureHashAlgorithmSecure = 1 }
"1.3.14.3.2.27" { $certSignatureHashAlgorithm = "sha1"; $certSignatureHashAlgorithmSecure = 1 }
"2.16.840.1.101.2.1.1.19" { $certSignatureHashAlgorithm = "mosaicSignature"; $certSignatureHashAlgorithmSecure = 0 }
"1.3.14.3.2.26" { $certSignatureHashAlgorithm = "sha1"; $certSignatureHashAlgorithmSecure = 1 }
"1.2.840.113549.2.5" { $certSignatureHashAlgorithm = "md5"; $certSignatureHashAlgorithmSecure = 1 }
"2.16.840.1.101.3.4.2.1" { $certSignatureHashAlgorithm = "sha256"; $certSignatureHashAlgorithmSecure = 2 }
"2.16.840.1.101.3.4.2.2" { $certSignatureHashAlgorithm = "sha384"; $certSignatureHashAlgorithmSecure = 2 }
"2.16.840.1.101.3.4.2.3" { $certSignatureHashAlgorithm = "sha512"; $certSignatureHashAlgorithmSecure = 2 }
"1.2.840.113549.1.1.11" { $certSignatureHashAlgorithm = "sha256"; $certSignatureHashAlgorithmSecure = 2 }
"1.2.840.113549.1.1.12" { $certSignatureHashAlgorithm = "sha384"; $certSignatureHashAlgorithmSecure = 2 }
"1.2.840.113549.1.1.13" { $certSignatureHashAlgorithm = "sha512"; $certSignatureHashAlgorithmSecure = 2 }
"1.2.840.113549.1.1.10" { $certSignatureHashAlgorithm = "rsassa-pss"; $certSignatureHashAlgorithmSecure = 2 }
"1.2.840.10045.4.1" { $certSignatureHashAlgorithm = "sha1"; $certSignatureHashAlgorithmSecure = 1 }
"1.2.840.10045.4.3.2" { $certSignatureHashAlgorithm = "sha256"; $certSignatureHashAlgorithmSecure = 2 }
"1.2.840.10045.4.3.3" { $certSignatureHashAlgorithm = "sha384"; $certSignatureHashAlgorithmSecure = 2 }
"1.2.840.10045.4.3.4" { $certSignatureHashAlgorithm = "sha512"; $certSignatureHashAlgorithmSecure = 2 }
"1.2.840.10045.4.3" { $certSignatureHashAlgorithm = "sha256"; $certSignatureHashAlgorithmSecure = 2 }
Default { $certSignatureHashAlgorithm = "Unknown"; $certSignatureHashAlgorithmSecure = 0 }
}
}

$certInformationObj = New-Object PSCustomObject
$certInformationObj | Add-Member -MemberType NoteProperty -Name "FriendlyName" -Value $certFriendlyName
$certInformationObj | Add-Member -MemberType NoteProperty -Name "Thumbprint" -Value $cert.Thumbprint
$certInformationObj | Add-Member -MemberType NoteProperty -Name "PublicKeySize" -Value $cert.PublicKey.Key.KeySize
$certInformationObj | Add-Member -MemberType NoteProperty -Name "SignatureAlgorithm" -Value $certSignatureAlgorithm
$certInformationObj | Add-Member -MemberType NoteProperty -Name "SignatureHashAlgorithm" -Value $certSignatureHashAlgorithm
$certInformationObj | Add-Member -MemberType NoteProperty -Name "SignatureHashAlgorithmSecure" -Value $certSignatureHashAlgorithmSecure
$certInformationObj | Add-Member -MemberType NoteProperty -Name "IsSanCertificate" -Value $sanCertificateInfo
$certInformationObj | Add-Member -MemberType NoteProperty -Name "Namespaces" -Value $certDnsNameList
$certInformationObj | Add-Member -MemberType NoteProperty -Name "Services" -Value $cert.Services
Expand Down
4 changes: 2 additions & 2 deletions Search/Troubleshoot-ModernSearch.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ $BuildVersion = ""
. $PSScriptRoot\Troubleshoot-ModernSearch\StoreQuery\Get-FolderInformation.ps1
. $PSScriptRoot\Troubleshoot-ModernSearch\StoreQuery\Get-MessageIndexState.ps1
. $PSScriptRoot\Troubleshoot-ModernSearch\StoreQuery\Get-QueryItemResult.ps1
. $PSScriptRoot\Troubleshoot-ModernSearch\StoreQuery\Get-StoreQueryHandler.ps1
. $PSScriptRoot\Troubleshoot-ModernSearch\StoreQuery\StoreQueryFunctions.ps1

. $PSScriptRoot\Troubleshoot-ModernSearch\Write\Write-BasicMailboxInformation.ps1
. $PSScriptRoot\Troubleshoot-ModernSearch\Write\Write-CheckSearchProcessState.ps1
Expand Down Expand Up @@ -140,7 +140,7 @@ Function Main {
Write-BasicMailboxInformation -MailboxInformation $mailboxInformation
Write-CheckSearchProcessState -ActiveServer $mailboxInformation.PrimaryServer

$storeQueryHandler = Get-StoreQueryHandler -MailboxInformation $mailboxInformation
$storeQueryHandler = Get-StoreQueryObject -MailboxInformation $mailboxInformation
$basicMailboxQueryContext = Get-BasicMailboxQueryContext -StoreQueryHandler $storeQueryHandler

Write-DisplayObjectInformation -DisplayObject $basicMailboxQueryContext -PropertyToDisplay @(
Expand Down
Loading

0 comments on commit 9bcd3c5

Please sign in to comment.