diff --git a/.build/CodeFormatter.ps1 b/.build/CodeFormatter.ps1 index 960548287a..9cb85b1968 100644 --- a/.build/CodeFormatter.ps1 +++ b/.build/CodeFormatter.ps1 @@ -20,11 +20,11 @@ Set-StrictMode -Version Latest . $PSScriptRoot\CodeFormatterChecks\CheckMultipleEmptyLines.ps1 . $PSScriptRoot\CodeFormatterChecks\CheckScriptFileHasBOM.ps1 . $PSScriptRoot\CodeFormatterChecks\CheckScriptFileHasComplianceHeader.ps1 -. $PSScriptRoot\CodeFormatterChecks\CheckKeywordCasing.ps1 . $PSScriptRoot\CodeFormatterChecks\CheckScriptFormat.ps1 +. $PSScriptRoot\CodeFormatterChecks\CheckTokenTypeCasing.ps1 . $PSScriptRoot\HelpFunctions\Get-CommitFilesOnBranch.ps1 -if (-not (Load-Module -Name PSScriptAnalyzer -MinimumVersion "1.21")) { +if (-not (Load-Module -Name PSScriptAnalyzer -MinimumVersion "1.23")) { throw "PSScriptAnalyzer module could not be loaded" } @@ -68,7 +68,8 @@ foreach ($fileInfo in $filesToCheck) { $errorCount += (CheckMarkdownFileHasNoBOM $fileInfo $Save) ? 1 : 0 $errorCount += (CheckScriptFileHasBOM $fileInfo $Save) ? 1 : 0 $errorCount += (CheckScriptFileHasComplianceHeader $fileInfo $Save) ? 1 : 0 - $errorCount += (CheckKeywordCasing $fileInfo $Save) ? 1 : 0 + $errorCount += (CheckTokenTypeCasing $fileInfo $Save "Keyword") ? 1 : 0 + $errorCount += (CheckTokenTypeCasing $fileInfo $Save "Operator") ? 1 : 0 $errorCount += (CheckMultipleEmptyLines $fileInfo $Save) ? 1 : 0 $errorCount += (CheckContainsCurlyQuotes $fileInfo $Save) ? 1 : 0 diff --git a/.build/CodeFormatterChecks/CheckKeywordCasing.ps1 b/.build/CodeFormatterChecks/CheckTokenTypeCasing.ps1 similarity index 76% rename from .build/CodeFormatterChecks/CheckKeywordCasing.ps1 rename to .build/CodeFormatterChecks/CheckTokenTypeCasing.ps1 index 71d5796bb1..da24394e8a 100644 --- a/.build/CodeFormatterChecks/CheckKeywordCasing.ps1 +++ b/.build/CodeFormatterChecks/CheckTokenTypeCasing.ps1 @@ -1,7 +1,7 @@ # Copyright (c) Microsoft Corporation. # Licensed under the MIT License. -function CheckKeywordCasing { +function CheckTokenTypeCasing { [CmdletBinding()] [OutputType([boolean])] param ( @@ -11,7 +11,12 @@ function CheckKeywordCasing { [Parameter()] [boolean] - $Save + $Save, + + [Parameter()] + [ValidateSet("Operator", "Keyword")] + [string] + $Type ) if ($FileInfo.Extension -eq ".ps1" -or $FileInfo.Extension -eq ".psm1") { @@ -25,15 +30,15 @@ function CheckKeywordCasing { $keywordWrongCase = @() foreach ($t in $tokens) { - if ($t.Type -eq "Keyword") { + if ($t.Type -eq $Type) { if (-not $t.Content.Equals($t.Content.ToLower(), "Ordinal")) { $keywordWrongCase += $t if ($Save) { $content = $content.Remove($t.Start, $t.Length).Insert($t.Start, $t.Content.ToLower()) - Write-Host "Corrected case of keyword: $($t.Content) at position $($t.Start) in $($FileInfo.FullName)" + Write-Host "Corrected case of $Type`: $($t.Content) at position $($t.Start) in $($FileInfo.FullName)" } else { - Write-Warning "Keyword $($t.Content) at position $($t.Start) in $($FileInfo.FullName) is not lowercase." + Write-Warning "$Type $($t.Content) at position $($t.Start) in $($FileInfo.FullName) is not lowercase." } } } diff --git a/Admin/MonitorExchangeAuthCertificate/DataCollection/Get-ExchangeAuthCertificateStatus.ps1 b/Admin/MonitorExchangeAuthCertificate/DataCollection/Get-ExchangeAuthCertificateStatus.ps1 index d6e5e9ffcf..0ebc1a2242 100644 --- a/Admin/MonitorExchangeAuthCertificate/DataCollection/Get-ExchangeAuthCertificateStatus.ps1 +++ b/Admin/MonitorExchangeAuthCertificate/DataCollection/Get-ExchangeAuthCertificateStatus.ps1 @@ -47,7 +47,7 @@ function Get-ExchangeAuthCertificateStatus { $allMailboxServers = Get-ExchangeServer | Where-Object { ((($_.IsMailboxServer) -or ($_.IsClientAccessServer)) -and - ($_.AdminDisplayVersion -Match "^Version 15")) + ($_.AdminDisplayVersion -match "^Version 15")) } $multipleExchangeSites = (($allMailboxServers.Site.Name | Sort-Object -Unique).Count -gt 1) diff --git a/Admin/MonitorExchangeAuthCertificate/DataCollection/Test-IsServerValidForAuthCertificateGeneration.ps1 b/Admin/MonitorExchangeAuthCertificate/DataCollection/Test-IsServerValidForAuthCertificateGeneration.ps1 index 26504ad61a..0c6486472c 100644 --- a/Admin/MonitorExchangeAuthCertificate/DataCollection/Test-IsServerValidForAuthCertificateGeneration.ps1 +++ b/Admin/MonitorExchangeAuthCertificate/DataCollection/Test-IsServerValidForAuthCertificateGeneration.ps1 @@ -22,7 +22,7 @@ function Test-IsServerValidForAuthCertificateGeneration { $exchangeServerDetails = Get-ExchangeServer -Identity $ComputerName -ErrorAction Stop if (($exchangeServerDetails.IsMailboxServer) -and - (($exchangeServerDetails.AdminDisplayVersion -Match "^Version 15"))) { + (($exchangeServerDetails.AdminDisplayVersion -match "^Version 15"))) { Write-Verbose ("Exchange Server role and version is VALID to renew the Auth Certificate") $isValid = $true } else { diff --git a/Calendar/Get-RBASummary.ps1 b/Calendar/Get-RBASummary.ps1 index c05c8d4d5d..dd1d470064 100644 --- a/Calendar/Get-RBASummary.ps1 +++ b/Calendar/Get-RBASummary.ps1 @@ -539,8 +539,8 @@ function RBALogSummary { $LastDate = "[Unknown]" if ($starts.count -gt 1) { - $LastDate = ($Starts[0] -Split ",")[0].Trim() - $FirstDate = ($starts[$($Starts.count) -1 ] -Split ",")[0].Trim() + $LastDate = ($Starts[0] -split ",")[0].Trim() + $FirstDate = ($starts[$($Starts.count) -1 ] -split ",")[0].Trim() Write-Host "`tThe RBA Log for [$Identity] shows the following:" Write-Host "`t $($starts.count) Processed events times between $FirstDate and $LastDate" } @@ -555,19 +555,19 @@ function RBALogSummary { $Cancellations = $RBALog | Select-String -Pattern "It's a meeting cancellation." if ($AcceptLogs.count -ne 0) { - $LastAccept = ($AcceptLogs[0] -Split ",")[0].Trim() + $LastAccept = ($AcceptLogs[0] -split ",")[0].Trim() Write-Host "`t $($AcceptLogs.count) were Accepted between $FirstDate and $LastDate" Write-Host "`t`t with the last meeting Accepted on $LastAccept" } if ($TentativeLogs.count -ne 0) { - $LastTentative = ($TentativeLogs[0] -Split ",")[0].Trim() + $LastTentative = ($TentativeLogs[0] -split ",")[0].Trim() Write-Host "`t $($TentativeLogs.count) Tentatively Accepted meetings between $FirstDate and $LastDate" Write-Host "`t`t with the last meeting Tentatively Accepted on $LastTentative" } if ($DeclineLogs.count -ne 0) { - $LastDecline = ($DeclineLogs[0] -Split ",")[0].Trim() + $LastDecline = ($DeclineLogs[0] -split ",")[0].Trim() Write-Host "`t $($DeclineLogs.count) Declined meetings between $FirstDate and $LastDate" Write-Host "`t`t with the last meeting Declined on $LastDecline" } @@ -577,7 +577,7 @@ function RBALogSummary { } if ($UpdatedLogs.count -ne 0) { - $LastUpdated = ($UpdatedLogs[0] -Split ",")[0].Trim() + $LastUpdated = ($UpdatedLogs[0] -split ",")[0].Trim() Write-Host "`t $($UpdatedLogs.count) Updates to meetings between $FirstDate and $LastDate" Write-Host "`t`t with the last meeting updated on $LastUpdated" } else { @@ -591,7 +591,7 @@ function RBALogSummary { } if ($DelegateReferrals.count -ne 0) { - $LastDelegateReferral = ($DelegateReferrals[0] -Split ",")[0].Trim() + $LastDelegateReferral = ($DelegateReferrals[0] -split ",")[0].Trim() Write-Host "`t $($DelegateReferrals.count) Delegate Referrals were sent between $FirstDate and $LastDate" Write-Host "`t`t with the last Delegate Referral sent on $LastDelegateReferral" } else { @@ -599,7 +599,7 @@ function RBALogSummary { } if ($NonMeetingRequests.count -ne 0) { - $LastNonMeetingRequest = ($NonMeetingRequests[0] -Split ",")[0].Trim() + $LastNonMeetingRequest = ($NonMeetingRequests[0] -split ",")[0].Trim() Write-Host "`t $($NonMeetingRequests.count) Non Meeting Requests were skipped between $FirstDate and $LastDate" Write-Host "`t`t with the last Non Meeting Request skipped on $LastNonMeetingRequest" } else { diff --git a/Diagnostics/HealthChecker/Features/Get-LoadBalancingReport.ps1 b/Diagnostics/HealthChecker/Features/Get-LoadBalancingReport.ps1 index 9ee1ae692d..20a046a315 100644 --- a/Diagnostics/HealthChecker/Features/Get-LoadBalancingReport.ps1 +++ b/Diagnostics/HealthChecker/Features/Get-LoadBalancingReport.ps1 @@ -13,18 +13,18 @@ function Get-LoadBalancingReport { Write-Grey("Site filtering ON. Only Exchange 2013+ CAS servers in {0} will be used in the report." -f $SiteName) $CASServers = $getExchangeServer | Where-Object { ($_.IsClientAccessServer -eq $true) -and - ($_.AdminDisplayVersion -Match "^Version 15") -and + ($_.AdminDisplayVersion -match "^Version 15") -and ([System.Convert]::ToString($_.Site).Split("/")[-1] -eq $SiteName) } | Select-Object Name, Site | Sort-Object Name Write-Grey("Site filtering ON. Only Exchange 2013+ MBX servers in {0} will be used in the report." -f $SiteName) $MBXServers = $getExchangeServer | Where-Object { ($_.IsMailboxServer -eq $true) -and - ($_.AdminDisplayVersion -Match "^Version 15") -and + ($_.AdminDisplayVersion -match "^Version 15") -and ([System.Convert]::ToString($_.Site).Split("/")[-1] -eq $SiteName) } | Select-Object Name, Site | Sort-Object Name } else { if ( ($null -eq $ServerList) ) { Write-Grey("Filtering OFF. All Exchange 2013+ servers will be used in the report.") - $CASServers = $getExchangeServer | Where-Object { ($_.IsClientAccessServer -eq $true) -and ($_.AdminDisplayVersion -Match "^Version 15") } | Select-Object Name, Site | Sort-Object Name - $MBXServers = $getExchangeServer | Where-Object { ($_.IsMailboxServer -eq $true) -and ($_.AdminDisplayVersion -Match "^Version 15") } | Select-Object Name, Site | Sort-Object Name + $CASServers = $getExchangeServer | Where-Object { ($_.IsClientAccessServer -eq $true) -and ($_.AdminDisplayVersion -match "^Version 15") } | Select-Object Name, Site | Sort-Object Name + $MBXServers = $getExchangeServer | Where-Object { ($_.IsMailboxServer -eq $true) -and ($_.AdminDisplayVersion -match "^Version 15") } | Select-Object Name, Site | Sort-Object Name } else { Write-Grey("Custom server list is being used. Only servers specified after the -ServerList parameter will be used in the report.") $CASServers = $getExchangeServer | Where-Object { ($_.IsClientAccessServer -eq $true) -and ( ($_.Name -in $ServerList) -or ($_.FQDN -in $ServerList) ) } | Select-Object Name, Site | Sort-Object Name diff --git a/Diagnostics/ManagedAvailabilityTroubleshooter/ManagedAvailabilityTroubleshooter.ps1 b/Diagnostics/ManagedAvailabilityTroubleshooter/ManagedAvailabilityTroubleshooter.ps1 index d03f95d08f..4def3375f5 100644 --- a/Diagnostics/ManagedAvailabilityTroubleshooter/ManagedAvailabilityTroubleshooter.ps1 +++ b/Diagnostics/ManagedAvailabilityTroubleshooter/ManagedAvailabilityTroubleshooter.ps1 @@ -91,7 +91,7 @@ function InvestigateProbe { param([String]$ProbeToInvestigate , [String]$MonitorToInvestigate , [String]$ResponderToInvestigate , [String]$ResourceNameToInvestigate , [String]$ResponderTargetResource ) TestFileOrCmd $ProbeDefinitionEventCmd - if (-Not ($ResponderTargetResource) -and ($ProbeToInvestigate.split("/").Count -gt 1)) { + if (-not ($ResponderTargetResource) -and ($ProbeToInvestigate.split("/").Count -gt 1)) { $ResponderTargetResource = $ProbeToInvestigate.split("/")[1] } $ProbeDetailsCmd = '(' + $ProbeDefinitionEventCmd + '| % {[XML]$_.toXml()}).event.userData.eventXml| ? {$_.Name -like "' + $ProbeToInvestigate.split("/")[0] + '*" }' diff --git a/PublicFolders/Update-PublicFolderPermissions.ps1 b/PublicFolders/Update-PublicFolderPermissions.ps1 index ae4e5e57d3..fbc3d6452a 100644 --- a/PublicFolders/Update-PublicFolderPermissions.ps1 +++ b/PublicFolders/Update-PublicFolderPermissions.ps1 @@ -118,7 +118,7 @@ function FindFoldersToUpdate([string[]]$includeFolders, [bool]$recurseOnFolders, continue } - if ($folderToSkip -notContains $foundFolder.EntryId) { + if ($folderToSkip -notcontains $foundFolder.EntryId) { Write-Verbose "$($MyInvocation.MyCommand): Returning found folder $($foundFolder.Identity) with EntryId $($foundFolder.EntryID)" #Return found folder $foundFolder diff --git a/Security/src/Test-ProxyLogon.ps1 b/Security/src/Test-ProxyLogon.ps1 index 0d6ff92fe4..12dd818799 100644 --- a/Security/src/Test-ProxyLogon.ps1 +++ b/Security/src/Test-ProxyLogon.ps1 @@ -136,7 +136,7 @@ begin { [Void]$allResults.FileList.Add( $files[$i] ) Import-Csv -Path $files[$i] -ErrorAction SilentlyContinue | - Where-Object { $_.AnchorMailbox -Like 'ServerInfo~*/*' -and $_.AnchorMailbox -notlike 'ServerInfo~*/autodiscover*' -and $_.AnchorMailbox -notlike 'ServerInfo~localhost*/*' } | + Where-Object { $_.AnchorMailbox -like 'ServerInfo~*/*' -and $_.AnchorMailbox -notlike 'ServerInfo~*/autodiscover*' -and $_.AnchorMailbox -notlike 'ServerInfo~localhost*/*' } | Select-Object -Property $outProps | ForEach-Object { [Void]$allResults.Hits.Add( $_ ) @@ -219,7 +219,7 @@ begin { if ((Get-ChildItem $files[$i] -ErrorAction SilentlyContinue | Select-String -Pattern "ServerInfo~").Count -gt 0) { - $hits = @(Import-Csv -Path $files[$i] -ErrorAction SilentlyContinue | Where-Object { $_.AnchorMailbox -Like 'ServerInfo~*/*Reset*VirtualDirectory#' -and $_.HttpStatus -eq 200 } | + $hits = @(Import-Csv -Path $files[$i] -ErrorAction SilentlyContinue | Where-Object { $_.AnchorMailbox -like 'ServerInfo~*/*Reset*VirtualDirectory#' -and $_.HttpStatus -eq 200 } | Select-Object -Property $outProps) if ($hits.Count -gt 0) { $hits | ForEach-Object {