mirror of
https://github.com/fleschutz/PowerShell.git
synced 2024-11-29 19:33:20 +01:00
Improved add-firewall-rules.ps1
This commit is contained in:
parent
fbfd13d636
commit
8c8ec05c16
@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
#Requires -RunAsAdministrator
|
#Requires -RunAsAdministrator
|
||||||
|
|
||||||
param([string]$PathToExecutables)
|
param([string]$PathToExecutables = "")
|
||||||
|
|
||||||
$command = '
|
$command = '
|
||||||
$output = ''Firewall rules for path '' + $args[0]
|
$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
|
$null = New-NetFirewallRule -DisplayName $name -Direction Inbound -Program $path -Profile Domain, Private -Action Allow
|
||||||
}
|
}
|
||||||
Write-Host -NoNewLine ''Done - press any key to continue...'';
|
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 "" ) {
|
||||||
#Add 64bit Apps (if applicable)
|
$PathToExecutables = read-host "Enter path to executables"
|
||||||
$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){
|
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...';
|
Write-Host -NoNewhLine 'Press any key to continue...';
|
||||||
$null = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown');
|
[void]$Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown');
|
||||||
}else{
|
exit 1
|
||||||
$arg = "$path $Apps"
|
|
||||||
Start-Process powershell -Verb runAs -ArgumentList "-command & {$command} $arg"
|
|
||||||
}
|
}
|
||||||
}else{
|
|
||||||
write-warning "Cannot find executables path. The script must be executed in ATTower root directory"
|
$arg = "PathToExecutables $Apps"
|
||||||
Write-Host -NoNewLine 'Press any key to continue...';
|
Start-Process powershell -Verb runAs -ArgumentList "-command & {$command} $arg"
|
||||||
$null = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown');
|
exit 0
|
||||||
|
} catch {
|
||||||
|
write-error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||||
|
exit 1
|
||||||
}
|
}
|
||||||
exit 0
|
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
.NOTES Author: Markus Fleschutz / License: CC0
|
.NOTES Author: Markus Fleschutz / License: CC0
|
||||||
#>
|
#>
|
||||||
|
|
||||||
param([string]$URL)
|
param([string]$URL = "")
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if ($URL -eq "" ) {
|
if ($URL -eq "" ) {
|
||||||
|
Loading…
Reference in New Issue
Block a user