mirror of
https://github.com/Grace-Solutions/Invoke-OpenSSHConfiguration.git
synced 2026-07-26 11:38:14 +00:00
Fix TimeSpan error and firewall profile enumeration
- Added ExecutionTimeout and ExecutionTimeoutInterval to ssh-keygen calls (2 min timeout)
- Added ExecutionTimeout and ExecutionTimeoutInterval to sshd -t validation (30 sec timeout)
- Fixed firewall profile enumeration: use string array instead of unavailable type
- Profiles now use simple array: @('Domain', 'Private', 'Public')
This commit is contained in:
@@ -383,6 +383,8 @@ Switch (Test-ProcessElevationStatus)
|
|||||||
$StartProcessWithOutputParameters.AcceptableExitCodeList = New-Object -TypeName 'System.Collections.Generic.List[System.String]'
|
$StartProcessWithOutputParameters.AcceptableExitCodeList = New-Object -TypeName 'System.Collections.Generic.List[System.String]'
|
||||||
$StartProcessWithOutputParameters.AcceptableExitCodeList.Add('0')
|
$StartProcessWithOutputParameters.AcceptableExitCodeList.Add('0')
|
||||||
$StartProcessWithOutputParameters.CreateNoWindow = $True
|
$StartProcessWithOutputParameters.CreateNoWindow = $True
|
||||||
|
$StartProcessWithOutputParameters.ExecutionTimeout = [System.Timespan]::FromMinutes(2)
|
||||||
|
$StartProcessWithOutputParameters.ExecutionTimeoutInterval = [System.Timespan]::FromSeconds(5)
|
||||||
$StartProcessWithOutputParameters.LogOutput = $True
|
$StartProcessWithOutputParameters.LogOutput = $True
|
||||||
$StartProcessWithOutputParameters.ContinueOnError = $False
|
$StartProcessWithOutputParameters.ContinueOnError = $False
|
||||||
$StartProcessWithOutputParameters.Verbose = $True
|
$StartProcessWithOutputParameters.Verbose = $True
|
||||||
@@ -714,6 +716,8 @@ Switch (Test-ProcessElevationStatus)
|
|||||||
$ValidateConfigParameters.AcceptableExitCodeList = New-Object -TypeName 'System.Collections.Generic.List[System.String]'
|
$ValidateConfigParameters.AcceptableExitCodeList = New-Object -TypeName 'System.Collections.Generic.List[System.String]'
|
||||||
$ValidateConfigParameters.AcceptableExitCodeList.Add('0')
|
$ValidateConfigParameters.AcceptableExitCodeList.Add('0')
|
||||||
$ValidateConfigParameters.CreateNoWindow = $True
|
$ValidateConfigParameters.CreateNoWindow = $True
|
||||||
|
$ValidateConfigParameters.ExecutionTimeout = [System.Timespan]::FromSeconds(30)
|
||||||
|
$ValidateConfigParameters.ExecutionTimeoutInterval = [System.Timespan]::FromSeconds(5)
|
||||||
$ValidateConfigParameters.LogOutput = $True
|
$ValidateConfigParameters.LogOutput = $True
|
||||||
$ValidateConfigParameters.ContinueOnError = $True
|
$ValidateConfigParameters.ContinueOnError = $True
|
||||||
$ValidateConfigParameters.Verbose = $True
|
$ValidateConfigParameters.Verbose = $True
|
||||||
@@ -798,7 +802,7 @@ Switch (Test-ProcessElevationStatus)
|
|||||||
|
|
||||||
#region Windows Firewall Configuration (Automatic)
|
#region Windows Firewall Configuration (Automatic)
|
||||||
$FirewallRuleName = 'OpenSSH-Server-In-TCP'
|
$FirewallRuleName = 'OpenSSH-Server-In-TCP'
|
||||||
$FirewallProfiles = [System.Enum]::GetValues([Microsoft.PowerShell.Cmdletization.GeneratedTypes.NetSecurity.Profile])
|
$FirewallProfiles = @('Domain', 'Private', 'Public')
|
||||||
|
|
||||||
ForEach ($FirewallProfile In $FirewallProfiles)
|
ForEach ($FirewallProfile In $FirewallProfiles)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -241,53 +241,64 @@ Function Start-ProcessWithOutput
|
|||||||
[System.TimeSpan]$InputObject
|
[System.TimeSpan]$InputObject
|
||||||
)
|
)
|
||||||
|
|
||||||
$InputObjectMessageBuilder = New-Object -TypeName 'System.Text.StringBuilder'
|
Switch ($Null -ine $InputObject)
|
||||||
|
|
||||||
$InputObjectProperties = $InputObject | Select-Object -Property @('Days', 'Hours', 'Minutes', 'Seconds', 'Milliseconds')
|
|
||||||
|
|
||||||
$InputObjectPropertyNameList = New-Object -TypeName 'System.Collections.Generic.List[System.String]'
|
|
||||||
|
|
||||||
($InputObjectProperties.PSObject.Properties | Where-Object {($_.Value -gt 0)}).Name | ForEach-Object {($InputObjectPropertyNameList.Add($_))}
|
|
||||||
|
|
||||||
$InputObjectPropertyNameListUpperBound = $InputObjectPropertyNameList.ToArray().GetUpperBound(0)
|
|
||||||
|
|
||||||
For ($InputObjectPropertyNameListIndex = 0; $InputObjectPropertyNameListIndex -lt $InputObjectPropertyNameList.Count; $InputObjectPropertyNameListIndex++)
|
|
||||||
{
|
|
||||||
$InputObjectPropertyName = $InputObjectPropertyNameList[$InputObjectPropertyNameListIndex]
|
|
||||||
|
|
||||||
$InputObjectPropertyValue = $InputObject.$($InputObjectPropertyName)
|
|
||||||
|
|
||||||
Switch ($True)
|
|
||||||
{
|
|
||||||
{($InputObjectPropertyNameList.Count -gt 1) -and ($InputObjectPropertyNameListIndex -eq $InputObjectPropertyNameListUpperBound)}
|
|
||||||
{
|
|
||||||
$Null = $InputObjectMessageBuilder.Append('and ')
|
|
||||||
}
|
|
||||||
|
|
||||||
{($InputObjectPropertyValue -eq 1)}
|
|
||||||
{
|
|
||||||
$Null = $InputObjectMessageBuilder.Append("$($InputObjectPropertyValue) $($InputObjectPropertyName.TrimEnd('s').ToLower())")
|
|
||||||
}
|
|
||||||
|
|
||||||
{($InputObjectPropertyValue -gt 1)}
|
|
||||||
{
|
|
||||||
$Null = $InputObjectMessageBuilder.Append("$($InputObjectPropertyValue) $($InputObjectPropertyName.ToLower())")
|
|
||||||
}
|
|
||||||
|
|
||||||
{($InputObjectPropertyNameList.Count -gt 1) -and ($InputObjectPropertyNameListIndex -ne $InputObjectPropertyNameListUpperBound)}
|
|
||||||
{
|
|
||||||
$Null = $InputObjectMessageBuilder.Append(', ')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$OutputObject = $InputObjectMessageBuilder.ToString()
|
|
||||||
|
|
||||||
Switch ($InputObjectMessageBuilder.Length -gt 0)
|
|
||||||
{
|
{
|
||||||
{($_ -eq $True)}
|
{($_ -eq $True)}
|
||||||
{
|
{
|
||||||
|
$InputObjectMessageBuilder = New-Object -TypeName 'System.Text.StringBuilder'
|
||||||
|
|
||||||
|
$InputObjectProperties = $InputObject | Select-Object -Property @('Days', 'Hours', 'Minutes', 'Seconds', 'Milliseconds')
|
||||||
|
|
||||||
|
$InputObjectPropertyNameList = New-Object -TypeName 'System.Collections.Generic.List[System.String]'
|
||||||
|
|
||||||
|
($InputObjectProperties.PSObject.Properties | Where-Object {($_.Value -gt 0)}).Name | ForEach-Object {($InputObjectPropertyNameList.Add($_))}
|
||||||
|
|
||||||
|
$InputObjectPropertyNameListUpperBound = $InputObjectPropertyNameList.ToArray().GetUpperBound(0)
|
||||||
|
|
||||||
|
For ($InputObjectPropertyNameListIndex = 0; $InputObjectPropertyNameListIndex -lt $InputObjectPropertyNameList.Count; $InputObjectPropertyNameListIndex++)
|
||||||
|
{
|
||||||
|
$InputObjectPropertyName = $InputObjectPropertyNameList[$InputObjectPropertyNameListIndex]
|
||||||
|
|
||||||
|
$InputObjectPropertyValue = $InputObject.$($InputObjectPropertyName)
|
||||||
|
|
||||||
|
Switch ($True)
|
||||||
|
{
|
||||||
|
{($InputObjectPropertyNameList.Count -gt 1) -and ($InputObjectPropertyNameListIndex -eq $InputObjectPropertyNameListUpperBound)}
|
||||||
|
{
|
||||||
|
$Null = $InputObjectMessageBuilder.Append('and ')
|
||||||
|
}
|
||||||
|
|
||||||
|
{($InputObjectPropertyValue -eq 1)}
|
||||||
|
{
|
||||||
|
$Null = $InputObjectMessageBuilder.Append("$($InputObjectPropertyValue) $($InputObjectPropertyName.TrimEnd('s').ToLower())")
|
||||||
|
}
|
||||||
|
|
||||||
|
{($InputObjectPropertyValue -gt 1)}
|
||||||
|
{
|
||||||
|
$Null = $InputObjectMessageBuilder.Append("$($InputObjectPropertyValue) $($InputObjectPropertyName.ToLower())")
|
||||||
|
}
|
||||||
|
|
||||||
|
{($InputObjectPropertyNameList.Count -gt 1) -and ($InputObjectPropertyNameListIndex -ne $InputObjectPropertyNameListUpperBound)}
|
||||||
|
{
|
||||||
|
$Null = $InputObjectMessageBuilder.Append(', ')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$OutputObject = $InputObjectMessageBuilder.ToString()
|
$OutputObject = $InputObjectMessageBuilder.ToString()
|
||||||
|
|
||||||
|
Switch ($InputObjectMessageBuilder.Length -gt 0)
|
||||||
|
{
|
||||||
|
{($_ -eq $True)}
|
||||||
|
{
|
||||||
|
$OutputObject = $InputObjectMessageBuilder.ToString()
|
||||||
|
}
|
||||||
|
|
||||||
|
Default
|
||||||
|
{
|
||||||
|
$OutputObject = 'N/A'
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Default
|
Default
|
||||||
@@ -295,8 +306,8 @@ Function Start-ProcessWithOutput
|
|||||||
$OutputObject = 'N/A'
|
$OutputObject = 'N/A'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Write-Output -InputObject ($OutputObject)
|
Write-Output -InputObject ($OutputObject)
|
||||||
}
|
}
|
||||||
|
|
||||||
[ScriptBlock]$WriteStandardOutputStream = {
|
[ScriptBlock]$WriteStandardOutputStream = {
|
||||||
|
|||||||
Reference in New Issue
Block a user