Skip to content

Commit 23f3ffe

Browse files
SamErdeCopilot
andcommitted
🐛 fix(function): resolve medium-severity bugs across scripts
F02: Fix RegistryAccessRule from FullControl to ReadKey in Activate and Get License (comment/output said 'read permissions' but code was granting FullControl) F05: Fix Write-Error \\Cannot validate argument on parameter 'MaximumHistoryCount'. The 0 argument is less than the minimum allowed range of 1. Supply an argument that is greater than or equal to 1 and then try the command again.[0]\ -> \\\ in Get Hostnames from CSV IP Addresses (\\Cannot validate argument on parameter 'MaximumHistoryCount'. The 0 argument is less than the minimum allowed range of 1. Supply an argument that is greater than or equal to 1 and then try the command again.[0]\ may not reflect the current exception in a catch block) F15: Confirmed already fixed in critical pass (Get-Date format HH-mm-ss correct) F18: Replace \�reak 1\ with \ eturn\ in two catch blocks in Get-InactiveUsers (break outside a loop throws LoopFlowException in PowerShell) F20: Add BadPasswordTime to Get-ADUser -Properties list in Get-LockedOutLocation (property was used in output object but never requested from AD) F25: Fix undefined \\\ -> \\\\ in Update-ModuleVersion F28: Remove Set-ExecutionPolicy RemoteSigned from Parse-TransportLogs (modifies machine security policy as a script side effect) F30: Add bounds check before split('<')[1] in Parse-TransportLogs (throws index-out-of-range if no '<' delimiter present in log data) F31: Replace \\Continue\ global mutation with try/catch for DNS lookup in Parse-TransportLogs (scoped error handling instead of global state change) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 28005d5 commit 23f3ffe

6 files changed

Lines changed: 18 additions & 12 deletions

File tree

Active Directory/AD Users/Get-InactiveUsers.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
Write-Verbose 'Active Directory module imported successfully'
7474
} catch {
7575
Write-Error "Failed to import Active Directory module: $($_.Exception.Message)"
76-
break 1
76+
return
7777
}
7878

7979
# Calculate the cutoff date and its file time representation for the AD filter.
@@ -99,7 +99,7 @@
9999
Write-Host "Found $($InactiveUsersResult.Count) inactive user account(s)." -ForegroundColor Green
100100
} catch {
101101
Write-Error "Failed to get user accounts: $($_.Exception.Message)"
102-
break 1
102+
return
103103
}
104104

105105
$InactiveUsers = @()

Active Directory/AD Users/Get-LockedOutLocation.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
$DCCounter++
4949
Write-Progress -Activity 'Contacting DCs for lockout info' -Status "Querying $($DC.Hostname)" -PercentComplete (($DCCounter / $DomainControllers.Count) * 100)
5050
try {
51-
$UserInfo = Get-ADUser -Identity $Identity -Server $DC.Hostname -Properties AccountLockoutTime, LastBadPasswordAttempt, BadPwdCount, LockedOut -ErrorAction Stop
51+
$UserInfo = Get-ADUser -Identity $Identity -Server $DC.Hostname -Properties AccountLockoutTime, BadPasswordTime, LastBadPasswordAttempt, BadPwdCount, LockedOut -ErrorAction Stop
5252
} catch {
5353
Write-Warning $_
5454
continue

DDI/Get Hostnames from CSV IP Addresses.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ $IPAddressList | foreach-object {
1010
$_.Hostname = ([System.Net.Dns]::GetHostEntry($ip)).HostName
1111
}
1212
catch {
13-
Write-Error $error[0] #.Exception.Message.Split(':')[1]
13+
Write-Error $_ #.Exception.Message.Split(':')[1]
1414
}
1515
}
1616
# Write the data back to the CSV with the hostnames added.

Exchange/Parse-TransportLogs.ps1

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
http://blog.chrislehr.com/2015/07/parse-transportlogs-which-ips-on-my.html
1414
#>
1515

16-
Set-ExecutionPolicy RemoteSigned
1716
$ExchangeCredential = Get-Credential -Message "Please enter credentials to connect to your Exchange Server. `nThis will be used to pull message subject lines from the tracking logs."
1817
$ExchangeServer = Read-Host 'Please specify an Exchange Server name.'
1918
$ExchangeSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri "http://$ExchangeServer/PowerShell/" -Authentication Kerberos -Credential $ExchangeCredential
@@ -47,13 +46,20 @@ foreach ($item in $TestSet) {
4746
$testProgress++; $testPercent = [math]::Round(($testProgress / $testCount), 2) * 100
4847
Write-Progress -Activity "Parsing message $testProgress of $testCount." -Status "$testPercent% complete" -PercentComplete $testPercent
4948

50-
$data = ($item.data.split('<')[1]).Split('>')[0]
49+
$splitData = $item.data.Split('<')
50+
if ($splitData.Count -lt 2) {
51+
Write-Warning "Skipping item with no message-id delimiter: $($item.data)"
52+
continue
53+
}
54+
$data = $splitData[1].Split('>')[0]
5155
$subject = (Get-MessageTrackingLog -MessageId $data).MessageSubject | Select-Object -Unique
5256
$item.MessageID = $data
5357
$item.Subject = $subject
54-
$ErrorActionPreference = 'SilentlyContinue' #To avoid ambiguous error output if/when a hostname is not found.
55-
$item.Hostname = ([System.Net.DNS]::GetHostbyAddress($item.IPAddress)).Hostname
56-
$ErrorActionPreference = 'Continue'
58+
try {
59+
$item.Hostname = ([System.Net.DNS]::GetHostbyAddress($item.IPAddress)).Hostname
60+
} catch {
61+
# Hostname not found for this IP; leave blank.
62+
}
5763
}
5864

5965
Remove-PSSession $ExchangeSession.Id

General/Update-ModuleVersion.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
}
8888

8989
if ("$NewVersion$PrereleaseTag" -notmatch $PatternValidation) {
90-
Write-Error -Message "The prerelease version '$PrereleaseVersion' is not a valid semantic version." -ErrorAction Continue
90+
Write-Error -Message "The prerelease version '$NewVersion$PrereleaseTag' is not a valid semantic version." -ErrorAction Continue
9191
} else {
9292
$matches | Write-Debug -Debug
9393
foreach ($match in $matches.GetEnumerator()) {

Windows/Activate and Get License.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ if (-not (Test-Path -Path $registryPath)) {
2929

3030
# Add read permissions for SID (S-1-1-0, Everyone) to the registry key with inheritance
3131
$acl = Get-Acl -Path $registryPath
32-
$ruleSID = New-Object System.Security.AccessControl.RegistryAccessRule($sid, 'FullControl', 'ContainerInherit,ObjectInherit', 'None', 'Allow')
32+
$ruleSID = New-Object System.Security.AccessControl.RegistryAccessRule($sid, 'ReadKey', 'ContainerInherit,ObjectInherit', 'None', 'Allow')
3333
$acl.AddAccessRule($ruleSID)
3434
Set-Acl -Path $registryPath -AclObject $acl
35-
Write-Output "Added 'Interactive' group and SID ($sid) with read permissions (with inheritance) to the registry key."
35+
Write-Output "Added 'Interactive' group and SID ($sid) with read (ReadKey) permissions (with inheritance) to the registry key."
3636

3737
#Remove the # below to make sure it will kick off the scheduled task on already enrolled devices
3838
Start-Process "$env:SystemRoot\system32\ClipRenew.exe"

0 commit comments

Comments
 (0)