Skip to content

πŸ› fix(scripts): third audit pass β€” string interpolation, obsolete API, and scope bugs#17

Merged
SamErde merged 3 commits intomainfrom
fix/third-audit-bugs
Apr 29, 2026
Merged

πŸ› fix(scripts): third audit pass β€” string interpolation, obsolete API, and scope bugs#17
SamErde merged 3 commits intomainfrom
fix/third-audit-bugs

Conversation

@SamErde
Copy link
Copy Markdown
Owner

@SamErde SamErde commented Apr 29, 2026

Summary

Third audit pass over the repository. Zero syntax errors found (verified via AST parse of all 233 files). Five confirmed runtime bugs fixed across 5 files.


Changes

Snippets/RemoteServerSessionLoop2.ps1 β€” 2 bugs

  • Enter-PSSession in a loop (Critical): Enter-PSSession is interactive-only β€” it does not route subsequent script lines through the remote session. Replaced with Invoke-Command -Session $session -ScriptBlock { ... }. Also removed the now-unnecessary Exit-PSSession.
  • String interpolation (Medium): "$session.ComputerName $session.State" was appending the property names as literal text. Fixed to "$($session.ComputerName) $($session.State)".

DDI/DNS Reverse Lookup from CSV and Add Column with Hostname.ps1 β€” 1 bug

  • Obsolete .NET API (Medium): [System.Net.DNS]::GetHostbyAddress() is obsolete. Replaced with [System.Net.DNS]::GetHostEntry(), which has the same return type (IPHostEntry) and the same .HostName property.

Windows/Disable-Poshv2.ps1 β€” 1 bug

  • String interpolation (Medium): "$servers.Count servers found." was outputting the array object's .ToString() followed by the literal text .Count servers found.. Fixed to "$($servers.Count) servers found.".

Active Directory/AD Users/Set User EmailAddress from PrimaryAddress.ps1 β€” 1 bug

  • String interpolation (Medium): "$i of $userCount - $user.Name" in Write-Progress -Status was appending .Name as a literal string. Fixed to "$i of $userCount - $($user.Name)".

DDI/Resolve-IPs.ps1 β€” 1 bug

  • $ErrorActionPreference global scope leak (Medium): $ErrorActionPreference = 'silentlycontinue' was set inside the foreach loop on every iteration, permanently overriding the preference for the entire script (and the caller's scope). Removed the global assignment and wrapped the .NET DNS lookup in a try/catch block to suppress per-call errors without leaking the preference change.

Verification

  • All 5 files parse cleanly via [System.Management.Automation.Language.Parser]::ParseFile()
  • No false positives β€” each bug was manually verified against actual file content before fixing

…ActionPreference scope bugs

- Snippets\RemoteServerSessionLoop2.ps1: replace Enter-PSSession (interactive-only) with
  Invoke-Command -Session; fix string interpolation for \.ComputerName and
  \.State using \ subexpression syntax
- DDI\DNS Reverse Lookup from CSV.ps1: replace obsolete GetHostbyAddress() with GetHostEntry()
- Windows\Disable-Poshv2.ps1: fix \.Count not expanding in double-quoted string
- AD Users\Set User EmailAddress from PrimaryAddress.ps1: fix \.Name not expanding
  in Write-Progress -Status string
- DDI\Resolve-IPs.ps1: remove \Continue global assignment inside foreach loop;
  wrap DNS lookup in try/catch to suppress per-call errors without leaking preference scope

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 29, 2026 11:28
@codacy-production
Copy link
Copy Markdown

codacy-production Bot commented Apr 29, 2026

Up to standards βœ…

🟒 Issues 0 issues

Results:
0 new issues

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Third audit pass addressing several PowerShell runtime issues across the repo, primarily fixing broken string interpolation, replacing an obsolete DNS API, and correcting remoting/error-scope behavior.

Changes:

  • Fix PowerShell string interpolation in multiple scripts to correctly expand properties/counts.
  • Replace obsolete [System.Net.DNS]::GetHostbyAddress() with [System.Net.DNS]::GetHostEntry().
  • Adjust remoting and error-handling patterns (notably removing $ErrorActionPreference leakage in DDI/Resolve-IPs.ps1 and switching an interactive remoting pattern to Invoke-Command).

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
Windows/Disable-Poshv2.ps1 Fixes count interpolation so the β€œservers found” message shows the actual count.
Snippets/RemoteServerSessionLoop2.ps1 Replaces interactive Enter-PSSession usage with Invoke-Command and fixes property interpolation when logging session details.
DDI/Resolve-IPs.ps1 Removes $ErrorActionPreference leakage by switching to try/catch around DNS lookups.
DDI/DNS Reverse Lookup from CSV and Add Column with Hostname.ps1 Replaces an obsolete .NET DNS reverse-lookup API with the supported equivalent.
Active Directory/AD Users/Set User EmailAddress from PrimaryAddress.ps1 Fixes Write-Progress status interpolation for user name display.

Comment thread Snippets/RemoteServerSessionLoop2.ps1 Outdated
Comment thread Snippets/RemoteServerSessionLoop2.ps1 Outdated
Comment thread DDI/Resolve-IPs.ps1
SamErde and others added 2 commits April 29, 2026 07:38
- Make profile Prompt implementations null-safe when command history is empty
- Add ShouldProcess support around New-gMSA Active Directory changes
- Update stale remoting catch messages after replacing Enter-PSSession usage

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Move PSSession creation into try/catch with terminating errors
- Ensure PSSession cleanup runs from finally when remote execution fails
- Use consistent PascalCase Result variable in Resolve-IPs

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@SamErde SamErde merged commit 1241307 into main Apr 29, 2026
8 checks passed
@SamErde SamErde deleted the fix/third-audit-bugs branch April 29, 2026 11:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants