ci(lint): add CmdletBinding and ShouldProcess support to ISO creation functions for safer execution
This commit is contained in:
@@ -270,11 +270,13 @@ if (-not ([System.Management.Automation.PSTypeName]'IsoStreamWriter2').Type) {
|
||||
}
|
||||
|
||||
function New-IsoFromFolder {
|
||||
[CmdletBinding(SupportsShouldProcess, ConfirmImpact='Low')]
|
||||
param(
|
||||
[Parameter(Mandatory)] [string] $SourceFolder,
|
||||
[Parameter(Mandatory)] [string] $IsoPath,
|
||||
[Parameter(Mandatory)] [string] $VolumeLabel
|
||||
)
|
||||
if (-not $PSCmdlet.ShouldProcess($IsoPath, 'Create ISO from folder')) { return }
|
||||
if (Test-Path $IsoPath) { Remove-Item $IsoPath -Force }
|
||||
$fsi = New-Object -ComObject IMAPI2FS.MsftFileSystemImage
|
||||
$result = $null
|
||||
@@ -305,10 +307,12 @@ function New-WinIsoNoPrompt {
|
||||
Result: UEFI boot proceeds straight into Windows Setup, no
|
||||
"Press any key to boot from CD" prompt.
|
||||
#>
|
||||
[CmdletBinding(SupportsShouldProcess, ConfirmImpact='Low')]
|
||||
param(
|
||||
[Parameter(Mandatory)] [string] $SourceIsoPath,
|
||||
[Parameter(Mandatory)] [string] $OutputIsoPath
|
||||
)
|
||||
if (-not $PSCmdlet.ShouldProcess($OutputIsoPath, 'Rebuild Windows ISO without boot prompt')) { return }
|
||||
if (Test-Path $OutputIsoPath) { Remove-Item $OutputIsoPath -Force }
|
||||
|
||||
$mount = Mount-DiskImage -ImagePath $SourceIsoPath -PassThru -StorageType ISO -Access ReadOnly
|
||||
@@ -383,11 +387,13 @@ function Invoke-Vmrun {
|
||||
}
|
||||
|
||||
function Set-VmxKey {
|
||||
[CmdletBinding(SupportsShouldProcess, ConfirmImpact='Low')]
|
||||
param(
|
||||
[Parameter(Mandatory)] [string] $VmxPath,
|
||||
[Parameter(Mandatory)] [string] $Key,
|
||||
[Parameter(Mandatory)] [string] $Value
|
||||
)
|
||||
if (-not $PSCmdlet.ShouldProcess($VmxPath, "Set VMX key '$Key'")) { return }
|
||||
$lines = Get-Content -LiteralPath $VmxPath
|
||||
$pattern = "^\s*$([regex]::Escape($Key))\s*="
|
||||
$found = $false
|
||||
@@ -400,8 +406,10 @@ function Set-VmxKey {
|
||||
}
|
||||
|
||||
function Remove-VmxLines {
|
||||
[CmdletBinding(SupportsShouldProcess, ConfirmImpact='Low')]
|
||||
param([Parameter(Mandatory)] [string] $VmxPath,
|
||||
[Parameter(Mandatory)] [string] $KeyPrefix)
|
||||
if (-not $PSCmdlet.ShouldProcess($VmxPath, "Remove VMX lines starting with '$KeyPrefix'")) { return }
|
||||
$pat = "^\s*$([regex]::Escape($KeyPrefix))"
|
||||
$lines = Get-Content -LiteralPath $VmxPath | Where-Object { $_ -notmatch $pat }
|
||||
Set-Content -LiteralPath $VmxPath -Value $lines -Encoding ASCII
|
||||
@@ -428,8 +436,10 @@ function Invoke-VmrunBounded {
|
||||
}
|
||||
|
||||
function Stop-Vm {
|
||||
[CmdletBinding(SupportsShouldProcess, ConfirmImpact='Low')]
|
||||
param([Parameter(Mandatory)] [string] $VmxPath,
|
||||
[int] $SoftTimeoutMinutes = 5)
|
||||
if (-not $PSCmdlet.ShouldProcess($VmxPath, 'Stop VM')) { return }
|
||||
# Send soft-stop (ACPI); vmrun may block until guest finishes — kill vmrun after 30 s.
|
||||
# Guest OS continues shutdown independently once the signal is received.
|
||||
Invoke-VmrunBounded -Arguments @('-T','ws','stop',$VmxPath,'soft') -TimeoutSeconds 30
|
||||
|
||||
Reference in New Issue
Block a user