Reviewed Hyper-V host lifecycle audit script#3
Open
AlrightLad wants to merge 1 commit into
Open
Conversation
Addresses all CodeRabbit review feedback from DTC-Inc/msp-script-library#48: - Add #Requires -RunAsAdministrator and #Requires -Modules Hyper-V for preflight validation (Issue 1: missing preflight checks) - Cache Get-VM result once ($allVMs) to avoid repeated calls and cross-section drift during long runs (Issue 2: repeated Get-VM) - Add Start-Transcript/Stop-Transcript logging to %SystemRoot%\Logs for QA evidence retention (nitpick: console-only output) - Replace -ErrorAction SilentlyContinue with try/catch blocks on Get-VHD, Get-VMSnapshot, and Get-NetAdapterVmq to surface real errors instead of silently masking them (nitpick: audit masking) - Add proper comment-based help, CmdletBinding, and -LogPath param to match repo script conventions https://claude.ai/code/session_016vxJGXe9VEcq5g2rqDPK4J
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Reviewed version of the Hyper-V host lifecycle audit script from DTC-Inc/msp-script-library#48, incorporating all CodeRabbit feedback and senior engineer review.
Changes from original PR
#Requires -RunAsAdministratorand#Requires -Modules Hyper-Vso the script fails fast with a clear message instead of cryptic cmdlet errors$allVMs = Get-VMcalled once and reused across VM Inventory, VHDX, and Checkpoints sections — eliminates repeated calls and cross-section driftStart-Transcript/Stop-Transcriptwrites to%SystemRoot%\Logs\HyperVAuditwith timestamped hostname filenames for QA evidence retention-ErrorAction SilentlyContinuewithtry/catchonGet-VHD,Get-VMSnapshot, andGet-NetAdapterVmq— audit scripts should surface failures, not hide them.SYNOPSIS,.DESCRIPTION,.PARAMETER,.EXAMPLE,.NOTES),[CmdletBinding()], and-LogPathparameter matching existing script patternshttps://claude.ai/code/session_016vxJGXe9VEcq5g2rqDPK4J