Skip to content

Commit 722c592

Browse files
author
Markus Fleschutz
committed
Merge branch 'master' of github.com:fleschutz/PowerShell
2 parents a3340f3 + b31ca9f commit 722c592

File tree

581 files changed

+1006
-712
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

581 files changed

+1006
-712
lines changed

Docs/add-firewall-rules.md

+51-47
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,34 @@ This PowerShell script adds firewall rules for the given executable. Administrat
66
Parameters
77
----------
88
```powershell
9-
PS> ./add-firewall-rules.ps1 [[-PathToExecutables] <String>] [<CommonParameters>]
9+
PS> ./add-firewall-rules.ps1 [[-PathToExecutables] <String>] [[-Direction] <String>] [[-FirewallProfile] <Array>] [<CommonParameters>]
1010
1111
-PathToExecutables <String>
12-
Specifies the path to the executables
12+
Specifies the path to the executables.
1313
1414
Required? false
1515
Position? 1
1616
Default value
1717
Accept pipeline input? false
1818
Accept wildcard characters? false
1919
20+
-Direction <String>
21+
Specifies the direction for the firewall rule. Can be 'Inbound' or 'Outbound'. Default is 'Inbound'.
22+
23+
Required? false
24+
Position? 2
25+
Default value Inbound
26+
Accept pipeline input? false
27+
Accept wildcard characters? false
28+
29+
-FirewallProfile <Array>
30+
31+
Required? false
32+
Position? 3
33+
Default value @("Domain", "Private")
34+
Accept pipeline input? false
35+
Accept wildcard characters? false
36+
2037
[<CommonParameters>]
2138
This script supports the common parameters: Verbose, Debug, ErrorAction, ErrorVariable, WarningAction,
2239
WarningVariable, OutBuffer, PipelineVariable, and OutVariable.
@@ -25,10 +42,7 @@ PS> ./add-firewall-rules.ps1 [[-PathToExecutables] <String>] [<CommonParameters>
2542
Example
2643
-------
2744
```powershell
28-
PS> ./add-firewall-rules.ps1 C:\MyApp\bin
29-
Adding firewall rule for C:\MyApp\bin\app1.exe
30-
Adding firewall rule for C:\MyApp\bin\app2.exe
31-
...
45+
PS> ./add-firewall-rules.ps1 -PathToExecutables C:\MyApp\bin -Direction Outbound -Profile Private
3246
3347
```
3448

@@ -45,16 +59,17 @@ Script Content
4559
```powershell
4660
<#
4761
.SYNOPSIS
48-
Adds firewall rules for executables (needs admin rights)
62+
Adds firewall rules for executables (needs admin rights).
4963
.DESCRIPTION
5064
This PowerShell script adds firewall rules for the given executable. Administrator rights are required.
5165
.PARAMETER PathToExecutables
52-
Specifies the path to the executables
66+
Specifies the path to the executables.
67+
.PARAMETER Direction
68+
Specifies the direction for the firewall rule. Can be 'Inbound' or 'Outbound'. Default is 'Inbound'.
69+
.PARAMETER Profile
70+
Specifies the firewall profile. Can be 'Domain', 'Private', or 'Public'. Multiple values can be specified as an array.
5371
.EXAMPLE
54-
PS> ./add-firewall-rules.ps1 C:\MyApp\bin
55-
Adding firewall rule for C:\MyApp\bin\app1.exe
56-
Adding firewall rule for C:\MyApp\bin\app2.exe
57-
...
72+
PS> ./add-firewall-rules.ps1 -PathToExecutables C:\MyApp\bin -Direction Outbound -Profile Private
5873
.LINK
5974
https://github.com/fleschutz/PowerShell
6075
.NOTES
@@ -63,50 +78,39 @@ Script Content
6378
6479
#Requires -RunAsAdministrator
6580
66-
param([string]$PathToExecutables = "")
67-
68-
$command = '
69-
$output = ''Firewall rules for path '' + $args[0]
70-
write-output $output
71-
for($i = 1; $i -lt $args.count; $i++){
72-
$path = $args[0]
73-
$path += ''\''
74-
$path += $args[$i]
75-
76-
$null = $args[$i] -match ''[^\\]*\.exe$''
77-
$name = $matches[0]
78-
$output = ''Adding firewall rule for '' + $name
79-
write-output $output
80-
$null = New-NetFirewallRule -DisplayName $name -Direction Inbound -Program $path -Profile Domain, Private -Action Allow
81-
}
82-
write-host -foregroundColor green -noNewline ''Done - press any key to continue...'';
83-
[void]$Host.UI.RawUI.ReadKey(''NoEcho,IncludeKeyDown'');
84-
'
85-
81+
param(
82+
[string]$PathToExecutables = "",
83+
[string]$Direction = "Inbound",
84+
[array]$FirewallProfile = @("Domain", "Private")
85+
)
8686
8787
try {
88-
if ($PathToExecutables -eq "" ) {
89-
$PathToExecutables = read-host "Enter path to executables"
88+
if (-not $PathToExecutables) {
89+
$PathToExecutables = Read-Host "Enter path to executables"
9090
}
9191
92-
$PathToExecutables = Convert-Path -Path $PathToExecutables
92+
$AbsPath = Convert-Path -Path $PathToExecutables
93+
$Executables = Get-ChildItem -Path $AbsPath -Filter "*.exe"
9394
94-
$Apps = Get-ChildItem "$PathToExecutables\*.exe" -Name
95+
if (-not $Executables) {
96+
Write-Warning "No executables found. No Firewall rules have been created."
97+
Read-Host "Press Enter to continue..."
98+
return
99+
}
100+
101+
foreach ($exe in $Executables) {
102+
$exeName = $exe.Name
103+
$exeFullPath = $exe.FullName
95104
96-
if($Apps.count -eq 0){
97-
write-warning "No executables found. No Firewall rules have been created."
98-
Write-Host -NoNewhLine 'Press any key to continue...';
99-
[void]$Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown');
100-
exit 1
105+
Write-Output "Adding firewall rule for $exeName"
106+
New-NetFirewallRule -DisplayName $exeName -Direction $Direction -Program $exeFullPath -Profile $FirewallProfile -Action Allow
101107
}
102108
103-
$arg = "PathToExecutables $Apps"
104-
Start-Process powershell -Verb runAs -ArgumentList "-command & {$command} $arg"
105-
exit 0 # success
109+
Write-Host -ForegroundColor Green "Done"
106110
} catch {
107-
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
108-
exit 1
111+
Write-Error "Error in line $($_.InvocationInfo.ScriptLineNumber): $($_.Exception.Message)"
109112
}
113+
110114
```
111115

112-
*(generated by convert-ps2md.ps1 using the comment-based help of add-firewall-rules.ps1 as of 09/01/2023 17:51:47)*
116+
*(generated by convert-ps2md.ps1 using the comment-based help of add-firewall-rules.ps1 as of 09/13/2023 09:48:36)*

Docs/add-memo.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,4 @@ try {
7979
}
8080
```
8181

82-
*(generated by convert-ps2md.ps1 using the comment-based help of add-memo.ps1 as of 09/01/2023 17:51:47)*
82+
*(generated by convert-ps2md.ps1 using the comment-based help of add-memo.ps1 as of 09/13/2023 09:48:37)*

Docs/alert.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,4 @@ try {
7171
}
7272
```
7373

74-
*(generated by convert-ps2md.ps1 using the comment-based help of alert.ps1 as of 09/01/2023 17:51:47)*
74+
*(generated by convert-ps2md.ps1 using the comment-based help of alert.ps1 as of 09/13/2023 09:48:37)*

Docs/build-repo.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -177,4 +177,4 @@ try {
177177
}
178178
```
179179

180-
*(generated by convert-ps2md.ps1 using the comment-based help of build-repo.ps1 as of 09/01/2023 17:51:47)*
180+
*(generated by convert-ps2md.ps1 using the comment-based help of build-repo.ps1 as of 09/13/2023 09:48:37)*

Docs/build-repos.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,4 @@ try {
8282
}
8383
```
8484

85-
*(generated by convert-ps2md.ps1 using the comment-based help of build-repos.ps1 as of 09/01/2023 17:51:47)*
85+
*(generated by convert-ps2md.ps1 using the comment-based help of build-repos.ps1 as of 09/13/2023 09:48:37)*

Docs/cd-autostart.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,4 @@ try {
6060
}
6161
```
6262

63-
*(generated by convert-ps2md.ps1 using the comment-based help of cd-autostart.ps1 as of 09/01/2023 17:51:47)*
63+
*(generated by convert-ps2md.ps1 using the comment-based help of cd-autostart.ps1 as of 09/13/2023 09:48:37)*

Docs/cd-crashdumps.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,4 @@ try {
6060
}
6161
```
6262

63-
*(generated by convert-ps2md.ps1 using the comment-based help of cd-crashdumps.ps1 as of 09/01/2023 17:51:47)*
63+
*(generated by convert-ps2md.ps1 using the comment-based help of cd-crashdumps.ps1 as of 09/13/2023 09:48:37)*

Docs/cd-desktop.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,4 @@ try {
6464
}
6565
```
6666

67-
*(generated by convert-ps2md.ps1 using the comment-based help of cd-desktop.ps1 as of 09/01/2023 17:51:47)*
67+
*(generated by convert-ps2md.ps1 using the comment-based help of cd-desktop.ps1 as of 09/13/2023 09:48:37)*

Docs/cd-docs.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,4 @@ try {
6464
}
6565
```
6666

67-
*(generated by convert-ps2md.ps1 using the comment-based help of cd-docs.ps1 as of 09/01/2023 17:51:47)*
67+
*(generated by convert-ps2md.ps1 using the comment-based help of cd-docs.ps1 as of 09/13/2023 09:48:37)*

Docs/cd-downloads.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,4 @@ try {
6464
}
6565
```
6666

67-
*(generated by convert-ps2md.ps1 using the comment-based help of cd-downloads.ps1 as of 09/01/2023 17:51:47)*
67+
*(generated by convert-ps2md.ps1 using the comment-based help of cd-downloads.ps1 as of 09/13/2023 09:48:37)*

Docs/cd-dropbox.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,4 @@ try {
6060
}
6161
```
6262

63-
*(generated by convert-ps2md.ps1 using the comment-based help of cd-dropbox.ps1 as of 09/01/2023 17:51:47)*
63+
*(generated by convert-ps2md.ps1 using the comment-based help of cd-dropbox.ps1 as of 09/13/2023 09:48:37)*

Docs/cd-etc.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,4 @@ try {
6464
}
6565
```
6666

67-
*(generated by convert-ps2md.ps1 using the comment-based help of cd-etc.ps1 as of 09/01/2023 17:51:47)*
67+
*(generated by convert-ps2md.ps1 using the comment-based help of cd-etc.ps1 as of 09/13/2023 09:48:37)*

Docs/cd-fonts.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,4 @@ try {
6060
}
6161
```
6262

63-
*(generated by convert-ps2md.ps1 using the comment-based help of cd-fonts.ps1 as of 09/01/2023 17:51:47)*
63+
*(generated by convert-ps2md.ps1 using the comment-based help of cd-fonts.ps1 as of 09/13/2023 09:48:37)*

Docs/cd-home.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,4 @@ try {
6060
}
6161
```
6262

63-
*(generated by convert-ps2md.ps1 using the comment-based help of cd-home.ps1 as of 09/01/2023 17:51:47)*
63+
*(generated by convert-ps2md.ps1 using the comment-based help of cd-home.ps1 as of 09/13/2023 09:48:37)*

Docs/cd-logs.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,4 @@ try {
4848
}
4949
```
5050

51-
*(generated by convert-ps2md.ps1 using the comment-based help of cd-logs.ps1 as of 09/01/2023 17:51:47)*
51+
*(generated by convert-ps2md.ps1 using the comment-based help of cd-logs.ps1 as of 09/13/2023 09:48:37)*

Docs/cd-music.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,4 @@ try {
6464
}
6565
```
6666

67-
*(generated by convert-ps2md.ps1 using the comment-based help of cd-music.ps1 as of 09/01/2023 17:51:47)*
67+
*(generated by convert-ps2md.ps1 using the comment-based help of cd-music.ps1 as of 09/13/2023 09:48:37)*

Docs/cd-onedrive.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,4 @@ try {
6060
}
6161
```
6262

63-
*(generated by convert-ps2md.ps1 using the comment-based help of cd-onedrive.ps1 as of 09/01/2023 17:51:48)*
63+
*(generated by convert-ps2md.ps1 using the comment-based help of cd-onedrive.ps1 as of 09/13/2023 09:48:37)*

Docs/cd-pics.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,4 @@ try {
6262
}
6363
```
6464

65-
*(generated by convert-ps2md.ps1 using the comment-based help of cd-pics.ps1 as of 09/01/2023 17:51:48)*
65+
*(generated by convert-ps2md.ps1 using the comment-based help of cd-pics.ps1 as of 09/13/2023 09:48:37)*

Docs/cd-public.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,4 @@ try {
6262
}
6363
```
6464

65-
*(generated by convert-ps2md.ps1 using the comment-based help of cd-public.ps1 as of 09/01/2023 17:51:48)*
65+
*(generated by convert-ps2md.ps1 using the comment-based help of cd-public.ps1 as of 09/13/2023 09:48:37)*

Docs/cd-recycle-bin.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,4 @@ try {
5353
}
5454
```
5555

56-
*(generated by convert-ps2md.ps1 using the comment-based help of cd-recycle-bin.ps1 as of 09/01/2023 17:51:48)*
56+
*(generated by convert-ps2md.ps1 using the comment-based help of cd-recycle-bin.ps1 as of 09/13/2023 09:48:37)*

Docs/cd-repos.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,4 @@ try {
8080
}
8181
```
8282

83-
*(generated by convert-ps2md.ps1 using the comment-based help of cd-repos.ps1 as of 09/01/2023 17:51:48)*
83+
*(generated by convert-ps2md.ps1 using the comment-based help of cd-repos.ps1 as of 09/13/2023 09:48:37)*

Docs/cd-root.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,4 @@ try {
5757
}
5858
```
5959

60-
*(generated by convert-ps2md.ps1 using the comment-based help of cd-root.ps1 as of 09/01/2023 17:51:48)*
60+
*(generated by convert-ps2md.ps1 using the comment-based help of cd-root.ps1 as of 09/13/2023 09:48:37)*

Docs/cd-screenshots.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,4 @@ try {
5555
}
5656
```
5757

58-
*(generated by convert-ps2md.ps1 using the comment-based help of cd-screenshots.ps1 as of 09/01/2023 17:51:48)*
58+
*(generated by convert-ps2md.ps1 using the comment-based help of cd-screenshots.ps1 as of 09/13/2023 09:48:37)*

Docs/cd-scripts.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,4 @@ try {
5858
}
5959
```
6060

61-
*(generated by convert-ps2md.ps1 using the comment-based help of cd-scripts.ps1 as of 09/01/2023 17:51:48)*
61+
*(generated by convert-ps2md.ps1 using the comment-based help of cd-scripts.ps1 as of 09/13/2023 09:48:37)*

Docs/cd-ssh.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,4 @@ try {
5858
}
5959
```
6060

61-
*(generated by convert-ps2md.ps1 using the comment-based help of cd-ssh.ps1 as of 09/01/2023 17:51:48)*
61+
*(generated by convert-ps2md.ps1 using the comment-based help of cd-ssh.ps1 as of 09/13/2023 09:48:37)*

Docs/cd-temp.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,4 @@ try {
5050
}
5151
```
5252

53-
*(generated by convert-ps2md.ps1 using the comment-based help of cd-temp.ps1 as of 09/01/2023 17:51:48)*
53+
*(generated by convert-ps2md.ps1 using the comment-based help of cd-temp.ps1 as of 09/13/2023 09:48:37)*

Docs/cd-templates.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,4 @@ try {
6262
}
6363
```
6464

65-
*(generated by convert-ps2md.ps1 using the comment-based help of cd-templates.ps1 as of 09/01/2023 17:51:48)*
65+
*(generated by convert-ps2md.ps1 using the comment-based help of cd-templates.ps1 as of 09/13/2023 09:48:37)*

Docs/cd-trash.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,4 @@ try {
5353
}
5454
```
5555

56-
*(generated by convert-ps2md.ps1 using the comment-based help of cd-trash.ps1 as of 09/01/2023 17:51:48)*
56+
*(generated by convert-ps2md.ps1 using the comment-based help of cd-trash.ps1 as of 09/13/2023 09:48:37)*

Docs/cd-up.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,4 @@ try {
5858
}
5959
```
6060

61-
*(generated by convert-ps2md.ps1 using the comment-based help of cd-up.ps1 as of 09/01/2023 17:51:48)*
61+
*(generated by convert-ps2md.ps1 using the comment-based help of cd-up.ps1 as of 09/13/2023 09:48:37)*

Docs/cd-up2.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,4 @@ try {
5858
}
5959
```
6060

61-
*(generated by convert-ps2md.ps1 using the comment-based help of cd-up2.ps1 as of 09/01/2023 17:51:48)*
61+
*(generated by convert-ps2md.ps1 using the comment-based help of cd-up2.ps1 as of 09/13/2023 09:48:37)*

Docs/cd-up3.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,4 @@ try {
5858
}
5959
```
6060

61-
*(generated by convert-ps2md.ps1 using the comment-based help of cd-up3.ps1 as of 09/01/2023 17:51:48)*
61+
*(generated by convert-ps2md.ps1 using the comment-based help of cd-up3.ps1 as of 09/13/2023 09:48:37)*

Docs/cd-up4.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,4 @@ try {
5858
}
5959
```
6060

61-
*(generated by convert-ps2md.ps1 using the comment-based help of cd-up4.ps1 as of 09/01/2023 17:51:48)*
61+
*(generated by convert-ps2md.ps1 using the comment-based help of cd-up4.ps1 as of 09/13/2023 09:48:37)*

Docs/cd-users.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,4 @@ try {
5858
}
5959
```
6060

61-
*(generated by convert-ps2md.ps1 using the comment-based help of cd-users.ps1 as of 09/01/2023 17:51:48)*
61+
*(generated by convert-ps2md.ps1 using the comment-based help of cd-users.ps1 as of 09/13/2023 09:48:37)*

Docs/cd-videos.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,4 @@ try {
6262
}
6363
```
6464

65-
*(generated by convert-ps2md.ps1 using the comment-based help of cd-videos.ps1 as of 09/01/2023 17:51:48)*
65+
*(generated by convert-ps2md.ps1 using the comment-based help of cd-videos.ps1 as of 09/13/2023 09:48:37)*

Docs/cd-windows.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,4 @@ try {
5858
}
5959
```
6060

61-
*(generated by convert-ps2md.ps1 using the comment-based help of cd-windows.ps1 as of 09/01/2023 17:51:48)*
61+
*(generated by convert-ps2md.ps1 using the comment-based help of cd-windows.ps1 as of 09/13/2023 09:48:37)*

Docs/change-wallpaper.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,4 @@ try {
7979
}
8080
```
8181

82-
*(generated by convert-ps2md.ps1 using the comment-based help of change-wallpaper.ps1 as of 09/01/2023 17:51:48)*
82+
*(generated by convert-ps2md.ps1 using the comment-based help of change-wallpaper.ps1 as of 09/13/2023 09:48:37)*

Docs/check-apps.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,4 @@ try {
7575
}
7676
```
7777

78-
*(generated by convert-ps2md.ps1 using the comment-based help of check-apps.ps1 as of 09/01/2023 17:51:48)*
78+
*(generated by convert-ps2md.ps1 using the comment-based help of check-apps.ps1 as of 09/13/2023 09:48:37)*

Docs/check-bios.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,4 @@ try {
7676
}
7777
```
7878

79-
*(generated by convert-ps2md.ps1 using the comment-based help of check-bios.ps1 as of 09/01/2023 17:51:48)*
79+
*(generated by convert-ps2md.ps1 using the comment-based help of check-bios.ps1 as of 09/13/2023 09:48:37)*

Docs/check-cpu.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,4 @@ try {
103103
}
104104
```
105105

106-
*(generated by convert-ps2md.ps1 using the comment-based help of check-cpu.ps1 as of 09/01/2023 17:51:48)*
106+
*(generated by convert-ps2md.ps1 using the comment-based help of check-cpu.ps1 as of 09/13/2023 09:48:37)*

Docs/check-day.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,4 @@ try {
5757
}
5858
```
5959

60-
*(generated by convert-ps2md.ps1 using the comment-based help of check-day.ps1 as of 09/01/2023 17:51:48)*
60+
*(generated by convert-ps2md.ps1 using the comment-based help of check-day.ps1 as of 09/13/2023 09:48:37)*

0 commit comments

Comments
 (0)