bc3dd6c535
Deploys a fully preconfigured OPNsense appliance into a Hyper-V lab in a single execution, re-running safely because every stage detects the current state before it acts. Main script: - Hyper-V platform detection and installation, exiting 3010 only when the hypervisor itself needs a restart - Random /20 block selection out of a private base network, divided into /24 networks whose VLAN tag is the third octet of their own network address - Zone based roles, with five server zones paired by index to five client zones, plus Management, Infrastructure, DMZ, Storage and Guest - Generated OPNsense config.xml delivered on a FAT32 VHDX at conf/config.xml - Generation 2 virtual machine with secure boot disabled and a LAN trunk carrying VLANs 1-4094 - Marker scoped teardown via RemoveExistingDeployment Toolkit functions: - Save-ToolkitModule, Install-HyperVPlatform, Test-PendingReboot - Expand-CompressedFile, Get-OPNSenseInstallationMedia - Get-HyperVStorageLocation, Get-HostUpstreamDNSConfiguration - New-RandomPassword, New-OPNSensePasswordHash - New-OPNSenseNetworkPlan, New-OPNSenseConfigurationDocument, Save-OPNSenseConfigurationDocument, New-OPNSenseConfigurationDisk - Initialize-OPNSenseVirtualSwitch, New-OPNSenseVirtualMachine, Remove-OPNSenseDeployment Configuration document covers interfaces, VLANs, Kea DHCPv4 scopes with PXE options, Unbound, outbound NAT, six firewall aliases and an ordered rule set that grants management full reach, allows the jump hosts over well known management ports, forces name resolution to approved resolvers, and pairs the client and server zones. Bundles 7-Zip, because the tar.exe included with Windows cannot read a raw bzip2 stream, and BCrypt.Net-Next for the appliance password hash. docs: Add readme with execution flow and generated per function reference docs: Add design specification under .ai/specification Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
5.3 KiB
5.3 KiB
Start-ProcessWithOutput
Function index | Repository readme | Source
Allows for the execution of processes with the ability to return their output without first dumping the content to a file. It can all be kept in memory.
Description
This is not the best option when your process returns a large enough amount of output to cause a memory leak or overflow.
Parameters
| Name | Type | Required | Aliases | Description |
|---|---|---|---|---|
FilePath |
String |
Yes | FP | Your parameter description |
WorkingDirectory |
IO.DirectoryInfo |
No | WD | Your parameter description |
ArgumentList |
String[] |
No | AL | Your parameter description |
AcceptableExitCodeList |
String[] |
No | AECL | A * can be used to accept all exit codes. |
WindowStyle |
String |
No | WS | Your parameter description |
CreateNoWindow |
Switch |
No | CNW | Your parameter description |
NoWait |
Switch |
No | NW | |
Priority |
String |
No | P | |
ExecutionTimeout |
TimeSpan |
No | ET | Your parameter description |
ExecutionTimeoutInterval |
TimeSpan |
No | ETI | Your parameter description |
StandardInputObjectList |
Object[] |
No | SIO | |
ParsingExpression |
Text.RegularExpressions.Regex |
No | StandardOutputParsingExpression, SOPE, PE | A valid regular expression that will allow for the output to be parsed into objects. |
SecureArgumentList |
Switch |
No | SAL | Your parameter description |
LogOutput |
Switch |
No | LO | Your parameter description |
ContinueOnError |
Switch |
No | COE |
Examples
Example 1
Start-ProcessWithOutput -FilePath 'cmd.exe' -ArgumentList '/c ipconfig /all' -AcceptableExitCodeList @('*') -CreateNoWindow -NoWait -Verbose
Example 2
Start-ProcessWithOutput -FilePath 'cmd.exe' -ArgumentList '/c ipconfig /all' -AcceptableExitCodeList @('*') -CreateNoWindow -Timeout ([System.TimeSpan]::FromSeconds(30)) -Verbose
Example 3
$StartProcessWithOutputParameters = New-Object -TypeName 'System.Collections.Specialized.OrderedDictionary'
$StartProcessWithOutputParameters.FilePath = "dsregcmd.exe"
$StartProcessWithOutputParameters.WorkingDirectory = "$([System.Environment]::SystemDirectory)"
$StartProcessWithOutputParameters.ArgumentList = New-Object -TypeName 'System.Collections.Generic.List[String]'
$StartProcessWithOutputParameters.ArgumentList.Add('/status')
$StartProcessWithOutputParameters.AcceptableExitCodeList = New-Object -TypeName 'System.Collections.Generic.List[String]'
$StartProcessWithOutputParameters.AcceptableExitCodeList.Add('0')
$StartProcessWithOutputParameters.WindowStyle = "Hidden"
$StartProcessWithOutputParameters.Priority = "Normal"
$StartProcessWithOutputParameters.ParsingExpression = "(?:\s+)(?<PropertyName>.+)(?:\s+\:\s+)(?<PropertyValue>.+)"
$StartProcessWithOutputParameters.LogOutput = $True
$StartProcessWithOutputParameters.ExecutionTimeout = [Timespan]::FromMinutes(1)
$StartProcessWithOutputParameters.ExecutionTimeoutInterval = [Timespan]::FromSeconds(30)
$StartProcessWithOutputParameters.StandardInputObjectList = New-Object -TypeName 'System.Collections.Generic.List[System.Object]'
$StartProcessWithOutputParameters.StandardInputObjectList.Add('S')
$StartProcessWithOutputParameters.SecureArgumentList = $False
$StartProcessWithOutputParameters.Verbose = $True
$StartProcessWithOutputResult = Start-ProcessWithOutput @StartProcessWithOutputParameters
Write-Output -InputObject ($StartProcessWithOutputResult)
Example 4
$StartProcessWithOutputParameters = New-Object -TypeName 'System.Collections.Specialized.OrderedDictionary'
$StartProcessWithOutputParameters.FilePath = "dsregcmd.exe"
$StartProcessWithOutputParameters.WorkingDirectory = "$([System.Environment]::SystemDirectory)"
$StartProcessWithOutputParameters.ArgumentList = New-Object -TypeName 'System.Collections.Generic.List[String]'
$StartProcessWithOutputParameters.ArgumentList.Add('/status')
$StartProcessWithOutputParameters.AcceptableExitCodeList = New-Object -TypeName 'System.Collections.Generic.List[String]'
$StartProcessWithOutputParameters.AcceptableExitCodeList.Add('0')
$StartProcessWithOutputParameters.WindowStyle = "Hidden"
$StartProcessWithOutputParameters.Priority = "Normal"
$StartProcessWithOutputParameters.ParsingExpression = "(?:\s+)(?<PropertyName>.+)(?:\s+\:\s+)(?<PropertyValue>.+)"
$StartProcessWithOutputParameters.LogOutput = $True
$StartProcessWithOutputParameters.ExecutionTimeout = [Timespan]::FromMinutes(1)
$StartProcessWithOutputParameters.ExecutionTimeoutInterval = [Timespan]::FromSeconds(30)
$StartProcessWithOutputParameters.StandardInputObjectList = New-Object -TypeName 'System.Collections.Generic.List[System.Object]'
$StartProcessWithOutputParameters.StandardInputObjectList.Add('S')
$StartProcessWithOutputParameters.SecureArgumentList = $True
$StartProcessWithOutputParameters.Verbose = $True
$StartProcessWithOutputResult = Start-ProcessWithOutput @StartProcessWithOutputParameters
Write-Output -InputObject ($StartProcessWithOutputResult)
Notes
Mileage may vary when parsing output and may have to be done using additional code outside of this function to address specific needs.