Improved add-firewall-rules.ps1

This commit is contained in:
Markus Fleschutz 2021-02-01 08:25:03 +01:00
parent fbfd13d636
commit 8c8ec05c16
2 changed files with 21 additions and 44 deletions

View File

@ -8,7 +8,7 @@
#Requires -RunAsAdministrator
param([string]$PathToExecutables)
param([string]$PathToExecutables = "")
$command = '
$output = ''Firewall rules for path '' + $args[0]
@ -25,53 +25,30 @@ for($i = 1; $i -lt $args.count; $i++){
$null = New-NetFirewallRule -DisplayName $name -Direction Inbound -Program $path -Profile Domain, Private -Action Allow
}
Write-Host -NoNewLine ''Done - press any key to continue...'';
$null = $Host.UI.RawUI.ReadKey(''NoEcho,IncludeKeyDown'');
[void]$Host.UI.RawUI.ReadKey(''NoEcho,IncludeKeyDown'');
'
#get current path
$path = get-location
$path = Convert-Path -Path $path
if(test-path "$path\executables"){
#get all executables
$Apps = @()
$Apps += Get-ChildItem "$path\executables\*.exe" -Name
for($i = 0; $i -lt $Apps.length; $i++){
$Apps[$i] = "executables\" + $Apps[$i]
try {
if ($PathToExecutables -eq "" ) {
$PathToExecutables = read-host "Enter path to executables"
}
#Add 64bit Apps (if applicable)
$Apps64 = @()
if(test-path "$path\executables64"){
#only try if 64bit executables are present
$Apps64 += Get-ChildItem "$path\executables64\*.exe" -Name
for($i = 0; $i -lt $Apps64.length; $i++){
$Apps64[$i] = "executables64\" + $Apps64[$i]
}
$Apps += $Apps64
}
#Add all Java runtimes delivered
$subdirs = get-childitem $path\jre
foreach($item in $subdirs){
if($item.PSIsContainer){
$itempath = $item.BaseName
$itempath += "\bin\javaw.exe"
$itempath = "jre\$itempath"
if(test-path("$path\$itempath")){
$Apps += $itempath
}
}
}
$PathToExecutables = Convert-Path -Path $PathToExecutables
$Apps = Get-ChildItem "$PathToExecutables\*.exe" -Name
if($Apps.count -eq 0){
Write-Warning "No executables found. No Firewall rules have been created."
write-warning "No executables found. No Firewall rules have been created."
Write-Host -NoNewhLine 'Press any key to continue...';
$null = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown');
}else{
$arg = "$path $Apps"
Start-Process powershell -Verb runAs -ArgumentList "-command & {$command} $arg"
[void]$Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown');
exit 1
}
}else{
write-warning "Cannot find executables path. The script must be executed in ATTower root directory"
Write-Host -NoNewLine 'Press any key to continue...';
$null = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown');
$arg = "PathToExecutables $Apps"
Start-Process powershell -Verb runAs -ArgumentList "-command & {$command} $arg"
exit 0
} catch {
write-error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}
exit 0

View File

@ -6,7 +6,7 @@
.NOTES Author: Markus Fleschutz / License: CC0
#>
param([string]$URL)
param([string]$URL = "")
try {
if ($URL -eq "" ) {