mirror of
https://github.com/fleschutz/PowerShell.git
synced 2025-08-09 05:04:39 +02:00
Merge branch 'master' into master
This commit is contained in:
@ -1,15 +1,16 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Adds firewall rules for executables (needs admin rights)
|
||||
Adds firewall rules for executables (needs admin rights).
|
||||
.DESCRIPTION
|
||||
This PowerShell script adds firewall rules for the given executable. Administrator rights are required.
|
||||
.PARAMETER PathToExecutables
|
||||
Specifies the path to the executables
|
||||
Specifies the path to the executables.
|
||||
.PARAMETER Direction
|
||||
Specifies the direction for the firewall rule. Can be 'Inbound' or 'Outbound'. Default is 'Inbound'.
|
||||
.PARAMETER Profile
|
||||
Specifies the firewall profile. Can be 'Domain', 'Private', or 'Public'. Multiple values can be specified as an array.
|
||||
.EXAMPLE
|
||||
PS> ./add-firewall-rules.ps1 C:\MyApp\bin
|
||||
Adding firewall rule for C:\MyApp\bin\app1.exe
|
||||
Adding firewall rule for C:\MyApp\bin\app2.exe
|
||||
...
|
||||
PS> ./add-firewall-rules.ps1 -PathToExecutables C:\MyApp\bin -Direction Outbound -Profile Private
|
||||
.LINK
|
||||
https://github.com/fleschutz/PowerShell
|
||||
.NOTES
|
||||
@ -18,47 +19,36 @@
|
||||
|
||||
#Requires -RunAsAdministrator
|
||||
|
||||
param([string]$PathToExecutables = "")
|
||||
|
||||
$command = '
|
||||
$output = ''Firewall rules for path '' + $args[0]
|
||||
write-output $output
|
||||
for($i = 1; $i -lt $args.count; $i++){
|
||||
$path = $args[0]
|
||||
$path += ''\''
|
||||
$path += $args[$i]
|
||||
|
||||
$null = $args[$i] -match ''[^\\]*\.exe$''
|
||||
$name = $matches[0]
|
||||
$output = ''Adding firewall rule for '' + $name
|
||||
write-output $output
|
||||
$null = New-NetFirewallRule -DisplayName $name -Direction Inbound -Program $path -Profile Domain, Private -Action Allow
|
||||
}
|
||||
write-host -foregroundColor green -noNewline ''Done - press any key to continue...'';
|
||||
[void]$Host.UI.RawUI.ReadKey(''NoEcho,IncludeKeyDown'');
|
||||
'
|
||||
|
||||
param(
|
||||
[string]$PathToExecutables = "",
|
||||
[string]$Direction = "Inbound",
|
||||
[array]$FirewallProfile = @("Domain", "Private")
|
||||
)
|
||||
|
||||
try {
|
||||
if ($PathToExecutables -eq "" ) {
|
||||
$PathToExecutables = read-host "Enter path to executables"
|
||||
if (-not $PathToExecutables) {
|
||||
$PathToExecutables = Read-Host "Enter path to executables"
|
||||
}
|
||||
|
||||
$PathToExecutables = Convert-Path -Path $PathToExecutables
|
||||
$AbsPath = Convert-Path -Path $PathToExecutables
|
||||
$Executables = Get-ChildItem -Path $AbsPath -Filter "*.exe"
|
||||
|
||||
$Apps = Get-ChildItem "$PathToExecutables\*.exe" -Name
|
||||
|
||||
if($Apps.count -eq 0){
|
||||
write-warning "No executables found. No Firewall rules have been created."
|
||||
Write-Host -NoNewhLine 'Press any key to continue...';
|
||||
[void]$Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown');
|
||||
exit 1
|
||||
if (-not $Executables) {
|
||||
Write-Warning "No executables found. No Firewall rules have been created."
|
||||
Read-Host "Press Enter to continue..."
|
||||
return
|
||||
}
|
||||
|
||||
$arg = "PathToExecutables $Apps"
|
||||
Start-Process powershell -Verb runAs -ArgumentList "-command & {$command} $arg"
|
||||
exit 0 # success
|
||||
foreach ($exe in $Executables) {
|
||||
$exeName = $exe.Name
|
||||
$exeFullPath = $exe.FullName
|
||||
|
||||
Write-Output "Adding firewall rule for $exeName"
|
||||
New-NetFirewallRule -DisplayName $exeName -Direction $Direction -Program $exeFullPath -Profile $FirewallProfile -Action Allow
|
||||
}
|
||||
|
||||
Write-Host -ForegroundColor Green "Done"
|
||||
} catch {
|
||||
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
exit 1
|
||||
Write-Error "Error in line $($_.InvocationInfo.ScriptLineNumber): $($_.Exception.Message)"
|
||||
}
|
||||
|
||||
|
0
Scripts/cd-crashdumps.ps1
Normal file → Executable file
0
Scripts/cd-crashdumps.ps1
Normal file → Executable file
0
Scripts/cd-etc.ps1
Normal file → Executable file
0
Scripts/cd-etc.ps1
Normal file → Executable file
0
Scripts/cd-logs.ps1
Normal file → Executable file
0
Scripts/cd-logs.ps1
Normal file → Executable file
@ -1,11 +1,11 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Check DNS resolution
|
||||
Check the DNS resolution
|
||||
.DESCRIPTION
|
||||
This PowerShell script measures and prints the DNS resolution speed by using 200 popular domains.
|
||||
This PowerShell script measures the DNS resolution speed (using 100 popular domains) and prints it.
|
||||
.EXAMPLE
|
||||
PS> ./check-dns.ps1
|
||||
✅ DNS resolves 156.5 domains per second
|
||||
✅ DNS resolves 56.5 domains per second
|
||||
.LINK
|
||||
https://github.com/fleschutz/PowerShell
|
||||
.NOTES
|
||||
@ -13,15 +13,15 @@
|
||||
#>
|
||||
|
||||
try {
|
||||
Write-Progress "⏳ Resolving 200 popular domain names..."
|
||||
$table = Import-CSV "$PSScriptRoot/../Data/popular-domains.csv"
|
||||
$numRows = $table.Length
|
||||
Write-Progress "⏳ Resolving $numRows domain names..."
|
||||
|
||||
$stopWatch = [system.diagnostics.stopwatch]::startNew()
|
||||
if ($IsLinux) {
|
||||
foreach($row in $table){$nop=dig $row.Domain +short}
|
||||
foreach($row in $table){$nop=dig $row.Domain +short}
|
||||
} else {
|
||||
foreach($row in $table){$nop=Resolve-DNSName $row.Domain}
|
||||
foreach($row in $table){$nop=Resolve-DNSName $row.Domain}
|
||||
}
|
||||
Write-Progress -completed "."
|
||||
[float]$elapsed = $stopWatch.Elapsed.TotalSeconds
|
||||
|
@ -7,15 +7,15 @@
|
||||
Specifies the minimum warning level (10 GB by default)
|
||||
.EXAMPLE
|
||||
PS> ./check-drives.ps1
|
||||
✅ Drive C: at 49% of 1TB, 512GB free
|
||||
✅ Drive D: at 84% of 4TB, 641GB free
|
||||
✅ Drive C: uses 49% of 1TB, 512GB free
|
||||
✅ Drive D: uses 84% of 4TB, 641GB free
|
||||
.LINK
|
||||
https://github.com/fleschutz/PowerShell
|
||||
.NOTES
|
||||
Author: Markus Fleschutz | License: CC0
|
||||
#>
|
||||
|
||||
param([int]$minLevel = 10) # 10 GB minimum
|
||||
param([int64]$minLevel = 10) # 10 GB minimum
|
||||
|
||||
function Bytes2String { param([int64]$bytes)
|
||||
if ($bytes -lt 1000) { return "$bytes bytes" }
|
||||
@ -34,6 +34,7 @@ function Bytes2String { param([int64]$bytes)
|
||||
try {
|
||||
Write-Progress "⏳ Querying drives..."
|
||||
$drives = Get-PSDrive -PSProvider FileSystem
|
||||
$minLevel *= 1000 * 1000 * 1000
|
||||
Write-Progress -completed "."
|
||||
foreach($drive in $drives) {
|
||||
$details = (Get-PSDrive $drive.Name)
|
||||
@ -50,7 +51,7 @@ try {
|
||||
Write-Host "⚠️ Drive $name with $(Bytes2String $total) is nearly full, $(Bytes2String $free) free"
|
||||
} else {
|
||||
[int]$percent = ($used * 100) / $total
|
||||
Write-Host "✅ Drive $name at $percent% of $(Bytes2String $total), $(Bytes2String $free) free"
|
||||
Write-Host "✅ Drive $name uses $percent% of $(Bytes2String $total), $(Bytes2String $free) free"
|
||||
}
|
||||
}
|
||||
exit 0 # success
|
||||
|
2
Scripts/check-hardware.ps1
Normal file → Executable file
2
Scripts/check-hardware.ps1
Normal file → Executable file
@ -22,5 +22,5 @@
|
||||
& "$PSScriptRoot/check-gpu.ps1"
|
||||
& "$PSScriptRoot/check-smart-devices.ps1"
|
||||
& "$PSScriptRoot/check-drives.ps1"
|
||||
& "$PSScriptRoot/check-battery.ps1"
|
||||
& "$PSScriptRoot/check-power.ps1"
|
||||
exit 0 # success
|
||||
|
@ -1,30 +0,0 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Checks the IP address
|
||||
.DESCRIPTION
|
||||
This PowerShell script queries the public IP address and prints it.
|
||||
.EXAMPLE
|
||||
PS> ./check-ip.ps1
|
||||
✅ Public IPv4 185.77.209.161, IPv6 2003:f2:6128:fc01:e503:601:30c2:a028 near Munich
|
||||
.LINK
|
||||
https://github.com/fleschutz/PowerShell
|
||||
.NOTES
|
||||
Author: Markus Fleschutz | License: CC0
|
||||
#>
|
||||
|
||||
try {
|
||||
if ($IsLinux) {
|
||||
$PublicIPv4 = (curl -4 --silent ifconfig.co)
|
||||
$PublicIPv6 = (curl -6 --silent ifconfig.co)
|
||||
$City = (curl --silent ifconfig.co/city)
|
||||
} else {
|
||||
$PublicIPv4 = (curl.exe -4 --silent ifconfig.co)
|
||||
$PublicIPv6 = (curl.exe -6 --silent ifconfig.co)
|
||||
$City = (curl.exe --silent ifconfig.co/city)
|
||||
}
|
||||
Write-Output "✅ Public IPv4 $PublicIPv4, IPv6 $PublicIPv6 near $City"
|
||||
exit 0 # success
|
||||
} catch {
|
||||
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
exit 1
|
||||
}
|
6
Scripts/check-network.ps1
Normal file → Executable file
6
Scripts/check-network.ps1
Normal file → Executable file
@ -7,7 +7,7 @@
|
||||
PS> ./check-network.ps1
|
||||
|
||||
N E T W O R K
|
||||
✅ Firewall enabled
|
||||
✅ Online with 30ms latency (16ms..56ms, 0/10 loss)
|
||||
...
|
||||
.LINK
|
||||
https://github.com/fleschutz/PowerShell
|
||||
@ -17,9 +17,9 @@
|
||||
|
||||
" "
|
||||
& "$PSScriptRoot/write-green.ps1" " N E T W O R K"
|
||||
& "$PSScriptRoot/check-firewall"
|
||||
& "$PSScriptRoot/check-ping.ps1"
|
||||
& "$PSScriptRoot/check-firewall"
|
||||
& "$PSScriptRoot/check-dns.ps1"
|
||||
& "$PSScriptRoot/check-vpn.ps1"
|
||||
& "$PSScriptRoot/check-ip.ps1"
|
||||
& "$PSScriptRoot/list-public-ip.ps1"
|
||||
exit 0 # success
|
@ -7,7 +7,7 @@
|
||||
Specifies the hosts to check, seperated by commata (default is: amazon.com,bing.com,cnn.com,dropbox.com,github.com,google.com,live.com,meta.com,x.com,youtube.com)
|
||||
.EXAMPLE
|
||||
PS> ./check-ping.ps1
|
||||
✅ Ping latency is 29ms average (13ms...109ms, 0/10 loss)
|
||||
✅ Online with 18ms latency average (13ms...109ms, 0/10 ping loss)
|
||||
.LINK
|
||||
https://github.com/fleschutz/PowerShell
|
||||
.NOTES
|
||||
@ -19,28 +19,26 @@ param([string]$hosts = "bing.com,cnn.com,dropbox.com,github.com,google.com,ibm.c
|
||||
try {
|
||||
$hostsArray = $hosts.Split(",")
|
||||
$parallelTasks = $hostsArray | foreach {
|
||||
(New-Object Net.NetworkInformation.Ping).SendPingAsync($_, 500)
|
||||
(New-Object Net.NetworkInformation.Ping).SendPingAsync($_,750)
|
||||
}
|
||||
[int]$min = 9999999
|
||||
[int]$max = [int]$avg = [int]$successCount = [int]$lossCount = 0
|
||||
[int]$totalCount = $hostsArray.Count
|
||||
[int]$max = [int]$avg = [int]$success = 0
|
||||
[int]$total = $hostsArray.Count
|
||||
[Threading.Tasks.Task]::WaitAll($parallelTasks)
|
||||
foreach($ping in $parallelTasks.Result) {
|
||||
if ($ping.Status -eq "Success") {
|
||||
[int]$latency = $ping.RoundtripTime
|
||||
if ($latency -lt $min) { $min = $latency }
|
||||
if ($latency -gt $max) { $max = $latency }
|
||||
$avg += $latency
|
||||
$successCount++
|
||||
} else {
|
||||
$lossCount++
|
||||
}
|
||||
if ($ping.Status -ne "Success") { continue }
|
||||
$success++
|
||||
[int]$latency = $ping.RoundtripTime
|
||||
$avg += $latency
|
||||
if ($latency -lt $min) { $min = $latency }
|
||||
if ($latency -gt $max) { $max = $latency }
|
||||
}
|
||||
if ($successCount -eq 0) {
|
||||
Write-Host "⚠️ Offline ($lossCount/$totalCount loss)"
|
||||
[int]$loss = $total - $success
|
||||
if ($success -ne 0) {
|
||||
$avg /= $success
|
||||
Write-Host "✅ Online with $($avg)ms latency average ($($min)ms...$($max)ms, $loss/$total ping loss)"
|
||||
} else {
|
||||
$avg /= $successCount
|
||||
Write-Host "✅ Ping latency is $($avg)ms average ($($min)ms...$($max)ms, $lossCount/$totalCount loss)"
|
||||
Write-Host "⚠️ Offline ($loss/$total ping loss)"
|
||||
}
|
||||
exit 0 # success
|
||||
} catch {
|
||||
|
@ -1,11 +1,11 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Checks the battery
|
||||
Checks the power status
|
||||
.DESCRIPTION
|
||||
This PowerShell script queries the status of the system battery and prints it.
|
||||
This PowerShell script queries the power status and prints it.
|
||||
.EXAMPLE
|
||||
PS> ./check-battery.ps1
|
||||
⚠️ Battery 9% low, 54 min remaining
|
||||
PS> ./check-power.ps1
|
||||
⚠️ Battery at 9% (54 min remaining) with power scheme: HP Optimized
|
||||
.LINK
|
||||
https://github.com/fleschutz/PowerShell
|
||||
.NOTES
|
||||
@ -30,19 +30,23 @@ try {
|
||||
}
|
||||
} else { # must be offline
|
||||
if ($Remaining -eq 0) {
|
||||
$Reply = "✅ Battery at $Percent%, calculating remaining time..."
|
||||
$Reply = "✅ Battery at $Percent%"
|
||||
} elseif ($Remaining -le 5) {
|
||||
$Reply = "⚠️ Battery at $Percent%, ONLY $Remaining MIN remaining"
|
||||
} elseif ($Remaining -le 30) {
|
||||
$Reply = "⚠️ Battery at $Percent%, only $Remaining min remaining"
|
||||
} elseif ($Percent -lt 10) {
|
||||
$Reply = "⚠️ Battery $Percent% low, $Remaining min remaining"
|
||||
$Reply = "⚠️ Battery at $Percent% with $Remaining min remaining"
|
||||
} elseif ($Percent -ge 80) {
|
||||
$Reply = "✅ Battery $Percent% full, $Remaining min remaining"
|
||||
$Reply = "✅ Battery $Percent% full with $Remaining min remaining"
|
||||
} else {
|
||||
$Reply = "✅ Battery at $Percent%, $Remaining min remaining"
|
||||
$Reply = "✅ Battery at $Percent% with $Remaining min remaining"
|
||||
}
|
||||
}
|
||||
$PowerScheme = (powercfg /getactivescheme)
|
||||
$PowerScheme = $PowerScheme -Replace "^(.*) \(",""
|
||||
$PowerScheme = $PowerScheme -Replace "\)$",""
|
||||
$Reply += ", power scheme is '$PowerScheme'"
|
||||
}
|
||||
Write-Output $Reply
|
||||
exit 0 # success
|
@ -5,7 +5,7 @@
|
||||
This PowerShell script queries the PowerShell status and prints it.
|
||||
.EXAMPLE
|
||||
PS> ./check-powershell.ps1
|
||||
✅ PowerShell Desktop edition 5.1.19041.2673 (10 modules, 1458 cmdlets, 172 aliases)
|
||||
✅ PowerShell 5.1.19041.2673 Desktop edition (10 modules, 1458 cmdlets, 172 aliases)
|
||||
.LINK
|
||||
https://github.com/fleschutz/PowerShell
|
||||
.NOTES
|
||||
@ -13,15 +13,15 @@
|
||||
#>
|
||||
|
||||
try {
|
||||
$Version = $PSVersionTable.PSVersion
|
||||
$Edition = $PSVersionTable.PSEdition
|
||||
$NumModules = (Get-Module).Count
|
||||
$NumAliases = (Get-Alias).Count
|
||||
$version = $PSVersionTable.PSVersion
|
||||
$edition = $PSVersionTable.PSEdition
|
||||
$numModules = (Get-Module).Count
|
||||
$numAliases = (Get-Alias).Count
|
||||
if ($IsLinux) {
|
||||
"✅ PowerShell $Edition edition $Version ($NumModules modules, $NumAliases aliases)"
|
||||
"✅ PowerShell $version $edition edition ($numModules modules, $numAliases aliases)"
|
||||
} else {
|
||||
$NumCmdlets = (Get-Command -Command-Type cmdlet).Count
|
||||
"✅ PowerShell $Edition edition $Version ($NumModules modules, $NumCmdlets cmdlets, $NumAliases aliases)"
|
||||
$numCmdlets = (Get-Command -Command-Type cmdlet).Count
|
||||
"✅ PowerShell $version $edition edition ($numModules modules, $numCmdlets cmdlets, $numAliases aliases)"
|
||||
}
|
||||
exit 0 # success
|
||||
} catch {
|
||||
|
0
Scripts/check-ps1-file.ps1
Normal file → Executable file
0
Scripts/check-ps1-file.ps1
Normal file → Executable file
@ -1,11 +1,11 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Check the RAM status
|
||||
Checks the RAM
|
||||
.DESCRIPTION
|
||||
This PowerShell script queries the status of the installed RAM and prints it.
|
||||
This PowerShell script queries the status of the installed RAM memory modules and prints it.
|
||||
.EXAMPLE
|
||||
PS> ./check-ram.ps1
|
||||
✅ 16GB DDR4 RAM @ 3200MHz (1.2V) in P0 CHANNEL A/DIMM 0 by Samsung
|
||||
✅ 16GB DDR4 RAM @ 3200MHz by Micron (in CPU0/CPU0-DIMM3 @ 1.2V)
|
||||
.LINK
|
||||
https://github.com/fleschutz/PowerShell
|
||||
.NOTES
|
||||
@ -69,7 +69,7 @@ try {
|
||||
[float]$Voltage = $Bank.ConfiguredVoltage / 1000.0
|
||||
$Manufacturer = $Bank.Manufacturer
|
||||
$Location = "$($Bank.BankLabel)/$($Bank.DeviceLocator)"
|
||||
Write-Host "✅ $Capacity $Type @ $($Speed)MHz ($($Voltage)V) in $Location by $Manufacturer"
|
||||
Write-Host "✅ $Capacity $Type @ $($Speed)MHz by $Manufacturer (in $Location @ $($Voltage)V)"
|
||||
}
|
||||
}
|
||||
exit 0 # success
|
||||
|
@ -70,7 +70,7 @@ try {
|
||||
|
||||
$RepoDirName = (Get-Item "$FullPath").Name
|
||||
[int]$Elapsed = $StopWatch.Elapsed.TotalSeconds
|
||||
"✔️ checked Git repository 📂$RepoDirName in $Elapsed sec"
|
||||
"✔️ Checked repo 📂$RepoDirName in $Elapsed sec"
|
||||
exit 0 # success
|
||||
} catch {
|
||||
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
|
0
Scripts/check-software.ps1
Normal file → Executable file
0
Scripts/check-software.ps1
Normal file → Executable file
@ -7,7 +7,7 @@
|
||||
Specifies the minimum level in GB (10 GB by default)
|
||||
.EXAMPLE
|
||||
PS> ./check-swap-space.ps1
|
||||
✅ Swap space at 42% of 1GB, 748MB free
|
||||
✅ Swap space uses 42% of 1GB, 748MB free
|
||||
.LINK
|
||||
https://github.com/fleschutz/PowerShell
|
||||
.NOTES
|
||||
@ -29,31 +29,31 @@ function MB2String { param([int64]$Bytes)
|
||||
}
|
||||
|
||||
try {
|
||||
[int]$Total = [int]$Used = [int]$Free = 0
|
||||
[int64]$Total = [int64]$Used = [int64]$Free = 0
|
||||
if ($IsLinux) {
|
||||
$Result = $(free --mega | grep Swap:)
|
||||
[int]$Total = $Result.subString(5,14)
|
||||
[int]$Used = $Result.substring(20,13)
|
||||
[int]$Free = $Result.substring(32,11)
|
||||
[int64]$Total = $Result.subString(5,14)
|
||||
[int64]$Used = $Result.substring(20,13)
|
||||
[int64]$Free = $Result.substring(32,11)
|
||||
} else {
|
||||
$Items = Get-WmiObject -class "Win32_PageFileUsage" -namespace "root\CIMV2" -computername localhost
|
||||
foreach ($Item in $Items) {
|
||||
$Total = $Item.AllocatedBaseSize
|
||||
$Used = $Item.CurrentUsage
|
||||
$Free = ($Total - $Used)
|
||||
$Total += $Item.AllocatedBaseSize
|
||||
$Used += $Item.CurrentUsage
|
||||
$Free += ($Total - $Used)
|
||||
}
|
||||
}
|
||||
if ($Total -eq 0) {
|
||||
Write-Output "⚠️ No swap space configured"
|
||||
} elseif ($Free -eq 0) {
|
||||
Write-Output "⚠️ $(MB2String $Total) Swap space is full"
|
||||
Write-Output "⚠️ Swap space of $(MB2String $Total) is full"
|
||||
} elseif ($Free -lt $minLevel) {
|
||||
Write-Output "⚠️ $(MB2String $Total) Swap space is nearly full, only $(MB2String $Free) free"
|
||||
Write-Output "⚠️ Swap space of $(MB2String $Total) is nearly full, only $(MB2String $Free) free"
|
||||
} elseif ($Used -eq 0) {
|
||||
Write-Output "✅ $(MB2String $Total) Swap space reserved"
|
||||
Write-Output "✅ Swap space of $(MB2String $Total) reserved"
|
||||
} else {
|
||||
[int]$Percent = ($Used * 100) / $Total
|
||||
Write-Output "✅ Swap space at $Percent% of $(MB2String $Total), $(MB2String $Free) free"
|
||||
Write-Output "✅ Swap space uses $Percent% of $(MB2String $Total), $(MB2String $Free) free"
|
||||
}
|
||||
exit 0 # success
|
||||
} catch {
|
||||
|
@ -2,10 +2,10 @@
|
||||
.SYNOPSIS
|
||||
Checks the VPN status
|
||||
.DESCRIPTION
|
||||
This PowerShell script queries and prints the status of the VPN connection(s).
|
||||
This PowerShell script queries the status of the VPN connection(s) and prints it.
|
||||
.EXAMPLE
|
||||
PS> ./check-vpn.ps1
|
||||
✅ VPN to NASA L2TP is disconnected
|
||||
✅ VPN to NASA L2TP is connected
|
||||
.LINK
|
||||
https://github.com/fleschutz/PowerShell
|
||||
.NOTES
|
||||
@ -13,17 +13,17 @@
|
||||
#>
|
||||
|
||||
try {
|
||||
$NoVPN = $true
|
||||
$noVPN = $true
|
||||
if ($IsLinux) {
|
||||
# TODO
|
||||
} else {
|
||||
$Connections = Get-VPNConnection
|
||||
foreach($Connection in $Connections) {
|
||||
Write-Host "✅ VPN to $($Connection.Name) is $($Connection.ConnectionStatus.ToLower())"
|
||||
$NoVPN = $false
|
||||
$noVPN = $false
|
||||
}
|
||||
}
|
||||
if ($NoVPN) { Write-Host "⚠️ No VPN configured" }
|
||||
if ($noVPN) { Write-Host "⚠️ No VPN configured" }
|
||||
exit 0 # success
|
||||
} catch {
|
||||
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
|
@ -12,7 +12,7 @@
|
||||
⏳ (2/4) Checking local repository... 📂C:\rust
|
||||
⏳ (3/4) Removing untracked files in repository...
|
||||
⏳ (4/4) Removing untracked files in submodules...
|
||||
✔️ Cleaning repository 📂rust took 1 sec
|
||||
✔️ Cleaned repo 📂rust in 1 sec
|
||||
.LINK
|
||||
https://github.com/fleschutz/PowerShell
|
||||
.NOTES
|
||||
@ -45,7 +45,7 @@ try {
|
||||
if ($lastExitCode -ne "0") { throw "'git clean' in the submodules failed with exit code $lastExitCode" }
|
||||
|
||||
[int]$Elapsed = $StopWatch.Elapsed.TotalSeconds
|
||||
"✔️ Cleaning repository 📂$RepoDirName took $Elapsed sec"
|
||||
"✔️ Cleaned repo 📂$RepoDirName in $Elapsed sec"
|
||||
exit 0 # success
|
||||
} catch {
|
||||
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
|
@ -5,7 +5,7 @@
|
||||
This PowerShell script clears the DNS client cache of the local computer.
|
||||
.EXAMPLE
|
||||
PS> ./clear-dns-cache.ps1
|
||||
✔️ cleared DNS cache in 0 ms
|
||||
✔️ Cleared DNS cache in 1 sec
|
||||
.LINK
|
||||
https://github.com/fleschutz/PowerShell
|
||||
.NOTES
|
||||
@ -18,7 +18,7 @@ try {
|
||||
Clear-DnsClientCache
|
||||
|
||||
[int]$Elapsed = $StopWatch.Elapsed.TotalSeconds
|
||||
"✔️ cleared DNS cache in $Elapsed sec"
|
||||
"✔️ Cleared DNS cache in $Elapsed sec"
|
||||
exit 0 # success
|
||||
} catch {
|
||||
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
|
@ -2,70 +2,75 @@
|
||||
.SYNOPSIS
|
||||
Configures Git
|
||||
.DESCRIPTION
|
||||
This PowerShell script configures the user settings for Git.
|
||||
.PARAMETER FullName
|
||||
This PowerShell script configures the Git user settings.
|
||||
.PARAMETER fullName
|
||||
Specifies the user's full name
|
||||
.PARAMETER EmailAddress
|
||||
.PARAMETER emailAddress
|
||||
Specifies the user's email address
|
||||
.PARAMETER FavoriteEditor
|
||||
.PARAMETER favoriteEditor
|
||||
Specifies the user's favorite text editor
|
||||
.EXAMPLE
|
||||
PS> ./configure-git.ps1
|
||||
PS> ./configure-git.ps1 "Joe Doe" joe@doe.com vim
|
||||
⏳ (1/6) Searching for Git executable... git version 2.42.0.windows.1
|
||||
⏳ (2/6) Query user settings...
|
||||
⏳ (3/6) Saving basic settings (autocrlf,symlinks,longpaths,etc.)...
|
||||
⏳ (4/6) Saving user settings (name,email,editor)...
|
||||
⏳ (5/6) Saving user shortcuts ('git br', 'git ls', 'git st', etc.)...
|
||||
⏳ (6/6) Listing your current settings...
|
||||
.LINK
|
||||
https://github.com/fleschutz/PowerShell
|
||||
.NOTES
|
||||
Author: Markus Fleschutz | License: CC0
|
||||
#>
|
||||
|
||||
param([string]$FullName = "", [string]$EmailAddress = "", [string]$FavoriteEditor = "")
|
||||
param([string]$fullName = "", [string]$emailAddress = "", [string]$favoriteEditor = "")
|
||||
|
||||
try {
|
||||
$StopWatch = [system.diagnostics.stopwatch]::startNew()
|
||||
|
||||
Write-Host "⏳ (1/6) Searching for Git executable... " -noNewline
|
||||
& git --version
|
||||
if ($lastExitCode -ne "0") { throw "Can't execute 'git' - make sure Git is installed and available" }
|
||||
|
||||
"⏳ (2/6) Asking for details..."
|
||||
if ($FullName -eq "") { $FullName = read-host "Enter your full name" }
|
||||
if ($EmailAddress -eq "") { $EmailAddress = read-host "Enter your e-mail address"}
|
||||
if ($FavoriteEditor -eq "") { $FavoriteEditor = read-host "Enter your favorite text editor (atom,emacs,nano,subl,vi,vim,...)" }
|
||||
"⏳ (2/6) Query user settings..."
|
||||
if ($fullName -eq "") { $fullName = Read-Host "Enter your full name" }
|
||||
if ($emailAddress -eq "") { $emailAddress = Read-Host "Enter your e-mail address"}
|
||||
if ($favoriteEditor -eq "") { $favoriteEditor = Read-Host "Enter your favorite text editor (atom,code,emacs,nano,notepad,subl,vi,vim,...)" }
|
||||
$stopWatch = [system.diagnostics.stopwatch]::startNew()
|
||||
|
||||
"⏳ (3/6) Saving basic settings (autocrlf,symlinks,longpaths,etc.)..."
|
||||
& git config --global core.autocrlf false # don't change newlines
|
||||
& git config --global core.symlinks true # enable support for symbolic link files
|
||||
& git config --global core.longpaths true # enable support for long file paths
|
||||
& git config --global init.defaultBranch main # set the default branch name to 'main'
|
||||
& git config --global merge.renamelimit 99999
|
||||
& git config --global merge.renamelimit 99999 # raise the rename limit
|
||||
& git config --global pull.rebase false
|
||||
& git config --global fetch.parallel 0 # enable parallel fetching to improve the speed
|
||||
if ($lastExitCode -ne "0") { throw "'git config' failed with exit code $lastExitCode" }
|
||||
|
||||
"⏳ (4/6) Saving personal settings (name,email,editor)..."
|
||||
& git config --global user.name $FullName
|
||||
& git config --global user.email $EmailAddress
|
||||
& git config --global core.editor $FavoriteEditor
|
||||
"⏳ (4/6) Saving user settings (name,email,editor)..."
|
||||
& git config --global user.name $fullName
|
||||
& git config --global user.email $emailAddress
|
||||
& git config --global core.editor $favoriteEditor
|
||||
if ($lastExitCode -ne "0") { throw "'git config' failed with exit code $lastExitCode" }
|
||||
|
||||
"⏳ (5/6) Saving personal shortcuts (git co, git br, etc.)..."
|
||||
& git config --global alias.co "checkout"
|
||||
"⏳ (5/6) Saving user shortcuts ('git br', 'git ls', 'git st', etc.)..."
|
||||
& git config --global alias.br "branch"
|
||||
& git config --global alias.chp "cherry-pick --no-commit"
|
||||
& git config --global alias.ci "commit"
|
||||
& git config --global alias.st "status"
|
||||
& git config --global alias.co "checkout"
|
||||
& git config --global alias.ls "log -n20 --pretty=format:'%Cred%h%Creset%C(yellow)%d%Creset %s %C(bold blue)by %an%Creset %C(green)%cr%Creset' --abbrev-commit"
|
||||
& git config --global alias.mrg "merge --no-commit --no-ff"
|
||||
& git config --global alias.pl "pull --recurse-submodules"
|
||||
& git config --global alias.ps "push"
|
||||
& git config --global alias.mrg "merge --no-commit --no-ff"
|
||||
& git config --global alias.chp "cherry-pick --no-commit"
|
||||
& git config --global alias.ls "log -n20 --pretty=format:'%Cred%h%Creset%C(yellow)%d%Creset %s %C(bold blue)by %an%Creset %C(green)%cr%Creset' --abbrev-commit"
|
||||
& git config --global alias.smu "submodule update --init"
|
||||
& git config --global alias.st "status"
|
||||
if ($lastExitCode -ne "0") { throw "'git config' failed" }
|
||||
|
||||
"⏳ (6/6) Listing your current settings..."
|
||||
& git config --list
|
||||
if ($lastExitCode -ne "0") { throw "'git config --list' failed with exit code $lastExitCode" }
|
||||
|
||||
[int]$Elapsed = $StopWatch.Elapsed.TotalSeconds
|
||||
"✔️ configured Git in $Elapsed sec"
|
||||
[int]$elapsed = $stopWatch.Elapsed.TotalSeconds
|
||||
"✔️ Saved your Git configuration in $elapsed sec"
|
||||
exit 0 # success
|
||||
} catch {
|
||||
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber)): $($Error[0])"
|
||||
|
@ -2,25 +2,27 @@
|
||||
.SYNOPSIS
|
||||
Copy photos sorted by year and month
|
||||
.DESCRIPTION
|
||||
This PowerShell script copies image files from SourceDir to TargetDir sorted by year and month.
|
||||
.PARAMETER SourceDir
|
||||
This PowerShell script copies image files from sourceDir to targetDir sorted by year and month.
|
||||
.PARAMETER sourceDir
|
||||
Specifies the path to the source folder
|
||||
.PARAMTER TargetDir
|
||||
.PARAMTER targetDir
|
||||
Specifies the path to the target folder
|
||||
.EXAMPLE
|
||||
PS> ./copy-photos-sorted.ps1 D:\iPhone\DCIM C:\MyPhotos
|
||||
⏳ Copying IMG_20230903_134445.jpg to C:\MyPhotos\2023\09 SEP\...
|
||||
✔️ Copied 1 photo to 📂C:\MyPhotos in 41 sec
|
||||
.LINK
|
||||
https://github.com/fleschutz/PowerShell
|
||||
.NOTES
|
||||
Author: Markus Fleschutz | License: CC0
|
||||
#>
|
||||
|
||||
param([string]$SourceDir = "", [string]$TargetDir = "")
|
||||
param([string]$sourceDir = "", [string]$targetDir = "")
|
||||
|
||||
function CopyFile { param([string]$SourcePath, [string]$TargetDir, [int]$Date, [string]$Filename)
|
||||
[int]$Year = $Date / 10000
|
||||
[int]$Month = ($Date / 100) % 100
|
||||
$MonthDir = switch($Month) {
|
||||
function CopyFile { param([string]$sourcePath, [string]$targetDir, [int]$date, [string]$filename)
|
||||
[int]$year = $date / 10000
|
||||
[int]$month = ($date / 100) % 100
|
||||
$monthDir = switch($month) {
|
||||
1 {"01 JAN"}
|
||||
2 {"02 FEB"}
|
||||
3 {"03 MAR"}
|
||||
@ -34,52 +36,52 @@ function CopyFile { param([string]$SourcePath, [string]$TargetDir, [int]$Date, [
|
||||
11 {"11 NOV"}
|
||||
12 {"12 DEC"}
|
||||
}
|
||||
$TargetPath = "$TargetDir/$Year/$MonthDir/$Filename"
|
||||
$TargetPath = "$targetDir/$year/$monthDir/$filename"
|
||||
if (Test-Path "$TargetPath" -pathType leaf) {
|
||||
Write-Host "⏳ Skipping existing $Year/$MonthDir/$Filename..."
|
||||
Write-Host "⏳ Skipping existing $targetDir\$year\$monthDir\$filename..."
|
||||
} else {
|
||||
Write-Host "⏳ Copying $Filename to $Year/$MonthDir..."
|
||||
New-Item -path "$TargetDir" -name "$Year" -itemType "directory" -force | out-null
|
||||
New-Item -path "$TargetDir/$Year" -name "$MonthDir" -itemType "directory" -force | out-null
|
||||
Copy-Item "$SourcePath" "$TargetPath" -force
|
||||
Write-Host "⏳ Copying $filename to $targetDir\$year\$monthDir\..."
|
||||
New-Item -path "$targetDir" -name "$year" -itemType "directory" -force | out-null
|
||||
New-Item -path "$targetDir/$year" -name "$monthDir" -itemType "directory" -force | out-null
|
||||
Copy-Item "$sourcePath" "$TargetPath" -force
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
if ($SourceDir -eq "") { $SourceDir = Read-Host "Enter file path to source directory" }
|
||||
if ($TargetDir -eq "") { $TargetDir = Read-Host "Enter file path to target directory" }
|
||||
$StopWatch = [system.diagnostics.stopwatch]::startNew()
|
||||
if ($sourceDir -eq "") { $sourceDir = Read-Host "Enter file path to the source directory" }
|
||||
if ($targetDir -eq "") { $targetDir = Read-Host "Enter file path to the target directory" }
|
||||
$stopWatch = [system.diagnostics.stopWatch]::startNew()
|
||||
|
||||
Write-Host "⏳ Checking source directory 📂$($SourceDir)..."
|
||||
if (-not(Test-Path "$SourceDir" -pathType container)) { throw "Can't access source directory: $SourceDir" }
|
||||
$Files = (Get-ChildItem "$SourceDir\*.jpg" -attributes !Directory)
|
||||
Write-Host "⏳ Checking source directory 📂$($sourceDir)..."
|
||||
if (-not(Test-Path "$sourceDir" -pathType container)) { throw "Can't access source directory: $sourceDir" }
|
||||
$files = (Get-ChildItem "$sourceDir\*.jpg" -attributes !Directory)
|
||||
|
||||
Write-Host "⏳ Checking target directory 📂$($TargetDir)..."
|
||||
if (-not(Test-Path "$TargetDir" -pathType container)) { throw "Can't access target directory: $TargetDir" }
|
||||
Write-Host "⏳ Checking target directory 📂$($targetDir)..."
|
||||
if (-not(Test-Path "$targetDir" -pathType container)) { throw "Can't access target directory: $targetDir" }
|
||||
|
||||
foreach($File in $Files) {
|
||||
$Filename = (Get-Item "$File").Name
|
||||
if ("$Filename" -like "IMG_*_*.jpg") {
|
||||
$Array = $Filename.split("_")
|
||||
CopyFile "$File" "$TargetDir" $Array[1] "$Filename"
|
||||
} elseif ("$Filename" -like "IMG-*-*.jpg") {
|
||||
$Array = $Filename.split("-")
|
||||
CopyFile "$File" "$TargetDir" $Array[1] "$Filename"
|
||||
} elseif ("$Filename" -like "PANO_*_*.jpg") {
|
||||
$Array = $Filename.split("_")
|
||||
CopyFile "$File" "$TargetDir" $Array[1] "$Filename"
|
||||
} elseif ("$Filename" -like "PANO-*-*.jpg") {
|
||||
$Array = $Filename.split("-")
|
||||
CopyFile "$File" "$TargetDir" $Array[1] "$Filename"
|
||||
} elseif ("$Filename" -like "SAVE_*_*.jpg") {
|
||||
$Array = $Filename.split("_")
|
||||
CopyFile "$File" "$TargetDir" $Array[1] "$Filename"
|
||||
foreach($file in $files) {
|
||||
$filename = (Get-Item "$file").Name
|
||||
if ("$filename" -like "IMG_*_*.jpg") {
|
||||
$Array = $filename.split("_")
|
||||
CopyFile "$file" "$targetDir" $Array[1] "$filename"
|
||||
} elseif ("$filename" -like "IMG-*-*.jpg") {
|
||||
$Array = $filename.split("-")
|
||||
CopyFile "$file" "$targetDir" $Array[1] "$filename"
|
||||
} elseif ("$filename" -like "PANO_*_*.jpg") {
|
||||
$Array = $filename.split("_")
|
||||
CopyFile "$file" "$targetDir" $Array[1] "$filename"
|
||||
} elseif ("$filename" -like "PANO-*-*.jpg") {
|
||||
$Array = $filename.split("-")
|
||||
CopyFile "$file" "$targetDir" $Array[1] "$filename"
|
||||
} elseif ("$filename" -like "SAVE_*_*.jpg") {
|
||||
$Array = $filename.split("_")
|
||||
CopyFile "$file" "$targetDir" $Array[1] "$filename"
|
||||
} else {
|
||||
Write-Host "⏳ Skipping $Filename with unknown filename format..."
|
||||
Write-Host "⏳ Skipping $filename with unknown filename format..."
|
||||
}
|
||||
}
|
||||
[int]$Elapsed = $StopWatch.Elapsed.TotalSeconds
|
||||
"✔️ copied $($Files.Count) photos from 📂$SourceDir to 📂$TargetDir in $Elapsed sec"
|
||||
[int]$elapsed = $stopWatch.Elapsed.TotalSeconds
|
||||
"✔️ Copied $($files.Count) photos to 📂$targetDir in $elapsed sec"
|
||||
exit 0 # success
|
||||
} catch {
|
||||
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
|
@ -1,41 +1,41 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Counts lines of code
|
||||
Counts the lines of code (LOC)
|
||||
.DESCRIPTION
|
||||
This PowerShell script counts the number of code lines in a folder (including subfolders).
|
||||
.PARAMETER Folder
|
||||
Specifies the path to the folder
|
||||
This PowerShell script counts the number of code lines in a directory tree.
|
||||
.PARAMETER path
|
||||
Specifies the path to the directory tree.
|
||||
.EXAMPLE
|
||||
PS> ./count-lines-of-code.ps1 .
|
||||
⏳ Counting lines at 📂C:\PowerShell\Scripts ...
|
||||
✔️ 📂Scripts contains 15287 lines of code in 485 files (took 1 sec)
|
||||
✔️ 19765 lines of code (LOC) in 578 files in 📂Scripts (it took 1 sec)
|
||||
.LINK
|
||||
https://github.com/fleschutz/PowerShell
|
||||
.NOTES
|
||||
Author: Markus Fleschutz | License: CC0
|
||||
#>
|
||||
|
||||
param([string]$Folder = "")
|
||||
param([string]$path = "")
|
||||
|
||||
try {
|
||||
if ($Folder -eq "" ) { $Folder = read-host "Enter the path to the folder" }
|
||||
if ($path -eq "" ) { $path = Read-Host "Enter the path to the directory tree" }
|
||||
|
||||
$StopWatch = [system.diagnostics.stopwatch]::startNew()
|
||||
$Folder = Resolve-Path "$Folder"
|
||||
"⏳ Counting lines at 📂$Folder ..."
|
||||
$stopWatch = [system.diagnostics.stopwatch]::startNew()
|
||||
$path = Resolve-Path "$path"
|
||||
|
||||
[int]$Files = [int]$CodeLines = 0
|
||||
Get-ChildItem -Path $Folder -Include *.c,*.h,*.cpp,*.hpp,*.java,*.ps1 -Recurse | ForEach-Object {
|
||||
$FileStats = Get-Content $_.FullName | Measure-Object -line
|
||||
$CodeLines += $FileStats.Lines
|
||||
$Files++
|
||||
Write-Progress "⏳ Counting lines of code in 📂$path ..."
|
||||
[int]$files = [int]$LOC = 0
|
||||
Get-ChildItem -Path $path -Include *.c,*.h,*.cpp,*.hpp,*.java,*.ps1 -Recurse | ForEach-Object {
|
||||
$fileStats = Get-Content $_.FullName | Measure-Object -line
|
||||
$LOC += $fileStats.Lines
|
||||
$files++
|
||||
}
|
||||
Write-Progress -completed "."
|
||||
|
||||
$FolderName = (Get-Item "$Folder").Name
|
||||
[int]$Elapsed = $StopWatch.Elapsed.TotalSeconds
|
||||
"✔️ 📂$FolderName contains $CodeLines lines of code in $Files files (took $Elapsed sec)"
|
||||
$folderName = (Get-Item "$path").Name
|
||||
[int]$Elapsed = $stopWatch.Elapsed.TotalSeconds
|
||||
"✔️ $LOC lines of code (LOC) in $files files in 📂$folderName (took $Elapsed sec)"
|
||||
exit 0 # success
|
||||
} catch {
|
||||
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
exit 1
|
||||
}
|
||||
}
|
22
Scripts/disable-ipv6.ps1
Executable file
22
Scripts/disable-ipv6.ps1
Executable file
@ -0,0 +1,22 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Disables IPv6 (requires admin rights)
|
||||
.DESCRIPTION
|
||||
This PowerShell script disables IPv6 on all network interfaces of the local computer (requires administrator rights).
|
||||
.EXAMPLE
|
||||
PS> ./disable-ipv6.ps1
|
||||
✔ IPv6 is disabled now.
|
||||
.LINK
|
||||
https://github.com/fleschutz/PowerShell
|
||||
.NOTES
|
||||
Author: Markus Fleschutz | License: CC0
|
||||
#>
|
||||
|
||||
try {
|
||||
Disable-NetAdapterBinding -Name '*' -ComponentID 'ms_tcpip6'
|
||||
"✔️ IPv6 is disabled now."
|
||||
exit 0 # success
|
||||
} catch {
|
||||
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
exit 1
|
||||
}
|
22
Scripts/enable-ipv6.ps1
Executable file
22
Scripts/enable-ipv6.ps1
Executable file
@ -0,0 +1,22 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Enables IPv6
|
||||
.DESCRIPTION
|
||||
This PowerShell script enables IPv6 on all network interfaces of the local computer.
|
||||
.EXAMPLE
|
||||
PS> ./enable-ipv6.ps1
|
||||
✔ IPv6 is enabled now.
|
||||
.LINK
|
||||
https://github.com/fleschutz/PowerShell
|
||||
.NOTES
|
||||
Author: Markus Fleschutz | License: CC0
|
||||
#>
|
||||
|
||||
try {
|
||||
Enable-NetAdapterBinding -Name '*' -ComponentID 'ms_tcpip6'
|
||||
"✔️ IPv6 is enabled now."
|
||||
exit 0 # success
|
||||
} catch {
|
||||
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
exit 1
|
||||
}
|
@ -7,7 +7,7 @@
|
||||
PS> ./export-to-manuals.ps1
|
||||
⏳ (1/2) Reading PowerShell scripts from /home/mf/PowerShell/Scripts/*.ps1 ...
|
||||
⏳ (2/2) Exporting Markdown manuals to /home/mf/PowerShell/Scripts/../Docs ...
|
||||
✔️ Exporting 518 Markdown manuals took 28 sec
|
||||
✔️ Exported 518 Markdown manuals in 28 sec
|
||||
.LINK
|
||||
https://github.com/fleschutz/PowerShell
|
||||
.NOTES
|
||||
@ -30,7 +30,7 @@ try {
|
||||
}
|
||||
|
||||
[int]$Elapsed = $StopWatch.Elapsed.TotalSeconds
|
||||
"✔️ Exporting $($Scripts.Count) Markdown manuals took $Elapsed sec"
|
||||
"✔️ Exported $($Scripts.Count) Markdown manuals in $Elapsed sec"
|
||||
exit 0 # success
|
||||
} catch {
|
||||
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
|
@ -1,6 +1,6 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Fetches repository updates
|
||||
Fetches Git repository updates
|
||||
.DESCRIPTION
|
||||
This PowerShell script fetches the latest updates into a local Git repository (including submodules).
|
||||
.PARAMETER RepoDir
|
||||
@ -8,9 +8,9 @@
|
||||
.EXAMPLE
|
||||
PS> ./fetch-repo.ps1 C:\MyRepo
|
||||
⏳ (1/3) Searching for Git executable... git version 2.41.0.windows.3
|
||||
⏳ (2/3) Checking local repository... 📂C:\MyRepo
|
||||
⏳ (2/3) Checking local repository...
|
||||
⏳ (3/3) Fetching updates...
|
||||
✔️ Fetching updates into repository 📂MyRepo took 2 sec
|
||||
✔️ Fetched updates into repo 📂MyRepo (took 2 sec)
|
||||
.LINK
|
||||
https://github.com/fleschutz/PowerShell
|
||||
.NOTES
|
||||
@ -26,7 +26,7 @@ try {
|
||||
& git --version
|
||||
if ($lastExitCode -ne "0") { throw "Can't execute 'git' - make sure Git is installed and available" }
|
||||
|
||||
Write-Host "⏳ (2/3) Checking local repository... 📂$RepoDir"
|
||||
Write-Host "⏳ (2/3) Checking local repository..."
|
||||
if (!(Test-Path "$RepoDir" -pathType container)) { throw "Can't access folder: $RepoDir" }
|
||||
$RepoDirName = (Get-Item "$RepoDir").Name
|
||||
|
||||
@ -35,7 +35,7 @@ try {
|
||||
if ($lastExitCode -ne "0") { throw "'git fetch --all' failed with exit code $lastExitCode" }
|
||||
|
||||
[int]$Elapsed = $StopWatch.Elapsed.TotalSeconds
|
||||
"✔️ Fetching updates into repository 📂$RepoDirName took $Elapsed sec"
|
||||
"✔️ Fetched updates into repo 📂$RepoDirName (took $Elapsed sec)"
|
||||
exit 0 # success
|
||||
} catch {
|
||||
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
|
@ -17,33 +17,34 @@
|
||||
Author: Markus Fleschutz | License: CC0
|
||||
#>
|
||||
|
||||
param([string]$ParentDir = "$PWD")
|
||||
param([string]$parentDirPath = "$PWD")
|
||||
|
||||
try {
|
||||
$StopWatch = [system.diagnostics.stopwatch]::startNew()
|
||||
$stopWatch = [system.diagnostics.stopwatch]::startNew()
|
||||
|
||||
Write-Host "⏳ (1) Searching for Git executable... " -noNewline
|
||||
Write-Host "⏳ (1) Searching for Git executable... " -noNewline
|
||||
& git --version
|
||||
if ($lastExitCode -ne "0") { throw "Can't execute 'git' - make sure Git is installed and available" }
|
||||
|
||||
Write-Host "⏳ (2) Checking parent folder... " -noNewline
|
||||
if (-not(Test-Path "$ParentDir" -pathType container)) { throw "Can't access folder: $ParentDir" }
|
||||
$Folders = (Get-ChildItem "$ParentDir" -attributes Directory)
|
||||
$NumFolders = $Folders.Count
|
||||
$ParentDirName = (Get-Item "$ParentDir").Name
|
||||
Write-Host "$NumFolders subfolders"
|
||||
Write-Host "⏳ (2) Checking parent folder... " -noNewline
|
||||
if (-not(Test-Path "$parentDirPath" -pathType container)) { throw "Can't access folder: $parentDirPath" }
|
||||
$folders = (Get-ChildItem "$parentDirPath" -attributes Directory)
|
||||
$numFolders = $folders.Count
|
||||
$parentDirPathName = (Get-Item "$parentDirPath").Name
|
||||
Write-Host "$numFolders subfolders"
|
||||
|
||||
[int]$Step = 2
|
||||
foreach ($Folder in $Folders) {
|
||||
$FolderName = (Get-Item "$Folder").Name
|
||||
$Step++
|
||||
Write-Host "⏳ ($Step/$($NumFolders + 2)) Fetching into 📂$FolderName... "
|
||||
[int]$step = 3
|
||||
foreach ($folder in $folders) {
|
||||
$folderName = (Get-Item "$folder").Name
|
||||
Write-Host "⏳ ($step/$($numFolders + 2)) Fetching into 📂$folderName... "
|
||||
|
||||
& git -C "$Folder" fetch --all --recurse-submodules --prune --prune-tags --force
|
||||
if ($lastExitCode -ne "0") { throw "'git fetch' in $Folder failed with exit code $lastExitCode" }
|
||||
& git -C "$folder" fetch --all --recurse-submodules --prune --prune-tags --force
|
||||
if ($lastExitCode -ne "0") { throw "'git fetch' in $folder failed with exit code $lastExitCode" }
|
||||
|
||||
$step++
|
||||
}
|
||||
[int]$Elapsed = $StopWatch.Elapsed.TotalSeconds
|
||||
"✔️ Fetching updates into $NumFolders repositories under 📂$ParentDirName took $Elapsed sec"
|
||||
[int]$elapsed = $stopWatch.Elapsed.TotalSeconds
|
||||
"✔️ Fetched updates into $numFolders repos under 📂$parentDirPathName in $elapsed sec"
|
||||
exit 0 # success
|
||||
} catch {
|
||||
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
|
@ -1,29 +0,0 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Installs the Chrome browser
|
||||
.DESCRIPTION
|
||||
This PowerShell script installs the latest Google Chrome Web browser.
|
||||
.EXAMPLE
|
||||
PS> ./install-chrome-browser.ps1
|
||||
.LINK
|
||||
https://github.com/fleschutz/PowerShell
|
||||
.NOTES
|
||||
Author: Markus Fleschutz | License: CC0
|
||||
#>
|
||||
|
||||
try {
|
||||
$StopWatch = [system.diagnostics.stopwatch]::startNew()
|
||||
|
||||
$Path = $env:TEMP;
|
||||
$Installer = "chrome_installer.exe"
|
||||
Invoke-WebRequest "http://dl.google.com/chrome/install/latest/chrome_installer.exe" -OutFile $Path\$Installer
|
||||
Start-Process -FilePath $Path\$Installer -Args "/silent /install" -Verb RunAs -Wait
|
||||
Remove-Item $Path\$Installer
|
||||
|
||||
[int]$Elapsed = $StopWatch.Elapsed.TotalSeconds
|
||||
"✔️ installed Google Chrome in $Elapsed sec"
|
||||
exit 0 # success
|
||||
} catch {
|
||||
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
exit 1
|
||||
}
|
0
Scripts/install-octoprint.ps1
Normal file → Executable file
0
Scripts/install-octoprint.ps1
Normal file → Executable file
@ -53,12 +53,12 @@ try {
|
||||
& sudo unbound-control status
|
||||
if ($lastExitCode -ne "0") { throw "'unbound-control status' failed" }
|
||||
|
||||
"⏳ (10/10) Training Unbound with 200 popular domain names..."
|
||||
"⏳ (10/10) Training Unbound with 100 popular domain names..."
|
||||
& "$PSScriptRoot/check-dns.ps1"
|
||||
if ($lastExitCode -ne "0") { throw "'unbound-control status' failed" }
|
||||
|
||||
[int]$Elapsed = $StopWatch.Elapsed.TotalSeconds
|
||||
"✔️ installed Unbound in $Elapsed sec"
|
||||
"✔️ Installed Unbound in $Elapsed sec"
|
||||
exit 0 # success
|
||||
} catch {
|
||||
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
|
@ -1,9 +1,9 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Installs updates
|
||||
Installs software updates
|
||||
.DESCRIPTION
|
||||
This PowerShell script installs software updates for the local machine (needs admin rights).
|
||||
Use the script 'list-updates.ps1' to list available updates.
|
||||
NOTE: Use the script 'list-updates.ps1' to list the latest software updates.
|
||||
.EXAMPLE
|
||||
PS> ./install-updates.ps1
|
||||
.LINK
|
||||
@ -27,14 +27,17 @@ try {
|
||||
|
||||
"⏳ (4/4) Upgrading installed Snap packages..."
|
||||
& sudo snap refresh
|
||||
} else {
|
||||
} elseif ($IsMacOS) {
|
||||
Write-Progress "⏳ Installing updates..."
|
||||
" "
|
||||
& winget upgrade --all
|
||||
& sudo softwareupdate -i -a
|
||||
Write-Progress -completed " "
|
||||
} else {
|
||||
Write-Progress "⏳ Installing updates from winget and Microsoft Store..."
|
||||
& winget upgrade --all --include-unknown
|
||||
Write-Progress -completed " "
|
||||
}
|
||||
[int]$Elapsed = $StopWatch.Elapsed.TotalSeconds
|
||||
"✅ installed the updates in $Elapsed sec"
|
||||
"✅ Installed updates in $Elapsed sec"
|
||||
exit 0 # success
|
||||
} catch {
|
||||
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
|
0
Scripts/list-ascii-table.ps1
Normal file → Executable file
0
Scripts/list-ascii-table.ps1
Normal file → Executable file
@ -61,6 +61,7 @@ function ListTools {
|
||||
ListTool arp ""
|
||||
ListTool at ""
|
||||
ListTool attrib ""
|
||||
ListTool auditpol ""
|
||||
ListTool awk "--version"
|
||||
ListTool b2sum "--version"
|
||||
ListTool base32 "--version"
|
||||
@ -69,7 +70,9 @@ function ListTools {
|
||||
ListTool basenc "--version"
|
||||
ListTool bash "--version"
|
||||
ListTool bc "--version"
|
||||
ListTool bcdboot ""
|
||||
ListTool bcdedit ""
|
||||
ListTool bitsadmin ""
|
||||
ListTool bunzip2 "--version"
|
||||
ListTool bzcat "--version"
|
||||
ListTool bzip2 "--version"
|
||||
@ -81,10 +84,14 @@ function ListTools {
|
||||
ListTool chcon "--version"
|
||||
ListTool chcpu "--version"
|
||||
ListTool chdsk ""
|
||||
ListTool chglogon ""
|
||||
ListTool chgport ""
|
||||
ListTool chgusr ""
|
||||
ListTool chgrp "--version"
|
||||
ListTool chmod "--version"
|
||||
ListTool chkntfs ""
|
||||
ListTool chmem "--version"
|
||||
ListTool choice "/?"
|
||||
ListTool chown "--version"
|
||||
ListTool chpasswd "--version"
|
||||
ListTool chroot "--version"
|
||||
@ -95,12 +102,14 @@ function ListTools {
|
||||
ListTool clear "-V"
|
||||
ListTool cmake "--version"
|
||||
ListTool cmd ""
|
||||
ListTool cmdkey "/list"
|
||||
ListTool cmp "--version"
|
||||
ListTool column "--version"
|
||||
ListTool comp ""
|
||||
ListTool compact ""
|
||||
ListTool cp "--version"
|
||||
ListTool cpack "--version"
|
||||
ListTool cscript ""
|
||||
ListTool csplit "--version"
|
||||
ListTool ctest "--version"
|
||||
ListTool curl "--version"
|
||||
@ -122,6 +131,7 @@ function ListTools {
|
||||
ListTool dism ""
|
||||
ListTool dmidecode "--version"
|
||||
ListTool dos2unix "--version"
|
||||
ListTool doskey "/?"
|
||||
ListTool dotnet "--info"
|
||||
ListTool driverquery ""
|
||||
ListTool du "--version"
|
||||
@ -129,6 +139,7 @@ function ListTools {
|
||||
ListTool egrep "--version"
|
||||
ListTool emacs "--version"
|
||||
ListTool env "--version"
|
||||
ListTool eventcreate "/?"
|
||||
ListTool ex "--version"
|
||||
ListTool expand "--version"
|
||||
ListTool expr "--version"
|
||||
@ -236,10 +247,12 @@ function ListTools {
|
||||
ListTool replace "--version"
|
||||
ListTool robocopy "--version"
|
||||
ListTool route ""
|
||||
ListTool rpcping ""
|
||||
ListTool rsh ""
|
||||
ListTool rsync "--version"
|
||||
ListTool rundll32 "--version"
|
||||
ListTool scp ""
|
||||
ListTool setx ""
|
||||
ListTool sftp ""
|
||||
ListTool sh "--version"
|
||||
ListTool sha1sum "--version"
|
||||
|
3
Scripts/list-coffee-prices.ps1
Normal file → Executable file
3
Scripts/list-coffee-prices.ps1
Normal file → Executable file
@ -33,7 +33,10 @@ function WriteHorizontalBar { param([float]$Value, [float]$Max)
|
||||
}
|
||||
|
||||
try {
|
||||
Write-Progress "⏳ Loading data from www.alphavantage.co..."
|
||||
$prices = (Invoke-WebRequest -URI "https://www.alphavantage.co/query?function=COFFEE&interval=monthly&apikey=demo" -userAgent "curl" -useBasicParsing).Content | ConvertFrom-Json
|
||||
Write-Progress -completed " "
|
||||
|
||||
""
|
||||
"$($prices.name) (by alphavantage.co, in $($prices.unit))"
|
||||
"---------------------------------------------------------------"
|
||||
|
26
Scripts/list-defender-settings.ps1
Executable file
26
Scripts/list-defender-settings.ps1
Executable file
@ -0,0 +1,26 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Lists the Windows Defender settings
|
||||
.DESCRIPTION
|
||||
This PowerShell script lists the current settings of Windows Defender Antivirus.
|
||||
NOTE: use 'Set-MpPreference' to change settings (e.g. DisableScanningNetworkFiles)
|
||||
.EXAMPLE
|
||||
PS> ./list-defender-settings.ps1
|
||||
|
||||
AttackSurfaceReductionOnlyExclusions :
|
||||
CheckForSignaturesBeforeRunningScan : False
|
||||
...
|
||||
.LINK
|
||||
https://github.com/fleschutz/PowerShell
|
||||
.NOTES
|
||||
Author: Markus Fleschutz | License: CC0
|
||||
#>
|
||||
|
||||
try {
|
||||
Get-MpPreference
|
||||
"NOTE: Documentation at: https://learn.microsoft.com/en-us/previous-versions/windows/desktop/legacy/dn455323(v=vs.85)"
|
||||
exit 0 # success
|
||||
} catch {
|
||||
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
exit 1
|
||||
}
|
@ -2,21 +2,24 @@
|
||||
.SYNOPSIS
|
||||
Lists a directory tree
|
||||
.DESCRIPTION
|
||||
This PowerShell script lists all files and folders in a directory tree.
|
||||
.PARAMETER DirTree
|
||||
This PowerShell script lists all files and folders in a neat directory tree (including icon and size).
|
||||
.PARAMETER Path
|
||||
Specifies the path to the directory tree
|
||||
.EXAMPLE
|
||||
PS> ./list-dir-tree.ps1 C:\
|
||||
PS> ./list-dir-tree.ps1 C:\MyFolder
|
||||
├📂Results
|
||||
│ ├📄sales.txt (442K)
|
||||
(2 folders, 1 file, 442K total)
|
||||
.LINK
|
||||
https://github.com/fleschutz/PowerShell
|
||||
.NOTES
|
||||
Author: Markus Fleschutz | License: CC0
|
||||
#>
|
||||
|
||||
param([string]$DirTree = "$PWD")
|
||||
param([string]$Path = "$PWD")
|
||||
|
||||
function GetFileIcon { param([string]$Suffix)
|
||||
switch ($Suffix) {
|
||||
function GetFileIcon([string]$suffix) {
|
||||
switch ($suffix) {
|
||||
".csv" {return "📊"}
|
||||
".epub" {return "📓"}
|
||||
".exe" {return "⚙️"}
|
||||
@ -30,32 +33,43 @@ function GetFileIcon { param([string]$Suffix)
|
||||
}
|
||||
}
|
||||
|
||||
function ListDir { param([string]$Directory, [int]$Depth)
|
||||
$Depth++
|
||||
$Items = Get-ChildItem -path $Directory
|
||||
foreach($Item in $Items) {
|
||||
$Filename = $Item.Name
|
||||
for ($i = 1; $i -lt $Depth; $i++) { Write-Host "│ " -noNewline }
|
||||
if ($Item.Mode -like "d*") {
|
||||
Write-Host "├" -noNewline
|
||||
Write-Host -foregroundColor green "📂$Filename"
|
||||
ListDir "$Directory\$Filename" $Depth
|
||||
$global:Dirs++
|
||||
function Bytes2String([int64]$bytes) {
|
||||
if ($bytes -lt 1000) { return "$bytes bytes" }
|
||||
$bytes /= 1000
|
||||
if ($bytes -lt 1000) { return "$($bytes)K" }
|
||||
$bytes /= 1000
|
||||
if ($bytes -lt 1000) { return "$($bytes)MB" }
|
||||
$bytes /= 1000
|
||||
if ($bytes -lt 1000) { return "$($bytes)GB" }
|
||||
$bytes /= 1000
|
||||
return "$($Bytes)TB"
|
||||
}
|
||||
|
||||
function ListDirectory([string]$path, [int]$depth) {
|
||||
$depth++
|
||||
$items = Get-ChildItem -path $path
|
||||
foreach($item in $items) {
|
||||
$filename = $item.Name
|
||||
for ($i = 1; $i -lt $depth; $i++) { Write-Host "│ " -noNewline }
|
||||
if ($item.Mode -like "d*") {
|
||||
Write-Output "├📂$Filename"
|
||||
ListDirectory "$path\$filename" $depth
|
||||
$global:folders++
|
||||
} else {
|
||||
$Icon = GetFileIcon $Item.Extension
|
||||
Write-Host "├$($Icon)$Filename ($($Item.Length) bytes)"
|
||||
$global:Files++
|
||||
$global:Bytes += $Item.Length
|
||||
$icon = GetFileIcon $item.Extension
|
||||
Write-Output "├$($icon)$filename ($(Bytes2String $item.Length))"
|
||||
$global:files++
|
||||
$global:bytes += $item.Length
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
[int]$global:Dirs = 1
|
||||
[int]$global:Files = 0
|
||||
[int]$global:Bytes = 0
|
||||
ListDir $DirTree 0
|
||||
" ($($global:Dirs) folders, $($global:Files) files, $($global:Bytes) bytes in total)"
|
||||
[int]$global:folders = 1
|
||||
[int]$global:files = 0
|
||||
[int]$global:bytes = 0
|
||||
ListDirectory $Path 0
|
||||
Write-Output " ($($global:folders) folders, $($global:files) files, $(Bytes2String $global:bytes) total)"
|
||||
exit 0 # success
|
||||
} catch {
|
||||
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
|
25
Scripts/list-ipv6.ps1
Executable file
25
Scripts/list-ipv6.ps1
Executable file
@ -0,0 +1,25 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Lists IPv6 states
|
||||
.DESCRIPTION
|
||||
This PowerShell script lists the state of IPv6 on all network interfaces of the local computer.
|
||||
.EXAMPLE
|
||||
PS> ./list-ipv6.ps1
|
||||
Name Enabled
|
||||
---- -------
|
||||
Ethernet True
|
||||
vEthernet (WSL) True
|
||||
Bluetooth Network Connection True
|
||||
.LINK
|
||||
https://github.com/fleschutz/PowerShell
|
||||
.NOTES
|
||||
Author: Markus Fleschutz | License: CC0
|
||||
#>
|
||||
|
||||
try {
|
||||
Get-NetAdapterBinding -name '*' -componentID 'ms_tcpip6' | Format-Table -autoSize -property Name,Enabled
|
||||
exit 0 # success
|
||||
} catch {
|
||||
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
exit 1
|
||||
}
|
0
Scripts/list-power-schemes.ps1
Normal file → Executable file
0
Scripts/list-power-schemes.ps1
Normal file → Executable file
@ -17,6 +17,7 @@ try {
|
||||
} else {
|
||||
$ComputerName = $(hostname)
|
||||
Get-WMIObject -Class Win32_Printer -ComputerName $ComputerName | Format-Table
|
||||
"(PrinterStatus: 1=various 2=unknown 3=idle 4=printing 5=warmup 6=finished 7=offline)"
|
||||
}
|
||||
exit 0 # success
|
||||
} catch {
|
||||
|
33
Scripts/list-public-ip.ps1
Executable file
33
Scripts/list-public-ip.ps1
Executable file
@ -0,0 +1,33 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Lists the public IP address(es)
|
||||
.DESCRIPTION
|
||||
This PowerShell script queries the public IP address(es) and prints it.
|
||||
.EXAMPLE
|
||||
PS> ./list-public-ip.ps1
|
||||
✅ Public IP address 185.72.209.161, 2003:f2:6128:fc01:e503:601:30c2:a028 near Munich
|
||||
.LINK
|
||||
https://github.com/fleschutz/PowerShell
|
||||
.NOTES
|
||||
Author: Markus Fleschutz | License: CC0
|
||||
#>
|
||||
|
||||
try {
|
||||
if ($IsLinux) {
|
||||
$publicIPv4 = (curl -4 --silent ifconfig.co)
|
||||
$publicIPv6 = (curl -6 --silent ifconfig.co)
|
||||
$city = (curl --silent ifconfig.co/city)
|
||||
} else {
|
||||
$publicIPv4 = (curl.exe -4 --silent ifconfig.co)
|
||||
$publicIPv6 = (curl.exe -6 --silent ifconfig.co)
|
||||
$city = (curl.exe --silent ifconfig.co/city)
|
||||
}
|
||||
if ("$publicIPv4" -eq "") { $publicIPv4 = "no IPv4" }
|
||||
if ("$publicIPv6" -eq "") { $publicIPv6 = "no IPv6" }
|
||||
if ("$city" -eq "") { $city = "unknown" }
|
||||
Write-Output "✅ Public IP address $publicIPv4, $publicIPv6 near $City"
|
||||
exit 0 # success
|
||||
} catch {
|
||||
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
exit 1
|
||||
}
|
42
Scripts/list-pull-requests.ps1
Normal file
42
Scripts/list-pull-requests.ps1
Normal file
@ -0,0 +1,42 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Lists all pull requests
|
||||
.DESCRIPTION
|
||||
This PowerShell script lists all pull requests for a Git repository.
|
||||
.PARAMETER RepoDir
|
||||
Specifies the file path to the local Git repository (default is working directory).
|
||||
.EXAMPLE
|
||||
PS> ./list-pull-requests.ps1 C:\MyRepo
|
||||
.LINK
|
||||
https://github.com/fleschutz/PowerShell
|
||||
.NOTES
|
||||
Author: Markus Fleschutz | License: CC0
|
||||
#>
|
||||
|
||||
param([string]$RepoDir = "$PWD")
|
||||
|
||||
try {
|
||||
Write-Progress "⏳ (1/3) Searching for Git executable... "
|
||||
$null = (git --version)
|
||||
if ($lastExitCode -ne "0") { throw "Can't execute 'git' - make sure Git is installed and available" }
|
||||
|
||||
Write-Progress "⏳ (2/3) Checking local repository..."
|
||||
if (!(Test-Path "$RepoDir" -pathType container)) { throw "Can't access folder: $RepoDir" }
|
||||
$RepoDirName = (Get-Item "$RepoDir").Name
|
||||
|
||||
Write-Progress "⏳ (3/3) Fetching latest updates..."
|
||||
& git -C "$RepoDir" fetch --all --force --quiet
|
||||
if ($lastExitCode -ne "0") { throw "'git fetch --all' failed with exit code $lastExitCode" }
|
||||
Write-Progress -completed " "
|
||||
|
||||
" "
|
||||
"Commit ID Reference"
|
||||
"--------- ---------"
|
||||
& git -C "$RepoDir" ls-remote origin 'pull/*/head'
|
||||
if ($lastExitCode -ne "0") { throw "'git ls-remote' failed with exit code $lastExitCode" }
|
||||
Write-Progress -completed " "
|
||||
exit 0 # success
|
||||
} catch {
|
||||
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
exit 1
|
||||
}
|
@ -8,9 +8,9 @@
|
||||
.EXAMPLE
|
||||
PS> ./list-repos C:\MyRepos
|
||||
|
||||
Repository Latest Tag Branch Updates Status
|
||||
---------- ---------- ------ ------- ------
|
||||
📂cmake v3.23.0 main ↓0 ✔️clean
|
||||
Repository Latest Tag Branch Status Remote
|
||||
---------- ---------- ------ ------ ------
|
||||
📂cmake v3.23.0 main ✔️clean git@github.com:Kitware/CMake ↓0
|
||||
...
|
||||
.LINK
|
||||
https://github.com/fleschutz/PowerShell
|
||||
@ -31,11 +31,12 @@ function ListRepos {
|
||||
$LatestTag = ""
|
||||
}
|
||||
$Branch = (git -C "$Folder" branch --show-current)
|
||||
$RemoteURL = (git -C "$Folder" remote get-url origin)
|
||||
$NumCommits = (git -C "$Folder" rev-list HEAD...origin/$Branch --count)
|
||||
$Status = (git -C "$Folder" status --short)
|
||||
if ("$Status" -eq "") { $Status = "✔️clean" }
|
||||
elseif ("$Status" -like " M *") { $Status = "⚠️modified" }
|
||||
New-Object PSObject -property @{'Repository'="📂$Repository";'Latest Tag'="$LatestTag";'Branch'="$Branch";'Updates'="↓$NumCommits";'Status'="$Status";}
|
||||
New-Object PSObject -property @{'Repository'="📂$Repository";'Latest Tag'="$LatestTag";'Branch'="$Branch";'Status'="$Status";'Remote'="$RemoteURL ↓$NumCommits";}
|
||||
}
|
||||
}
|
||||
|
||||
@ -45,7 +46,7 @@ try {
|
||||
$Null = (git --version)
|
||||
if ($lastExitCode -ne "0") { throw "Can't execute 'git' - make sure Git is installed and available" }
|
||||
|
||||
ListRepos | Format-Table -property @{e='Repository';width=20},@{e='Latest Tag';width=18},@{e='Branch';width=20},@{e='Updates';width=8},Status
|
||||
ListRepos | Format-Table -property @{e='Repository';width=20},@{e='Latest Tag';width=18},@{e='Branch';width=20},@{e='Status';width=10},Remote
|
||||
exit 0 # success
|
||||
} catch {
|
||||
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
|
@ -1,33 +1,49 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Lists all PowerShell scripts
|
||||
Lists the PowerShell scripts
|
||||
.DESCRIPTION
|
||||
This PowerShell script lists all PowerShell scripts in the repository (sorted alphabetically).
|
||||
This PowerShell script lists the Mega collection of PowerShell scripts (sorted alphabetically and optionally by category).
|
||||
.PARAM category
|
||||
Specifies the desired category: audio, desktop, filesystem, fun, git, misc, or: * (default)
|
||||
.EXAMPLE
|
||||
PS> ./list-scripts.ps1
|
||||
|
||||
No Script Category Description
|
||||
-- ------ -------- -----------
|
||||
1 add-firewall-rules.ps1 misc Adds firewall rules for executables (needs admin rights)
|
||||
...
|
||||
.LINK
|
||||
https://github.com/fleschutz/PowerShell
|
||||
.NOTES
|
||||
Author: Markus Fleschutz | License: CC0
|
||||
#>
|
||||
|
||||
function ListScripts { param([string]$FilePath)
|
||||
Write-Progress "Reading $FilePath..."
|
||||
$table = Import-CSV "$FilePath"
|
||||
param([string]$category = "*")
|
||||
|
||||
function ListScripts([string]$category) {
|
||||
Write-Progress "Loading data from ../Data/script.csv..."
|
||||
$table = Import-CSV "$PSScriptRoot/../Data/scripts.csv"
|
||||
[int]$No = 1
|
||||
foreach($row in $table) {
|
||||
New-Object PSObject -Property @{
|
||||
'No' = $No++
|
||||
'Script' = $row.SCRIPT
|
||||
'Description' = $row.DESCRIPTION
|
||||
if ($row.CATEGORY -like $category) {
|
||||
New-Object PSObject -Property @{
|
||||
'No' = $No++
|
||||
'Script' = $row.SCRIPT
|
||||
'Category' = $row.CATEGORY
|
||||
'Description' = $row.DESCRIPTION
|
||||
}
|
||||
}
|
||||
}
|
||||
$global:NumScripts = $Table.Count
|
||||
Write-Progress -completed "."
|
||||
Write-Progress -completed " "
|
||||
}
|
||||
|
||||
try {
|
||||
ListScripts "$PSScriptRoot/../Data/scripts.csv" | Format-Table -property No,Script,Description
|
||||
ListScripts $category | Format-Table -property No,Script,Category,Description
|
||||
# $files = Get-ChildItem -path "./*.ps1" -attributes !Directory
|
||||
# foreach ($file in $files) {
|
||||
# $help = Get-Help $file -full
|
||||
# Write-Output "$($file.Name), ,`"$($help.Synopsis)`","
|
||||
# }
|
||||
exit 0 # success
|
||||
} catch {
|
||||
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
|
@ -2,7 +2,7 @@
|
||||
.SYNOPSIS
|
||||
Lists all tags in a repository
|
||||
.DESCRIPTION
|
||||
This PowerShell script fetches and lists all tags in a Git repository.
|
||||
This PowerShell script fetches all tags of a Git repository and lists it.
|
||||
.PARAMETER RepoDir
|
||||
Specifies the path to the Git repository (current working directory by default)
|
||||
.PARAMETER SearchPattern
|
||||
@ -23,18 +23,22 @@
|
||||
param([string]$RepoDir = "$PWD", [string]$SearchPattern="*")
|
||||
|
||||
try {
|
||||
Write-Progress "⏳ (1/3) Searching for Git executable... "
|
||||
Write-Progress "⏳ (1/4) Searching for Git executable... "
|
||||
$Null = (git --version)
|
||||
if ($lastExitCode -ne "0") { throw "Can't execute 'git' - make sure Git is installed and available" }
|
||||
|
||||
Write-Progress "⏳ (2/3) Checking local repository... "
|
||||
Write-Progress "⏳ (2/4) Checking local repository... "
|
||||
if (-not(Test-Path "$RepoDir" -pathType container)) { throw "Can't access directory: $RepoDir" }
|
||||
|
||||
Write-Progress "⏳ (3/3) Fetching remote tags..."
|
||||
Write-Progress "⏳ (3/4) Fetching newer tags from remote..."
|
||||
& git -C "$RepoDir" fetch --all --tags
|
||||
Write-Progress -completed "Done."
|
||||
if ($lastExitCode -ne "0") { throw "'git fetch --all --tags' failed" }
|
||||
|
||||
Write-Progress "⏳ (4/4) Removing obsolete local tags..."
|
||||
& git -C "$RepoDir" fetch --prune --prune-tags
|
||||
if ($lastExitCode -ne "0") { throw "'git fetch --prune --prune-tags' failed" }
|
||||
|
||||
Write-Progress -completed "Done."
|
||||
""
|
||||
"Tag Description"
|
||||
"--- -----------"
|
||||
|
@ -1,9 +1,9 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Lists new software updates
|
||||
Lists software updates
|
||||
.DESCRIPTION
|
||||
This PowerShell script queries and lists available software updates for the local machine.
|
||||
Use 'install-updates.ps1' to install the listed updates.
|
||||
This PowerShell script queries the latest available software updates for the local machine and lists it.
|
||||
NOTE: Use the script 'install-updates.ps1' to install the listed updates.
|
||||
.EXAMPLE
|
||||
PS> ./list-updates.ps1
|
||||
|
||||
@ -25,12 +25,12 @@ try {
|
||||
"⏳ (2/2) Querying Snap updates..."
|
||||
& sudo snap refresh --list
|
||||
} else {
|
||||
Write-Progress "⏳ Querying the latest updates from winget and Microsoft Store..."
|
||||
" "
|
||||
Write-Progress "⏳ Querying new software updates..."
|
||||
& winget upgrade
|
||||
Write-Progress -completed "."
|
||||
& winget upgrade --include-unknown
|
||||
Write-Progress -completed " "
|
||||
}
|
||||
"(use 'install-updates.ps1' to install the listed updates)"
|
||||
" (use 'install-updates.ps1' to install the listed updates)"
|
||||
exit 0 # success
|
||||
} catch {
|
||||
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
|
4
Scripts/list-wsl-distros.ps1
Executable file
4
Scripts/list-wsl-distros.ps1
Executable file
@ -0,0 +1,4 @@
|
||||
& wsl.exe --list --online
|
||||
" "
|
||||
& wsl.exe --status
|
||||
exit 0 # success
|
27
Scripts/measure-BubbleSort.ps1
Normal file → Executable file
27
Scripts/measure-BubbleSort.ps1
Normal file → Executable file
@ -1,4 +1,24 @@
|
||||
param([int]$numIntegers = 1000)
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Measures the speed of BubbleSort
|
||||
.DESCRIPTION
|
||||
This PowerShell script measures the speed of the BubbleSort algorithm.
|
||||
BubbleSort is a simple sorting algorithm that repeatedly steps through the list,
|
||||
compares adjacent elements and swaps them if they are in the wrong order. The pass
|
||||
through the list is repeated until the list is sorted. The algorithm, which is a
|
||||
comparison sort, is named for the way smaller or larger elements "bubble" to the top of the list.
|
||||
.PARAMETER numIntegers
|
||||
Specifies the number of integers to sort
|
||||
.EXAMPLE
|
||||
PS> ./measure-BubbleSort.ps1
|
||||
🧭 0.729 sec to sort 1000 integers by BubbleSort
|
||||
.LINK
|
||||
https://github.com/fleschutz/PowerShell
|
||||
.NOTES
|
||||
Author: Markus Fleschutz | License: CC0
|
||||
#>
|
||||
|
||||
param([int]$numIntegers = 1000)
|
||||
|
||||
class BubbleSort {
|
||||
static Sort($targetList) {
|
||||
@ -20,5 +40,6 @@ $list = (1..$NumIntegers | foreach{Get-Random -minimum 1 -maximum $numIntegers})
|
||||
$stopWatch = [system.diagnostics.stopwatch]::startNew()
|
||||
[BubbleSort]::Sort($list)
|
||||
[float]$elapsed = $stopWatch.Elapsed.TotalSeconds
|
||||
"🕒 BubbleSort of $numIntegers integers took $elapsed sec"
|
||||
exit 0 # success
|
||||
$elapsed3 = "{0:N3}" -f $elapsed # formatted to 3 decimal places
|
||||
"🧭 $elapsed3 sec to sort $numIntegers integers by BubbleSort"
|
||||
exit 0 # success
|
||||
|
33
Scripts/measure-BucketSort.ps1
Normal file → Executable file
33
Scripts/measure-BucketSort.ps1
Normal file → Executable file
@ -1,4 +1,29 @@
|
||||
param([int]$numIntegers = 1000)
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Measures the speed of BucketSort
|
||||
.DESCRIPTION
|
||||
This PowerShell script measures the speed of the BucketSort algorithm.
|
||||
BucketSort is a sorting algorithm that works by distributing the elements
|
||||
of an array into a number of buckets. Each bucket is then sorted individually,
|
||||
either using a different sorting algorithm, or by recursively applying the bucket
|
||||
sorting algorithm. It is a distribution sort, a generalization of pigeonhole sort
|
||||
that allows multiple keys per bucket, and is a cousin of radix sort in the
|
||||
most-to-least significant digit flavor. Bucket sort can be implemented with comparisons
|
||||
and therefore can also be considered a comparison sort algorithm. The computational
|
||||
complexity depends on the algorithm used to sort each bucket, the number of buckets
|
||||
to use, and whether the input is uniformly distributed.
|
||||
.PARAMETER numIntegers
|
||||
Specifies the number of integers to sort
|
||||
.EXAMPLE
|
||||
PS> ./measure-BucketSort.ps1
|
||||
🧭 0.065 sec to sort 1000 integers by BucketSort
|
||||
.LINK
|
||||
https://github.com/fleschutz/PowerShell
|
||||
.NOTES
|
||||
Author: Markus Fleschutz | License: CC0
|
||||
#>
|
||||
|
||||
param([int]$numIntegers = 1000)
|
||||
|
||||
class BucketSort {
|
||||
static Sort($targetList) {
|
||||
@ -31,7 +56,6 @@ class BucketSort {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -39,5 +63,6 @@ $list = (1..$numIntegers | foreach{Get-Random -minimum 1 -maximum $numIntegers})
|
||||
$stopWatch = [system.diagnostics.stopwatch]::startNew()
|
||||
[BucketSort]::Sort($list)
|
||||
[float]$elapsed = $stopWatch.Elapsed.TotalSeconds
|
||||
"🕒 BucketSort of $numIntegers integers took $elapsed sec"
|
||||
exit 0 # success
|
||||
$elapsed3 = "{0:N3}" -f $elapsed # formatted to 3 decimal places
|
||||
"🧭 $elapsed3 sec to sort $numIntegers integers by BucketSort"
|
||||
exit 0 # success
|
||||
|
32
Scripts/measure-CountingSort.ps1
Normal file → Executable file
32
Scripts/measure-CountingSort.ps1
Normal file → Executable file
@ -1,4 +1,29 @@
|
||||
param([int]$numIntegers = 1000)
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Measures the speed of CountingSort
|
||||
.DESCRIPTION
|
||||
This PowerShell script measures the speed of the CountingSort algorithm.
|
||||
CountingSort is an algorithm for sorting a collection of objects according to keys
|
||||
that are small positive integers; that is, it is an integer sorting algorithm. It
|
||||
operates by counting the number of objects that possess distinct key values, and
|
||||
applying prefix sum on those counts to determine the positions of each key value in
|
||||
the output sequence. Its running time is linear in the number of items and the difference
|
||||
between the maximum key value and the minimum key value, so it is only suitable for direct
|
||||
use in situations where the variation in keys is not significantly greater than the number
|
||||
of items. It is often used as a subroutine in radix sort, another sorting algorithm, which
|
||||
can handle larger keys more efficiently.
|
||||
.PARAMETER numIntegers
|
||||
Specifies the number of integers to sort
|
||||
.EXAMPLE
|
||||
PS> ./measure-CountingSort.ps1
|
||||
🧭 0.045 sec to sort 1000 integers by CountingSort
|
||||
.LINK
|
||||
https://github.com/fleschutz/PowerShell
|
||||
.NOTES
|
||||
Author: Markus Fleschutz | License: CC0
|
||||
#>
|
||||
|
||||
param([int]$numIntegers = 1000)
|
||||
|
||||
class CountingSort {
|
||||
static Sort($targetList) {
|
||||
@ -29,5 +54,6 @@ $list = (1..$numIntegers | foreach{Get-Random -minimum 1 -maximum $numIntegers})
|
||||
$stopWatch = [system.diagnostics.stopwatch]::startNew()
|
||||
[CountingSort]::Sort($list)
|
||||
[float]$elapsed = $stopWatch.Elapsed.TotalSeconds
|
||||
"🕒 CountingSort of $numIntegers integers took $elapsed sec"
|
||||
exit 0 # success
|
||||
$elapsed3 = "{0:N3}" -f $elapsed # formatted to 3 decimal places
|
||||
"🧭 $elapsed3 sec to sort $numIntegers integers by CountingSort"
|
||||
exit 0 # success
|
||||
|
30
Scripts/measure-HeapSort.ps1
Normal file → Executable file
30
Scripts/measure-HeapSort.ps1
Normal file → Executable file
@ -1,4 +1,27 @@
|
||||
param([int]$numIntegers = 1000)
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Measures the speed of HeapSort
|
||||
.DESCRIPTION
|
||||
This PowerShell script measures the speed of the HeapSort algorithm.
|
||||
HeapSort is a comparison-based sorting algorithm. Heapsort can be thought of as an
|
||||
improved selection sort: like selection sort, heapsort divides its input into a sorted
|
||||
and an unsorted region, and it iteratively shrinks the unsorted region by extracting
|
||||
the largest element from it and inserting it into the sorted region. Unlike selection
|
||||
sort, heapsort does not waste time with a linear-time scan of the unsorted region;
|
||||
rather, heap sort maintains the unsorted region in a heap data structure to more quickly
|
||||
find the largest element in each step.
|
||||
.PARAMETER numIntegers
|
||||
Specifies the number of integers to sort
|
||||
.EXAMPLE
|
||||
PS> ./measure-HeapSort.ps1
|
||||
🧭 0.614 sec to sort 1000 integers by HeapSort
|
||||
.LINK
|
||||
https://github.com/fleschutz/PowerShell
|
||||
.NOTES
|
||||
Author: Markus Fleschutz | License: CC0
|
||||
#>
|
||||
|
||||
param([int]$numIntegers = 1000)
|
||||
|
||||
class HeapSort {
|
||||
static Sort($targetList) {
|
||||
@ -48,5 +71,6 @@ $list = (1..$numIntegers | foreach{Get-Random -minimum 1 -maximum $numIntegers})
|
||||
$stopWatch = [system.diagnostics.stopwatch]::startNew()
|
||||
[HeapSort]::Sort($list)
|
||||
[float]$elapsed = $stopWatch.Elapsed.TotalSeconds
|
||||
"🕒 HeapSort of $numIntegers integers took $elapsed sec"
|
||||
exit 0 # success
|
||||
$elapsed3 = "{0:N3}" -f $elapsed # formatted to 3 decimal places
|
||||
"🧭 $elapsed3 sec to sort $numIntegers integers by HeapSort"
|
||||
exit 0 # success
|
||||
|
26
Scripts/measure-InsertionSort.ps1
Normal file → Executable file
26
Scripts/measure-InsertionSort.ps1
Normal file → Executable file
@ -1,4 +1,23 @@
|
||||
param([int]$numIntegers = 1000)
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Measures the speed of InsertionSort
|
||||
.DESCRIPTION
|
||||
This PowerShell script measures the speed of the InsertionSort algorithm.
|
||||
InsertionSort is a simple sorting algorithm that builds the final sorted array (or list)
|
||||
one item at a time. It is much less efficient on large lists than more advanced algorithms
|
||||
such as quicksort, heapsort, or merge sort.
|
||||
.PARAMETER numIntegers
|
||||
Specifies the number of integers to sort
|
||||
.EXAMPLE
|
||||
PS> ./measure-InsertionSort.ps1
|
||||
🧭 0.423 sec to sort 1000 integers by InsertionSort
|
||||
.LINK
|
||||
https://github.com/fleschutz/PowerShell
|
||||
.NOTES
|
||||
Author: Markus Fleschutz | License: CC0
|
||||
#>
|
||||
|
||||
param([int]$numIntegers = 1000)
|
||||
|
||||
class InsertionSort {
|
||||
static Sort($targetList) {
|
||||
@ -25,5 +44,6 @@ $list = (1..$numIntegers | foreach{Get-Random -minimum 1 -maximum $numIntegers})
|
||||
$stopWatch = [system.diagnostics.stopwatch]::startNew()
|
||||
[InsertionSort]::Sort($list)
|
||||
[float]$elapsed = $stopWatch.Elapsed.TotalSeconds
|
||||
"🕒 InsertionSort of $numIntegers integers took $elapsed sec"
|
||||
exit 0 # success
|
||||
$elapsed3 = "{0:N3}" -f $elapsed # formatted to 3 decimal places
|
||||
"🧭 $elapsed3 sec to sort $numIntegers integers by InsertionSort"
|
||||
exit 0 # success
|
||||
|
26
Scripts/measure-MergeSort.ps1
Normal file → Executable file
26
Scripts/measure-MergeSort.ps1
Normal file → Executable file
@ -1,4 +1,25 @@
|
||||
param([int]$numIntegers = 1000)
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Measures the speed of MergeSort
|
||||
.DESCRIPTION
|
||||
This PowerShell script measures the speed of the MergeSort algorithm.
|
||||
MergeSort is an efficient, general-purpose, and comparison-based sorting algorithm.
|
||||
Most implementations produce a stable sort, which means that the order of equal elements
|
||||
is the same in the input and output. Merge sort is a divide-and-conquer algorithm that
|
||||
was invented by John von Neumann in 1945. A detailed description and analysis of bottom-up
|
||||
merge sort appeared in a report by Goldstine and von Neumann as early as 1948.
|
||||
.PARAMETER numIntegers
|
||||
Specifies the number of integers to sort
|
||||
.EXAMPLE
|
||||
PS> ./measure-MergeSort.ps1
|
||||
🧭 0.378 sec to sorting 1000 integers by MergeSort
|
||||
.LINK
|
||||
https://github.com/fleschutz/PowerShell
|
||||
.NOTES
|
||||
Author: Markus Fleschutz | License: CC0
|
||||
#>
|
||||
|
||||
param([int]$numIntegers = 1000)
|
||||
|
||||
class MergeSort {
|
||||
|
||||
@ -46,5 +67,6 @@ $list = (1..$numIntegers | foreach{Get-Random -minimum 1 -maximum $numIntegers})
|
||||
$stopWatch = [system.diagnostics.stopwatch]::startNew()
|
||||
[MergeSort]::Sort($list)
|
||||
[float]$elapsed = $stopWatch.Elapsed.TotalSeconds
|
||||
"🕒 MergeSort of $numIntegers integers took $elapsed sec"
|
||||
$elapsed3 = "{0:N3}" -f $elapsed # formatted to 3 decimal places
|
||||
"🧭 $elapsed3 sec to sort $numIntegers integers by MergeSort"
|
||||
exit 0 # success
|
||||
|
27
Scripts/measure-QuickSort.ps1
Normal file → Executable file
27
Scripts/measure-QuickSort.ps1
Normal file → Executable file
@ -1,4 +1,24 @@
|
||||
param([int]$numIntegers = 1000)
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Measures the speed of QuickSort
|
||||
.DESCRIPTION
|
||||
This PowerShell script measures the speed of the QuickSort algorithm.
|
||||
QuickSort is an in-place sorting algorithm. Developed by British computer scientist
|
||||
Tony Hoare in 1959 and published in 1961, it is still a commonly used algorithm for
|
||||
sorting. When implemented well, it can be somewhat faster than merge sort and about
|
||||
two or three times faster than heapsort.
|
||||
.PARAMETER numIntegers
|
||||
Specifies the number of integers to sort
|
||||
.EXAMPLE
|
||||
PS> ./measure-QuickSort.ps1
|
||||
🧭 0.085 sec to sort 1000 integers by QuickSort
|
||||
.LINK
|
||||
https://github.com/fleschutz/PowerShell
|
||||
.NOTES
|
||||
Author: Markus Fleschutz | License: CC0
|
||||
#>
|
||||
|
||||
param([int]$numIntegers = 1000)
|
||||
|
||||
class QuickSort {
|
||||
static Sort($targetList, $left, $right) {
|
||||
@ -29,5 +49,6 @@ $list = (1..$numIntegers | foreach{Get-Random -minimum 1 -maximum $numIntegers})
|
||||
$stopWatch = [system.diagnostics.stopwatch]::startNew()
|
||||
[QuickSort]::Sort($list, 0, $list.Count-1)
|
||||
[float]$elapsed = $stopWatch.Elapsed.TotalSeconds
|
||||
"🕒 QuickSort of $numIntegers integers took $elapsed sec"
|
||||
exit 0 # success
|
||||
$elapsed3 = "{0:N3}" -f $elapsed # formatted to 3 decimal places
|
||||
"🧭 $elapsed3 sec to sort $numIntegers integers by QuickSort"
|
||||
exit 0 # success
|
||||
|
30
Scripts/measure-SelectionSort.ps1
Normal file → Executable file
30
Scripts/measure-SelectionSort.ps1
Normal file → Executable file
@ -1,4 +1,27 @@
|
||||
class SelectionSort {
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Measures the speed of SelectionSort
|
||||
.DESCRIPTION
|
||||
This PowerShell script measures the speed of the SelectionSort algorithm.
|
||||
SelectionSort is an in-place comparison sorting algorithm. It has an O(n2) time complexity,
|
||||
which makes it inefficient on large lists, and generally performs worse than the similar
|
||||
insertion sort. Selection sort is noted for its simplicity and has performance advantages
|
||||
over more complicated algorithms in certain situations, particularly where auxiliary memory
|
||||
is limited.
|
||||
.PARAMETER numIntegers
|
||||
Specifies the number of integers to sort
|
||||
.EXAMPLE
|
||||
PS> ./measure-SelectionSort.ps1
|
||||
🧭 0.335 sec to sort 1000 integers by SelectionSort
|
||||
.LINK
|
||||
https://github.com/fleschutz/PowerShell
|
||||
.NOTES
|
||||
Author: Markus Fleschutz | License: CC0
|
||||
#>
|
||||
|
||||
param([int]$numIntegers = 1000)
|
||||
|
||||
class SelectionSort {
|
||||
static Sort($targetList) {
|
||||
$n = $targetList.count
|
||||
|
||||
@ -18,5 +41,6 @@ $list = (1..$numIntegers | foreach{Get-Random -minimum 1 -maximum $numIntegers})
|
||||
$stopWatch = [system.diagnostics.stopwatch]::startNew()
|
||||
[SelectionSort]::Sort($list)
|
||||
[float]$elapsed = $stopWatch.Elapsed.TotalSeconds
|
||||
"🕒 SelectionSort of $numIntegers integers took $elapsed sec"
|
||||
exit 0 # success
|
||||
$elapsed3 = "{0:N3}" -f $elapsed # formatted to 3 decimal places
|
||||
"🧭 $elapsed3 sec to sort $numIntegers integers by SelectionSort"
|
||||
exit 0 # success
|
||||
|
5
Scripts/measure-sorting-algorithms.ps1
Normal file → Executable file
5
Scripts/measure-sorting-algorithms.ps1
Normal file → Executable file
@ -1,13 +1,13 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Measure sorting algorithms
|
||||
Measures the speed of sorting algorithms
|
||||
.DESCRIPTION
|
||||
This PowerShell script measures the speed of several sorting algorithms and prints it.
|
||||
.PARAMETER numIntegers
|
||||
Specifies the number of integers to sort (3000 by default)
|
||||
.EXAMPLE
|
||||
PS> ./measure-sorting-algorithms.ps1
|
||||
🕒 BubbleSort of 3000 integers took 6.041561 sec
|
||||
🧭 6.041 sec to sort 3000 integers by BubbleSort
|
||||
...
|
||||
.LINK
|
||||
https://github.com/fleschutz/PowerShell
|
||||
@ -16,6 +16,7 @@
|
||||
#>
|
||||
|
||||
param([int]$numIntegers = 3000)
|
||||
|
||||
" "
|
||||
& "$PSScriptRoot/measure-BubbleSort.ps1" $numIntegers
|
||||
& "$PSScriptRoot/measure-BucketSort.ps1" $numIntegers
|
||||
|
33
Scripts/move-mouse-pointer.ps1
Executable file
33
Scripts/move-mouse-pointer.ps1
Executable file
@ -0,0 +1,33 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Moves the mouse pointer
|
||||
.DESCRIPTION
|
||||
This PowerShell script moves the mouse pointer either to the given x/y coordinate or just slightly.
|
||||
.PARAMETER x
|
||||
Specifies the x coordinate in pixels
|
||||
.PARAMETER y
|
||||
Specifies the y coordinate in pixels
|
||||
.EXAMPLE
|
||||
PS> ./move-mouse-pointer.ps1 100 100
|
||||
.LINK
|
||||
https://github.com/fleschutz/PowerShell
|
||||
.NOTES
|
||||
Author: Markus Fleschutz | License: CC0
|
||||
#>
|
||||
|
||||
param([int]$x = -1, [int]$y = -1)
|
||||
|
||||
try {
|
||||
Add-Type -AssemblyName System.Windows.Forms
|
||||
|
||||
if (($x -eq -1) -and ($y -eq -1)) {
|
||||
$Pos = [System.Windows.Forms.Cursor]::Position
|
||||
$x = $pos.X + 5
|
||||
$y = $pos.Y + 5
|
||||
}
|
||||
[System.Windows.Forms.Cursor]::Position = New-Object System.Drawing.Point($x, $y)
|
||||
exit 0 # success
|
||||
} catch {
|
||||
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
exit 1
|
||||
}
|
@ -2,13 +2,20 @@
|
||||
.SYNOPSIS
|
||||
Creates a new Git branch
|
||||
.DESCRIPTION
|
||||
This PowerShell script creates a new branch in a Git repository and switches to it.
|
||||
This PowerShell script creates a new branch in a local Git repository and switches to it.
|
||||
.PARAMETER newBranch
|
||||
Specifies the new branch name
|
||||
.PARAMETER repoPath
|
||||
Specifies the path to the Git repository (current working directory per default)
|
||||
.EXAMPLE
|
||||
PS> ./new-branch.ps1 test123
|
||||
PS> ./new-branch.ps1 test123 C:\MyRepo
|
||||
⏳ (1/6) Searching for Git executable... git version 2.42.0.windows.2
|
||||
⏳ (2/6) Checking local repository...
|
||||
⏳ (3/6) Fetching latest updates...
|
||||
⏳ (4/6) Creating new branch...
|
||||
⏳ (5/6) Pushing updates...
|
||||
⏳ (6/6) Updating submodules...
|
||||
✔️ Created branch 'test123' in repo 📂MyRepo (based on 'main' in 18 sec)
|
||||
.LINK
|
||||
https://github.com/fleschutz/PowerShell
|
||||
.NOTES
|
||||
@ -26,7 +33,7 @@ try {
|
||||
& git --version
|
||||
if ($lastExitCode -ne "0") { throw "Can't execute 'git' - make sure Git is installed and available" }
|
||||
|
||||
Write-Host "⏳ (2/6) Checking local repository... 📂$repoPath"
|
||||
Write-Host "⏳ (2/6) Checking local repository..."
|
||||
if (-not(Test-Path "$repoPath" -pathType container)) { throw "Can't access directory: $repoPath" }
|
||||
$repoPathName = (Get-Item "$repoPath").Name
|
||||
|
||||
@ -37,7 +44,7 @@ try {
|
||||
$currentBranch = (git -C "$repoPath" rev-parse --abbrev-ref HEAD)
|
||||
if ($lastExitCode -ne "0") { throw "'git rev-parse' failed with exit code $lastExitCode" }
|
||||
|
||||
"⏳ (4/6) Creating branch..."
|
||||
"⏳ (4/6) Creating new branch..."
|
||||
& git -C "$repoPath" checkout -b "$newBranch"
|
||||
if ($lastExitCode -ne "0") { throw "'git checkout -b $newBranch' failed with exit code $lastExitCode" }
|
||||
|
||||
@ -50,7 +57,7 @@ try {
|
||||
if ($lastExitCode -ne "0") { throw "'git submodule update' failed with exit code $lastExitCode" }
|
||||
|
||||
[int]$elapsed = $stopWatch.Elapsed.TotalSeconds
|
||||
"✔️ created branch '$newBranch' based on '$currentBranch' in repo 📂$repoPathName in $elapsed sec"
|
||||
"✔️ Created branch '$newBranch' in repo 📂$repoPathName (based on '$currentBranch' in $elapsed sec)"
|
||||
exit 0 # success
|
||||
} catch {
|
||||
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
|
17
Scripts/on-desktop-login.ps1
Normal file → Executable file
17
Scripts/on-desktop-login.ps1
Normal file → Executable file
@ -1,9 +1,9 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Executes scripts on desktop login
|
||||
Executes tasks on desktop login
|
||||
.DESCRIPTION
|
||||
This PowerShell script executes welcome scripts on every desktop user login.
|
||||
Just put a symbolic link to this script into the Autostart folder (usually at: C:\Users\<USERNAME>\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup).
|
||||
This PowerShell script executes useful tasks on every desktop login by the user (e.g. open Web dashboards, list the news, fetch repos).
|
||||
NOTE: For installation on Windows create and put a symbolic link to this script into the Autostart folder (usually at: C:\Users\<USERNAME>\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup).
|
||||
.EXAMPLE
|
||||
PS> ./on-desktop-login.ps1
|
||||
.LINK
|
||||
@ -13,10 +13,19 @@
|
||||
#>
|
||||
|
||||
try {
|
||||
& "$PSScriptRoot/write-quote.ps1"
|
||||
& "$PSScriptRoot/write-big.ps1" "Welcome back"
|
||||
" "
|
||||
& "$PSScriptRoot/open-dashboards.ps1"
|
||||
" "
|
||||
& "$PSScriptRoot/write-quote.ps1"
|
||||
" "
|
||||
& "$PSScriptRoot/list-news.ps1"
|
||||
" "
|
||||
& "$PSScriptRoot/write-joke.ps1"
|
||||
" "
|
||||
& "$PSScriptRoot/cd-repos.ps1"
|
||||
& "$PSScriptRoot/fetch-repos.ps1"
|
||||
" "
|
||||
& "$PSScriptRoot/write-clock.ps1"
|
||||
exit 0 # success
|
||||
} catch {
|
||||
|
@ -2,11 +2,10 @@
|
||||
.SYNOPSIS
|
||||
Open web dashboards
|
||||
.DESCRIPTION
|
||||
This PowerShell script launches the web browser with tabs of 18 dashboard websites.
|
||||
This PowerShell script launches the Web browser with 20 tabs of popular dashboard websites.
|
||||
.EXAMPLE
|
||||
PS> ./open-dashboards.ps1
|
||||
⏳ (1/2) Reading Data/popular-dashboards.csv...
|
||||
⏳ (2/2) Launching web browser tabs with: Toggl Track · Google Calendar · CNN News...
|
||||
✅ Launching Web browser with 20 tabs... Toggl Track, Google Calendar, Google Mail, Google Keep, Google Photos, Google News, Outlook Mail, CNN News, GitHub Explore, FlightRadar24, Earthquake Watch, Live Cyber Threat Map, Live Traffic, Netflix Top 10, YouTube Music Charts, Webcams, Peak Zugspitze, Airport Salzburg, Windy Weather Radar, Windy Weather Temperatures, (Hint: execute './switch-tabs.ps1' for automated tab switching)
|
||||
...
|
||||
.LINK
|
||||
https://github.com/fleschutz/PowerShell
|
||||
@ -15,19 +14,17 @@
|
||||
#>
|
||||
|
||||
try {
|
||||
$stopWatch = [system.diagnostics.stopwatch]::startNew()
|
||||
Write-Host "⏳ (1/2) Reading Data/popular-dashboards.csv..."
|
||||
Write-Progress "⏳ Reading Data/popular-dashboards.csv..."
|
||||
$table = Import-CSV "$PSScriptRoot/../Data/popular-dashboards.csv"
|
||||
$numRows = $table.Length
|
||||
Write-Host "⏳ (2/2) Launching web browser tabs with: " -noNewline
|
||||
Write-Progress -completed "."
|
||||
Write-Host "✅ Launching Web browser with 20 tabs... " -noNewline
|
||||
foreach($row in $table) {
|
||||
Write-Host "$($row.NAME) · " -noNewline
|
||||
Write-Host "$($row.NAME), " -noNewline
|
||||
& "$PSScriptRoot/open-default-browser.ps1" "$($row.URL)"
|
||||
Start-Sleep -milliseconds 100
|
||||
}
|
||||
Write-Host ""
|
||||
[int]$elapsed = $stopWatch.Elapsed.TotalSeconds
|
||||
"✅ Opened $NumRows dashboards in $elapsed sec (Hint: use 'switch-tabs.ps1' to switch between the tabs automatically)"
|
||||
Write-Host "(Hint: execute './switch-tabs.ps1' for automated tab switching)"
|
||||
exit 0 # success
|
||||
} catch {
|
||||
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
|
22
Scripts/open-rdp.ps1
Executable file
22
Scripts/open-rdp.ps1
Executable file
@ -0,0 +1,22 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Opens the RDP app
|
||||
.DESCRIPTION
|
||||
This script launches the Remote Desktop Protocol (RDP) application.
|
||||
NOTE: Documentation of mstsc at: https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/mstsc
|
||||
.EXAMPLE
|
||||
PS> ./open-rdp.ps1
|
||||
.LINK
|
||||
https://github.com/fleschutz/PowerShell
|
||||
.NOTES
|
||||
Author: Markus Fleschutz | License: CC0
|
||||
#>
|
||||
|
||||
param([string]$hostname = "")
|
||||
|
||||
if ($hostname -eq "") {
|
||||
& Start-Process "$env:windir\system32\mstsc.exe"
|
||||
} else {
|
||||
& Start-Process "$env:windir\system32\mstsc.exe" -ArgumentList "/v:$hostname"
|
||||
}
|
||||
exit 0 # success
|
@ -1,26 +1,26 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Launches the Visual Studio app
|
||||
Launches Visual Studio
|
||||
.DESCRIPTION
|
||||
This script launches the Microsoft Visual Studio application.
|
||||
This PowerShell script launches the Microsoft Visual Studio application.
|
||||
.EXAMPLE
|
||||
PS> ./open-visual-studio
|
||||
PS> ./open-visual-studio.ps1
|
||||
.LINK
|
||||
https://github.com/fleschutz/PowerShell
|
||||
.NOTES
|
||||
Author: Markus Fleschutz | License: CC0
|
||||
#>
|
||||
|
||||
function TryLaunching { param($Path)
|
||||
if (test-path "$Path" -pathType leaf) {
|
||||
start-process "$Path"
|
||||
function tryToLaunch { param($filePath)
|
||||
if (Test-Path "$filePath" -pathType leaf) {
|
||||
Start-Process "$filePath"
|
||||
exit 0 # success
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
TryLaunching "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\devenv.exe"
|
||||
TryLaunching "C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\devenv.exe"
|
||||
tryToLaunch "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\devenv.exe"
|
||||
tryToLaunch "C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\devenv.exe"
|
||||
exit 0 # success
|
||||
} catch {
|
||||
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
|
157
Scripts/play-pong.ps1
Executable file
157
Scripts/play-pong.ps1
Executable file
@ -0,0 +1,157 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Play the Pong game
|
||||
.DESCRIPTION
|
||||
This PowerShell script lets 2 players play the famous Pong game.
|
||||
NOTE: Player 1: <W> moves up, <S> moves down | Player 2: <UP> or <DOWN> | <ESC> to quit
|
||||
.EXAMPLE
|
||||
PS> ./play-pong.ps1
|
||||
.LINK
|
||||
https://github.com/fleschutz/PowerShell
|
||||
.NOTES
|
||||
Author: Markus Fleschutz | License: CC0
|
||||
#>
|
||||
|
||||
function DrawScores {
|
||||
$x = [System.Console]::WindowWidth / 2 - 4
|
||||
[System.Console]::SetCursorPosition($x, 1)
|
||||
[System.Console]::Write("$($script:scorePlayer1) - $($script:scorePlayer2)")
|
||||
}
|
||||
|
||||
function DrawFooter {
|
||||
$text = "| Player 1: <W> moves up, <S> moves down | Player 2: <UP> or <DOWN> | <ESC> to quit |"
|
||||
$x = ([System.Console]::WindowWidth - $text.Length) / 2
|
||||
$y = [System.Console]::WindowHeight - 1
|
||||
[System.Console]::SetCursorPosition($x, $y)
|
||||
[System.Console]::Write($text)
|
||||
}
|
||||
|
||||
function DrawPaddle($y, $isLeft) {
|
||||
if ($isLeft) {
|
||||
$x = 0
|
||||
} else {
|
||||
$x = [System.Console]::WindowWidth - 1
|
||||
}
|
||||
for ($i = 0; $i -lt 5; $i++) {
|
||||
[System.Console]::SetCursorPosition($x, $y + $i)
|
||||
[System.Console]::Write("▌")
|
||||
}
|
||||
}
|
||||
|
||||
function ClearPaddle($y, $isLeft) {
|
||||
if ($isLeft) {
|
||||
$x = 0
|
||||
} else {
|
||||
$x = [System.Console]::WindowWidth - 1
|
||||
}
|
||||
for ($i = 0; $i -lt 5; $i++) {
|
||||
[System.Console]::SetCursorPosition($x, $y + $i)
|
||||
[System.Console]::Write(" ")
|
||||
}
|
||||
}
|
||||
|
||||
function DrawBall($x, $y) {
|
||||
if ($x -lt 0 -or $x -ge [System.Console]::WindowWidth - 1 -or $y -lt 0 -or $y -ge [System.Console]::WindowHeight) {
|
||||
return
|
||||
}
|
||||
[System.Console]::SetCursorPosition($x, $y)
|
||||
Write-Host "🔴" -noNewline
|
||||
}
|
||||
|
||||
function ClearBall($x, $y) {
|
||||
if ($x -lt 0 -or $x -ge [System.Console]::WindowWidth - 1 -or $y -lt 0 -or $y -ge [System.Console]::WindowHeight) {
|
||||
return
|
||||
}
|
||||
[System.Console]::SetCursorPosition($x, $y)
|
||||
[System.Console]::Write(" ")
|
||||
}
|
||||
|
||||
function UpdateBall {
|
||||
$nextX = $script:ball.X + $script:ball.Dx
|
||||
$nextY = $script:ball.Y + $script:ball.Dy
|
||||
|
||||
if ($nextY -lt 0 -or $nextY -ge [System.Console]::WindowHeight) {
|
||||
$script:ball.Dy = -$script:ball.Dy
|
||||
$nextY = $script:ball.Y
|
||||
}
|
||||
|
||||
if ($nextX -eq 1 -and ($nextY -ge $player1 -and $nextY -le ($player1 + 4))) {
|
||||
$script:ball.Dx = -$script:ball.Dx
|
||||
$nextX = $script:ball.X
|
||||
} elseif ($nextX -eq ([System.Console]::WindowWidth - 2) -and ($nextY -ge $player2 -and $nextY -le ($player2 + 4))) {
|
||||
$script:ball.Dx = -$script:ball.Dx
|
||||
$nextX = $script:ball.X
|
||||
}
|
||||
|
||||
if ($nextX -lt 0) {
|
||||
$script:scorePlayer2++
|
||||
DrawScores
|
||||
$nextX = [System.Console]::WindowWidth / 2
|
||||
} elseif ($nextX -ge [System.Console]::WindowWidth) {
|
||||
$script:scorePlayer1++
|
||||
DrawScores
|
||||
$nextX = [System.Console]::WindowWidth / 2
|
||||
}
|
||||
|
||||
$script:ball.X = $nextX
|
||||
$script:ball.Y = $nextY
|
||||
}
|
||||
|
||||
$ui = (Get-Host).ui
|
||||
$rui = $ui.rawui
|
||||
$console = [System.Console]::BufferWidth = [System.Console]::WindowWidth = $rui.MaxWindowSize.Width
|
||||
[System.Console]::BufferHeight = [System.Console]::WindowHeight = $rui.MaxWindowSize.Height
|
||||
|
||||
$player1 = 5
|
||||
$player2 = 5
|
||||
$ball = @{
|
||||
X = 25
|
||||
Y = 10
|
||||
Dx = 1
|
||||
Dy = 1
|
||||
}
|
||||
$scorePlayer1 = 0
|
||||
$scorePlayer2 = 0
|
||||
[System.Console]::Clear()
|
||||
DrawPaddle $player1 $true
|
||||
DrawPaddle $player2 $false
|
||||
DrawScores
|
||||
DrawFooter
|
||||
[System.Console]::TreatControlCAsInput = $true
|
||||
|
||||
while ($true) {
|
||||
if ([System.Console]::KeyAvailable) {
|
||||
$key = [System.Console]::ReadKey($true).Key
|
||||
|
||||
if ($key -eq "W" -and $player1 -gt 0) {
|
||||
ClearPaddle $player1 $true
|
||||
$player1--
|
||||
DrawPaddle $player1 $true
|
||||
} elseif ($key -eq "S" -and $player1 -lt [System.Console]::WindowHeight - 5) {
|
||||
ClearPaddle $player1 $true
|
||||
$player1++
|
||||
DrawPaddle $player1 $true
|
||||
} elseif ($key -eq "UpArrow" -and $player2 -gt 0) {
|
||||
ClearPaddle $player2 $false
|
||||
$player2--
|
||||
DrawPaddle $player2 $false
|
||||
} elseif ($key -eq "DownArrow" -and $player2 -lt [System.Console]::WindowHeight - 5) {
|
||||
ClearPaddle $player2 $false
|
||||
$player2++
|
||||
DrawPaddle $player2 $false
|
||||
} elseif ($key -eq "Escape") {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
ClearBall $ball.X $ball.Y
|
||||
UpdateBall
|
||||
DrawBall $ball.X $ball.Y
|
||||
|
||||
DrawPaddle $player1 $true
|
||||
DrawPaddle $player2 $false
|
||||
|
||||
Start-Sleep -Milliseconds 100
|
||||
}
|
||||
[System.Console]::Clear()
|
||||
exit 0 # success
|
16
Scripts/play-rick.ps1
Executable file
16
Scripts/play-rick.ps1
Executable file
@ -0,0 +1,16 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Plays Rick Astley
|
||||
.DESCRIPTION
|
||||
This PowerShell script launches the Web browser with YouTube playing Rick Astley.
|
||||
.EXAMPLE
|
||||
PS> ./play-rick.ps1
|
||||
.LINK
|
||||
https://github.com/fleschutz/PowerShell
|
||||
.NOTES
|
||||
Author: Markus Fleschutz | License: CC0
|
||||
#>
|
||||
|
||||
& "$PSScriptRoot/open-default-browser.ps1" "https://www.youtube.com/watch?v=v7ScGV5128A"
|
||||
"You've been Rick-Rolled 🤣"
|
||||
exit 0 # success
|
47
Scripts/play-snake.ps1
Executable file
47
Scripts/play-snake.ps1
Executable file
@ -0,0 +1,47 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Play the Snake game
|
||||
.DESCRIPTION
|
||||
This PowerShell script lets you play the famous Snake game.
|
||||
NOTE: use the arrow keys to control the snake
|
||||
.EXAMPLE
|
||||
PS> ./play-snake.ps1
|
||||
.LINK
|
||||
https://github.com/fleschutz/PowerShell
|
||||
.NOTES
|
||||
Author: Markus Fleschutz | License: CC0
|
||||
#>
|
||||
|
||||
$w=($q=($u=$Host.UI.RawUi).WindowSize).Width-1
|
||||
$u.CursorSize=0
|
||||
$a=0..($q.Height-1)|%{$i=$_;0..$w|%{@{X=$_;Y=$i}}};$s=($f=$n=$a[($x=$y=$d=3)]),$n
|
||||
|
||||
function Z($c,$t) {
|
||||
$u.CursorPosition=$c
|
||||
Write-Host $t -N
|
||||
}
|
||||
|
||||
while(0..$w-contains$x-and($b=$x+$y*($w+1))-ge0-and($n=$a[$b])-and$s-notcontains$n) {
|
||||
Z $n "X"
|
||||
sleep -M 99
|
||||
while($u.KeyAvailable-and1..4-contains($k=$u.ReadKey(15).VirtualKeyCode-36)-and$d%2-ne$k%2) {
|
||||
$d=$k
|
||||
}
|
||||
switch($d) {
|
||||
1 { --$x }
|
||||
2 { --$y }
|
||||
3 { ++$x }
|
||||
4 { ++$y }
|
||||
}
|
||||
$s+=$n
|
||||
if ($s-contains$f) {
|
||||
$f=$a|random
|
||||
} else {
|
||||
$p,$s=$s
|
||||
Z $p ' '
|
||||
}
|
||||
Z $f "🔶"
|
||||
}
|
||||
|
||||
Write-Host "`n---------`nGAME OVER`n---------"
|
||||
exit 0 # success
|
@ -1,12 +1,17 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Pulls repository updates
|
||||
Pulls updates into a Git repository
|
||||
.DESCRIPTION
|
||||
This PowerShell script pulls the latest updates into a local Git repository (including submodules).
|
||||
.PARAMETER RepoDir
|
||||
Specifies the file path to the local Git repository (default is working directory)
|
||||
.EXAMPLE
|
||||
PS> ./pull-repo C:\MyRepo
|
||||
PS> ./pull-repo.ps1 C:\MyRepo
|
||||
⏳ (1/4) Searching for Git executable... git version 2.42.0.windows.1
|
||||
⏳ (2/4) Checking local repository...
|
||||
⏳ (3/4) Pulling updates...
|
||||
⏳ (4/4) Updating submodules...
|
||||
✔️ Pulled updates into repo 📂MyRepo in 14 sec
|
||||
.LINK
|
||||
https://github.com/fleschutz/PowerShell
|
||||
.NOTES
|
||||
@ -22,7 +27,7 @@ try {
|
||||
& git --version
|
||||
if ($lastExitCode -ne "0") { throw "Can't execute 'git' - make sure Git is installed and available" }
|
||||
|
||||
Write-Host "⏳ (2/4) Checking local repository... 📂$RepoDir"
|
||||
Write-Host "⏳ (2/4) Checking local repository..."
|
||||
if (-not(Test-Path "$RepoDir" -pathType container)) { throw "Can't access folder: $RepoDir" }
|
||||
$Result = (git -C "$RepoDir" status)
|
||||
if ("$Result" -match "HEAD detached at ") { throw "Currently in detached HEAD state (not on a branch!), so nothing to pull" }
|
||||
@ -37,7 +42,7 @@ try {
|
||||
if ($lastExitCode -ne "0") { throw "'git submodule update' failed with exit code $lastExitCode" }
|
||||
|
||||
[int]$Elapsed = $StopWatch.Elapsed.TotalSeconds
|
||||
"✔️ Pulling updates into repository 📂$RepoDirName took $Elapsed sec"
|
||||
"✔️ Pulled updates into repo 📂$RepoDirName in $Elapsed sec"
|
||||
exit 0 # success
|
||||
} catch {
|
||||
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
|
@ -47,7 +47,7 @@ try {
|
||||
$Step++
|
||||
}
|
||||
[int]$Elapsed = $StopWatch.Elapsed.TotalSeconds
|
||||
"✔️ Pulling updates into $NumFolders repositories under 📂$ParentDirName took $Elapsed sec ($Failed failed)"
|
||||
"✔️ Pulled updates into $NumFolders repos under 📂$ParentDirName ($Failed failed, took $Elapsed sec)"
|
||||
exit 0 # success
|
||||
} catch {
|
||||
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
|
0
Scripts/remove-old-dirs.ps1
Normal file → Executable file
0
Scripts/remove-old-dirs.ps1
Normal file → Executable file
@ -1,35 +1,33 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Sets the volume
|
||||
Sets the audio volume
|
||||
.DESCRIPTION
|
||||
This PowerShell script sets the audio volume in percent.
|
||||
.PARAMETER volume
|
||||
Specifies the percent number
|
||||
This PowerShell script sets the audio volume to the given value in percent (0..100).
|
||||
.PARAMETER percent
|
||||
Specifies the volume in percent (0..100)
|
||||
.EXAMPLE
|
||||
PS> ./set-volume 50
|
||||
PS> ./set-volume.ps1 50
|
||||
.LINK
|
||||
https://github.com/fleschutz/PowerShell
|
||||
.NOTES
|
||||
Author: Markus Fleschutz | License: CC0
|
||||
#>
|
||||
|
||||
Param([Parameter(Mandatory=$true)] [ValidateRange(0,100)] [Int] $Volume)
|
||||
Param([Parameter(Mandatory=$true)] [ValidateRange(0,100)] [Int] $percent)
|
||||
|
||||
try {
|
||||
# Create the Windows Shell object.
|
||||
$obj = New-Object -ComObject WScript.Shell
|
||||
|
||||
# First, set volume to zero.
|
||||
1..50 | ForEach-Object { $obj.SendKeys( [char] 174 ) }
|
||||
|
||||
# Calculate number of (volume up) key presses
|
||||
$keyPresses = [Math]::Ceiling( $Volume / 2 )
|
||||
for ([int]$i = 0; $i -lt 100; $i += 2) {
|
||||
$obj.SendKeys([char]174) # each tick is -2%
|
||||
}
|
||||
|
||||
# Raise volume to specified level.
|
||||
for( $i = 0; $i -lt $keyPresses; $i++ ) {
|
||||
$obj.SendKeys( [char] 175 )
|
||||
for ([int]$i = 0; $i -lt $percent; $i += 2) {
|
||||
$obj.SendKeys([char]175) # each tick is +2%
|
||||
}
|
||||
& "$PSScriptRoot/speak-english.ps1" "$($Volume)% volume."
|
||||
exit 0 # success
|
||||
} catch {
|
||||
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
|
@ -1,6 +1,6 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Speaks text with an Arabic text-to-speech voice
|
||||
Speaks text in Arabic
|
||||
.DESCRIPTION
|
||||
This PowerShell script speaks the given text with an Arabic text-to-speech (TTS) voice.
|
||||
.PARAMETER text
|
||||
|
0
Scripts/speak-croatian.ps1
Normal file → Executable file
0
Scripts/speak-croatian.ps1
Normal file → Executable file
0
Scripts/speak-esperanto.ps1
Normal file → Executable file
0
Scripts/speak-esperanto.ps1
Normal file → Executable file
0
Scripts/speak-finnish.ps1
Normal file → Executable file
0
Scripts/speak-finnish.ps1
Normal file → Executable file
@ -1,6 +1,6 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Speaks text with a Greek text-to-speech voice
|
||||
Speaks text in Greek
|
||||
.DESCRIPTION
|
||||
This PowerShell script speaks the given text with a Greek text-to-speech (TTS) voice.
|
||||
.PARAMETER text
|
||||
|
0
Scripts/speak-hebrew.ps1
Normal file → Executable file
0
Scripts/speak-hebrew.ps1
Normal file → Executable file
0
Scripts/speak-korean.ps1
Normal file → Executable file
0
Scripts/speak-korean.ps1
Normal file → Executable file
0
Scripts/speak-norwegian.ps1
Normal file → Executable file
0
Scripts/speak-norwegian.ps1
Normal file → Executable file
33
Scripts/speak-russian.ps1
Executable file
33
Scripts/speak-russian.ps1
Executable file
@ -0,0 +1,33 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Speaks text in Russian
|
||||
.DESCRIPTION
|
||||
This PowerShell script speaks the text with a Russian text-to-speech (TTS) voice.
|
||||
.PARAMETER text
|
||||
Specifies the Russian text
|
||||
.EXAMPLE
|
||||
PS> ./speak-russian.ps1 "Привет"
|
||||
.LINK
|
||||
https://github.com/fleschutz/PowerShell
|
||||
.NOTES
|
||||
Author: Markus Fleschutz | License: CC0
|
||||
#>
|
||||
|
||||
param([string]$text = "")
|
||||
|
||||
try {
|
||||
if ($text -eq "") { $text = Read-Host "Enter the Russian text" }
|
||||
|
||||
$TTS = New-Object -ComObject SAPI.SPVoice
|
||||
foreach ($voice in $TTS.GetVoices()) {
|
||||
if ($voice.GetDescription() -like "*- Russian*") {
|
||||
$TTS.Voice = $voice
|
||||
[void]$TTS.Speak("Путин вторгся в Украину и проиграет войну!")
|
||||
exit 0 # success
|
||||
}
|
||||
}
|
||||
throw "No Russian text-to-speech voice found - please install one"
|
||||
} catch {
|
||||
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
exit 1
|
||||
}
|
@ -4,15 +4,17 @@
|
||||
.DESCRIPTION
|
||||
This PowerShell script performs a text-to-speech (TTS) test.
|
||||
.EXAMPLE
|
||||
PS> ./speak-test
|
||||
PS> ./speak-test.ps1
|
||||
📣 Let's begin with the default speed rate of 0 at the default volume of 100%.
|
||||
...
|
||||
.LINK
|
||||
https://github.com/fleschutz/PowerShell
|
||||
.NOTES
|
||||
Author: Markus Fleschutz | License: CC0
|
||||
#>
|
||||
|
||||
function Speak { param([string]$Text)
|
||||
write-output "'$Text'"
|
||||
function Speak([string]$Text) {
|
||||
Write-Output "📣 $Text"
|
||||
[void]$Voice.speak("$Text")
|
||||
}
|
||||
|
||||
@ -39,21 +41,22 @@ try {
|
||||
$Voice.rate = $DefaultRate
|
||||
|
||||
$Voice.volume = 100
|
||||
Speak("Let's try 100% volume")
|
||||
Speak("Let's try 100% volume.")
|
||||
$Voice.volume = 75
|
||||
Speak("Let's try 75% volume")
|
||||
Speak("Let's try 75% volume.")
|
||||
$Voice.volume = 50
|
||||
Speak("Let's try 50% volume")
|
||||
Speak("Let's try 50% volume.")
|
||||
$Voice.volume = 25
|
||||
Speak("Let's try 25% volume")
|
||||
Speak("Let's try 25% volume.")
|
||||
$Voice.volume = $DefaultVolume
|
||||
|
||||
$Voices = $Voice.GetVoices()
|
||||
foreach ($OtherVoice in $Voices) {
|
||||
$Voice.Voice = $OtherVoice
|
||||
$Description = $OtherVoice.GetDescription()
|
||||
Speak("Hi, I'm the voice called $Description")
|
||||
Speak("Hi, I'm the voice called $Description.")
|
||||
}
|
||||
Speak("Thanks for your attention.")
|
||||
exit 0 # success
|
||||
} catch {
|
||||
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
|
0
Scripts/speak-thai.ps1
Normal file → Executable file
0
Scripts/speak-thai.ps1
Normal file → Executable file
@ -3,23 +3,30 @@
|
||||
Switches the Git branch
|
||||
.DESCRIPTION
|
||||
This PowerShell script switches to another branch in a Git repository (including submodules).
|
||||
.PARAMETER BranchName
|
||||
.PARAMETER branchName
|
||||
Specifies the branch name
|
||||
.PARAMETER RepoDir
|
||||
.PARAMETER repoDir
|
||||
Specifies the path to the local Git repository
|
||||
.EXAMPLE
|
||||
PS> ./switch-branch main C:\MyRepo
|
||||
⏳ (1/6) Searching for Git executable... git version 2.42.0.windows.1
|
||||
⏳ (2/6) Checking local repository...
|
||||
⏳ (3/6) Fetching updates...
|
||||
⏳ (4/6) Switching to branch 'main'...
|
||||
⏳ (5/6) Pulling updates...
|
||||
⏳ (6/6) Updating submodules...
|
||||
✔️ Switched repo 📂MyRepo to branch 'main' in 22 sec
|
||||
.LINK
|
||||
https://github.com/fleschutz/PowerShell
|
||||
.NOTES
|
||||
Author: Markus Fleschutz | License: CC0
|
||||
#>
|
||||
|
||||
param([string]$BranchName = "", [string]$RepoDir = "$PWD")
|
||||
param([string]$branchName = "", [string]$repoDir = "$PWD")
|
||||
|
||||
try {
|
||||
if ($BranchName -eq "") { $BranchName = read-host "Enter name of branch to switch to" }
|
||||
if ($RepoDir -eq "") { $RepoDir = read-host "Enter path to the local Git repository" }
|
||||
if ($branchName -eq "") { $branchName = Read-Host "Enter the branch name to switch to" }
|
||||
if ($repoDir -eq "") { $repoDir = Read-Host "Enter the path to the local Git repository" }
|
||||
|
||||
$StopWatch = [system.diagnostics.stopwatch]::startNew()
|
||||
|
||||
@ -27,32 +34,32 @@ try {
|
||||
& git --version
|
||||
if ($lastExitCode -ne "0") { throw "Can't execute 'git' - make sure Git is installed and available" }
|
||||
|
||||
Write-Host "⏳ (2/6) Checking local repository... 📂$RepoDir"
|
||||
$RepoDir = Resolve-Path "$RepoDir"
|
||||
if (-not(Test-Path "$RepoDir" -pathType container)) { throw "Can't access directory: $RepoDir" }
|
||||
Write-Host "⏳ (2/6) Checking local repository..."
|
||||
$repoDir = Resolve-Path "$repoDir"
|
||||
if (-not(Test-Path "$repoDir" -pathType container)) { throw "Can't access directory: $repoDir" }
|
||||
$Result = (git status)
|
||||
if ($lastExitCode -ne "0") { throw "'git status' in $RepoDir failed with exit code $lastExitCode" }
|
||||
if ($lastExitCode -ne "0") { throw "'git status' in $repoDir failed with exit code $lastExitCode" }
|
||||
if ("$Result" -notmatch "nothing to commit, working tree clean") { throw "Git repository is NOT clean: $Result" }
|
||||
$RepoDirName = (Get-Item "$RepoDir").Name
|
||||
$repoDirName = (Get-Item "$repoDir").Name
|
||||
|
||||
"⏳ (3/6) Fetching updates..."
|
||||
& git -C "$RepoDir" fetch --all --prune --prune-tags --force
|
||||
"⏳ (3/6) Fetching latest updates..."
|
||||
& git -C "$repoDir" fetch --all --prune --prune-tags --force
|
||||
if ($lastExitCode -ne "0") { throw "'git fetch' failed with exit code $lastExitCode" }
|
||||
|
||||
"⏳ (4/6) Switching to branch '$BranchName'..."
|
||||
& git -C "$RepoDir" checkout --recurse-submodules "$BranchName"
|
||||
if ($lastExitCode -ne "0") { throw "'git checkout $BranchName' failed with exit code $lastExitCode" }
|
||||
"⏳ (4/6) Switching to branch '$branchName'..."
|
||||
& git -C "$repoDir" checkout --recurse-submodules "$branchName"
|
||||
if ($lastExitCode -ne "0") { throw "'git checkout $branchName' failed with exit code $lastExitCode" }
|
||||
|
||||
"⏳ (5/6) Pulling updates..."
|
||||
& git -C "$RepoDir" pull --recurse-submodules
|
||||
& git -C "$repoDir" pull --recurse-submodules
|
||||
if ($lastExitCode -ne "0") { throw "'git pull' failed with exit code $lastExitCode" }
|
||||
|
||||
"⏳ (6/6) Updating submodules..."
|
||||
& git -C "$RepoDir" submodule update --init --recursive
|
||||
& git -C "$repoDir" submodule update --init --recursive
|
||||
if ($lastExitCode -ne "0") { throw "'git submodule update' failed with exit code $lastExitCode" }
|
||||
|
||||
[int]$Elapsed = $StopWatch.Elapsed.TotalSeconds
|
||||
"✔️ switched repo 📂$RepoDirName to branch '$BranchName' in $Elapsed sec"
|
||||
"✔️ Switched repo 📂$repoDirName to branch '$branchName' in $Elapsed sec"
|
||||
exit 0 # success
|
||||
} catch {
|
||||
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
|
@ -2,18 +2,23 @@
|
||||
.SYNOPSIS
|
||||
Synchronizes a repo
|
||||
.DESCRIPTION
|
||||
This PowerShell script synchronizes a local Git repository by push and pull (including submodules).
|
||||
.PARAMETER RepoDir
|
||||
This PowerShell script synchronizes a local Git repository by pull and push (including submodules).
|
||||
.PARAMETER path
|
||||
Specifies the path to the Git repository
|
||||
.EXAMPLE
|
||||
PS> ./sync-repo C:\MyRepo
|
||||
PS> ./sync-repo.ps1 C:\MyRepo
|
||||
⏳ (1/4) Searching for Git executable... git version 2.42.0.windows.1
|
||||
⏳ (2/4) Checking local repository... 📂C:\MyRepo
|
||||
⏳ (3/4) Pulling remote updates... Already up to date.
|
||||
⏳ (4/4) Pushing local updates... Everything up-to-date
|
||||
✔️ Synced repo 📂MyRepo in 5 sec
|
||||
.LINK
|
||||
https://github.com/fleschutz/PowerShell
|
||||
.NOTES
|
||||
Author: Markus Fleschutz | License: CC0
|
||||
#>
|
||||
|
||||
param([string]$RepoDir = "$PWD")
|
||||
param([string]$path = "$PWD")
|
||||
|
||||
try {
|
||||
$StopWatch = [system.diagnostics.stopwatch]::startNew()
|
||||
@ -22,20 +27,20 @@ try {
|
||||
& git --version
|
||||
if ($lastExitCode -ne "0") { throw "Can't execute 'git' - make sure Git is installed and available" }
|
||||
|
||||
Write-Host "⏳ (2/4) Checking local repository... 📂$RepoDir"
|
||||
if (!(Test-Path "$RepoDir" -pathType container)) { throw "Can't access folder: $RepoDir" }
|
||||
$RepoDirName = (Get-Item "$RepoDir").Name
|
||||
Write-Host "⏳ (2/4) Checking local repository... 📂$path"
|
||||
if (!(Test-Path "$path" -pathType container)) { throw "Can't access folder: $path" }
|
||||
$pathName = (Get-Item "$path").Name
|
||||
|
||||
Write-Host "⏳ (3/4) Pushing local updates... " -noNewline
|
||||
& git -C "$RepoDir" push
|
||||
Write-Host "⏳ (3/4) Pulling remote updates... " -noNewline
|
||||
& git -C "$Path" pull --all --recurse-submodules
|
||||
if ($lastExitCode -ne "0") { throw "'git pull --all --recurse-submodes' failed" }
|
||||
|
||||
Write-Host "⏳ (4/4) Pushing local updates... " -noNewline
|
||||
& git -C "$Path" push
|
||||
if ($lastExitCode -ne "0") { throw "'git push' failed" }
|
||||
|
||||
Write-Host "⏳ (4/4) Pulling remote updates... " -noNewline
|
||||
& git -C "$RepoDir" pull --all --recurse-submodules
|
||||
if ($lastExitCode -ne "0") { throw "'git pull' failed" }
|
||||
|
||||
[int]$Elapsed = $StopWatch.Elapsed.TotalSeconds
|
||||
"✔️ synchronized repo 📂$RepoDirName in $Elapsed sec"
|
||||
"✔️ Synced repo 📂$pathName in $Elapsed sec"
|
||||
exit 0 # success
|
||||
} catch {
|
||||
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
|
@ -1,6 +1,6 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Tells a joke by text-to-speech
|
||||
Tells a random joke by text-to-speech
|
||||
.DESCRIPTION
|
||||
This PowerShell script selects a random Chuck Norris joke in Data/jokes.csv and speaks it by text-to-speech (TTS).
|
||||
.EXAMPLE
|
||||
|
@ -1,6 +1,6 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Tells a quote by text-to-speech
|
||||
Tells a random quote by text-to-speech
|
||||
.DESCRIPTION
|
||||
This PowerShell script selects a random quote from Data/quotes.csv and speaks it by text-to-speech (TTS).
|
||||
.EXAMPLE
|
||||
|
20
Scripts/uninstall-bloatware.ps1
Normal file → Executable file
20
Scripts/uninstall-bloatware.ps1
Normal file → Executable file
@ -1,4 +1,17 @@
|
||||
"Removing System Applications..."
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Uninstalls bloatware
|
||||
.DESCRIPTION
|
||||
This PowerShell script uninstalls unnecessary software and applications.
|
||||
.EXAMPLE
|
||||
PS> ./uninstall-bloatware.ps1
|
||||
.LINK
|
||||
https://github.com/fleschutz/PowerShell
|
||||
.NOTES
|
||||
Author: Markus Fleschutz | License: CC0
|
||||
#>
|
||||
|
||||
"⏳ (1/3) Removing System Applications..."
|
||||
winget uninstall 'OMEN Audio Control'
|
||||
winget uninstall 'OMEN Gaming Hub'
|
||||
winget uninstall 'Clipchamp'
|
||||
@ -32,14 +45,14 @@ winget uninstall 'Microsoft Teams'
|
||||
winget uninstall 'Mail and Calendar'
|
||||
winget uninstall 'Snipping Tool'
|
||||
|
||||
"Removing Xbox associated applications..."
|
||||
"⏳ (2/3) Removing Xbox associated applications..."
|
||||
winget uninstall 'Xbox'
|
||||
winget uninstall 'Xbox TCUI'
|
||||
winget uninstall 'Xbox Game Bar Plugin'
|
||||
winget uninstall 'Xbox Identity Provider'
|
||||
winget uninstall 'Xbox Game Speech Window'
|
||||
|
||||
"Removing miscellaneous Apps that crowd the Start Menu..."
|
||||
"⏳ (3/3) Removing miscellaneous Apps that crowd the Start Menu..."
|
||||
winget uninstall 'Spotify Music'
|
||||
winget uninstall 'Messenger'
|
||||
winget uninstall 'Instagram'
|
||||
@ -48,4 +61,5 @@ winget uninstall 'Netflix'
|
||||
winget uninstall 'LinkedIn'
|
||||
winget uninstall 'Prime Video for Windows'
|
||||
|
||||
"✔️ Finished"
|
||||
exit 0 # success
|
25
Scripts/uninstall-chrome.ps1
Executable file
25
Scripts/uninstall-chrome.ps1
Executable file
@ -0,0 +1,25 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Uninstalls the Chrome browser
|
||||
.DESCRIPTION
|
||||
This PowerShell script uninstalls the Google Chrome browser from the local computer.
|
||||
.EXAMPLE
|
||||
PS> ./uninstall-chrome.ps1
|
||||
.LINK
|
||||
https://github.com/fleschutz/PowerShell
|
||||
.NOTES
|
||||
Author: Markus Fleschutz | License: CC0
|
||||
#>
|
||||
|
||||
try {
|
||||
"⏳ Uninstalling Google Chrome..."
|
||||
|
||||
& winget uninstall --id Google.Chrome
|
||||
if ($lastExitCode -ne "0") { throw "Can't uninstall Google Chrome, is it installed?" }
|
||||
|
||||
"✔️ Google Chrome is uninstalled now."
|
||||
exit 0 # success
|
||||
} catch {
|
||||
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
exit 1
|
||||
}
|
0
Scripts/uninstall-github-cli.ps1
Normal file → Executable file
0
Scripts/uninstall-github-cli.ps1
Normal file → Executable file
@ -1,10 +1,10 @@
|
||||
c<#
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Uninstalls One Calendar
|
||||
.DESCRIPTION
|
||||
This PowerShell script uninstalls One Calendar from the local computer.
|
||||
.EXAMPLE
|
||||
PS> ./uninstall-one-calendar
|
||||
PS> ./uninstall-one-calendar.ps1
|
||||
.LINK
|
||||
https://github.com/fleschutz/PowerShell
|
||||
.NOTES
|
||||
@ -12,12 +12,14 @@
|
||||
#>
|
||||
|
||||
try {
|
||||
"Uninstalling One Calendar, please wait..."
|
||||
"⏳ Uninstalling One Calendar ..."
|
||||
$StopWatch = [system.diagnostics.stopwatch]::startNew()
|
||||
|
||||
& winget uninstall "One Calendar"
|
||||
if ($lastExitCode -ne "0") { throw "Can't uninstall One Calendar, is it installed?" }
|
||||
|
||||
"One Calendar is uninstalled now."
|
||||
[int]$Elapsed = $StopWatch.Elapsed.TotalSeconds
|
||||
"✔️ Removal of One Calendar tool $Elapsed sec"
|
||||
exit 0 # success
|
||||
} catch {
|
||||
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
|
@ -28,7 +28,7 @@ try {
|
||||
"💡 $($row.ABBR) in $basename refers to: $($row.MEANING)"
|
||||
}
|
||||
}
|
||||
if ($basename -eq "") { "🤷 Sorry, my databases have no '$abbr' entry." }
|
||||
if ($basename -eq "") { "🤷 Sorry, no entry '$abbr' in my database (located at .../Data/Abbr/)." }
|
||||
exit 0 # success
|
||||
} catch {
|
||||
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
|
2
Scripts/write-ascii-image.ps1
Normal file → Executable file
2
Scripts/write-ascii-image.ps1
Normal file → Executable file
@ -1,4 +1,4 @@
|
||||
<#
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Writes an ASCII image
|
||||
.DESCRIPTION
|
||||
|
117
Scripts/write-changelog.ps1
Executable file
117
Scripts/write-changelog.ps1
Executable file
@ -0,0 +1,117 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Writes a changelog
|
||||
.DESCRIPTION
|
||||
This PowerShell script writes an automated changelog to the console in Markdown format by using the Git commits.
|
||||
NOTE: You may also redirect the output into a file for later use.
|
||||
.EXAMPLE
|
||||
PS> ./write-changelog.ps1
|
||||
|
||||
Changelog of PowerShell
|
||||
=======================
|
||||
...
|
||||
.LINK
|
||||
https://github.com/fleschutz/PowerShell
|
||||
.NOTES
|
||||
Author: Markus Fleschutz | License: CC0
|
||||
#>
|
||||
|
||||
param([string]$RepoDir = "$PWD")
|
||||
|
||||
try {
|
||||
[system.threading.thread]::currentthread.currentculture = [system.globalization.cultureinfo]"en-US"
|
||||
|
||||
Write-Progress "⏳ (1/6) Searching for Git executable..."
|
||||
$null = (git --version)
|
||||
if ($lastExitCode -ne "0") { throw "Can't execute 'git' - make sure Git is installed and available" }
|
||||
|
||||
Write-Progress "⏳ (2/6) Checking local repository..."
|
||||
if (!(Test-Path "$RepoDir" -pathType container)) { throw "Can't access folder: $RepoDir" }
|
||||
$RepoDirName = (Get-Item "$RepoDir").Name
|
||||
|
||||
Write-Progress "⏳ (3/6) Fetching the latest commits..."
|
||||
& git -C "$RepoDir" fetch --all --force --quiet
|
||||
if ($lastExitCode -ne "0") { throw "'git fetch --all' failed with exit code $lastExitCode" }
|
||||
|
||||
Write-Progress "⏳ (4/6) Listing all Git commit messages..."
|
||||
$commits = (git -C "$RepoDir" log --boundary --pretty=oneline --pretty=format:%s | sort -u)
|
||||
|
||||
Write-Progress "⏳ (5/6) Sorting the Git commit messages..."
|
||||
$features = @()
|
||||
$fixes = @()
|
||||
$updates = @()
|
||||
$various = @()
|
||||
foreach($commit in $commits) {
|
||||
if ($commit -like "New*") {
|
||||
$features += $commit
|
||||
} elseif ($commit -like "Add*") {
|
||||
$features += $commit
|
||||
} elseif ($commit -like "Create*") {
|
||||
$features += $commit
|
||||
} elseif ($commit -like "Fix*") {
|
||||
$fixes += $commit
|
||||
} elseif ($commit -like "Hotfix*") {
|
||||
$fixes += $commit
|
||||
} elseif ($commit -like "Bugfix*") {
|
||||
$fixes += $commit
|
||||
} elseif ($commit -like "Update*") {
|
||||
$updates += $commit
|
||||
} elseif ($commit -like "Updating*") {
|
||||
$updates += $commit
|
||||
} elseif ($commit -like "Updaate*") {
|
||||
$updates += $commit
|
||||
} elseif ($commit -like "Adapt*") {
|
||||
$updates += $commit
|
||||
} elseif ($commit -like "Improve*") {
|
||||
$updates += $commit
|
||||
} elseif ($commit -like "Change*") {
|
||||
$updates += $commit
|
||||
} elseif ($commit -like "Changing*") {
|
||||
$updates += $commit
|
||||
} else {
|
||||
$various += $commit
|
||||
}
|
||||
}
|
||||
Write-Progress "⏳ (6/6) Listing all contributors..."
|
||||
$contributors = (git -C "$RepoDir" log --format='%aN' | sort -u)
|
||||
Write-Progress -completed " "
|
||||
|
||||
$Today = (Get-Date).ToShortDateString()
|
||||
Write-Output " "
|
||||
Write-Output "Changelog of $RepoDirName as of $Today"
|
||||
Write-Output "======================================"
|
||||
Write-Output " "
|
||||
Write-Output "🚀 New Features"
|
||||
Write-Output "---------------"
|
||||
foreach($c in $features) {
|
||||
Write-Output "* $c"
|
||||
}
|
||||
Write-Output " "
|
||||
Write-Output "⚠️ Bug Fixes"
|
||||
Write-Output "------------"
|
||||
foreach($c in $fixes) {
|
||||
Write-Output "* $c"
|
||||
}
|
||||
Write-Output " "
|
||||
Write-Output "🎉 Updates"
|
||||
Write-Output "----------"
|
||||
foreach($c in $updates) {
|
||||
Write-Output "* $c"
|
||||
}
|
||||
Write-Output " "
|
||||
Write-Output "🔦 Various"
|
||||
Write-Output "----------"
|
||||
foreach($c in $various) {
|
||||
Write-Output "* $c"
|
||||
}
|
||||
Write-Output " "
|
||||
Write-Output "🥇 Contributors"
|
||||
Write-Output "---------------"
|
||||
foreach($c in $contributors) {
|
||||
Write-Output "* $c"
|
||||
}
|
||||
exit 0 # success
|
||||
} catch {
|
||||
Write-Error $_.Exception.ToString()
|
||||
exit 1
|
||||
}
|
@ -2,9 +2,13 @@
|
||||
.SYNOPSIS
|
||||
Writes a chart
|
||||
.DESCRIPTION
|
||||
This PowerShell script writes a chart.
|
||||
This PowerShell script writes an horizontal chart to the console.
|
||||
.EXAMPLE
|
||||
PS> ./write-chart
|
||||
PS> ./write-chart.ps1
|
||||
|
||||
2023 BOWLING RESULTS
|
||||
████████████████▏ 40.5% Joe
|
||||
████████████▎ 30.9% Tom
|
||||
.LINK
|
||||
https://github.com/fleschutz/PowerShell
|
||||
.NOTES
|
||||
@ -14,32 +18,32 @@
|
||||
function WriteChartLine { param([string]$Text, [float]$Value, [float]$Max)
|
||||
$Num = ($Value * 40.0) / $Max
|
||||
while ($Num -ge 1.0) {
|
||||
write-host -noNewLine "█"
|
||||
Write-Host -noNewLine "█"
|
||||
$Num -= 1.0
|
||||
}
|
||||
if ($Num -ge 0.875) {
|
||||
write-host -noNewLine "▉"
|
||||
Write-Host -noNewLine "▉"
|
||||
} elseif ($Num -ge 0.75) {
|
||||
write-host -noNewLine "▊"
|
||||
Write-Host -noNewLine "▊"
|
||||
} elseif ($Num -ge 0.625) {
|
||||
write-host -noNewLine "▋"
|
||||
Write-Host -noNewLine "▋"
|
||||
} elseif ($Num -ge 0.5) {
|
||||
write-host -noNewLine "▌"
|
||||
Write-Host -noNewLine "▌"
|
||||
} elseif ($Num -ge 0.375) {
|
||||
write-host -noNewLine "▍"
|
||||
Write-Host -noNewLine "▍"
|
||||
} elseif ($Num -ge 0.25) {
|
||||
write-host -noNewLine "▎"
|
||||
Write-Host -noNewLine "▎"
|
||||
} elseif ($Num -ge 0.125) {
|
||||
write-host -noNewLine "▏"
|
||||
Write-Host -noNewLine "▏"
|
||||
}
|
||||
if ($Max -eq 100.0) {
|
||||
write-host " $($Value)% $Text"
|
||||
Write-Host " $($Value)% $Text"
|
||||
} else {
|
||||
write-host " $Value / $Max $Text"
|
||||
Write-Host " $Value / $Max $Text"
|
||||
}
|
||||
}
|
||||
|
||||
"2021 Wins"
|
||||
WriteChartLine "Markus" 40.5 100.0
|
||||
WriteChartLine "Andrea" 30.9 100.0
|
||||
Write-Host "`n2023 BOWLING RESULTS" -foregroundColor green
|
||||
WriteChartLine "Joe" 40.5 100.0
|
||||
WriteChartLine "Tom" 30.9 100.0
|
||||
exit 0 # success
|
||||
|
@ -26,9 +26,9 @@ function GetRandomCodeLine {
|
||||
0 { return $Tabs + "`$count = 0" }
|
||||
1 { return $Tabs + "`$count++" }
|
||||
2 { return $Tabs + "exit 0 # success" }
|
||||
3 { return $Tabs + "`$Files = Get-ChildItem C:" }
|
||||
3 { return $Tabs + "`$files = Get-ChildItem C:" }
|
||||
4 { return $Tabs + "Start-Sleep -seconds 1" }
|
||||
5 { return $Tabs + "`$Generator = New-Object System-Random" }
|
||||
5 { return $Tabs + "`$generator = New-Object System-Random" }
|
||||
6 { $global:Tabs = " "; return "} else {" }
|
||||
7 { $global:Tabs = " "; return "} catch {" }
|
||||
8 { $global:Tabs = " "; return "} elseif (`$count -eq 0) {" }
|
||||
@ -39,21 +39,21 @@ function GetRandomCodeLine {
|
||||
13 { return $Tabs + "return 1" }
|
||||
14 { return $Tabs + "return 0" }
|
||||
15 { return $Tabs + "Write-Progress `"Working...`" " }
|
||||
16 { return $Tabs + "[bool]`$KeepAlive = `$true" }
|
||||
16 { return $Tabs + "[bool]`$keepAlive = `$true" }
|
||||
17 { return $Tabs + "# Copyright © 2023 write-code.ps1. All Rights Reserved." }
|
||||
18 { $global:Tabs = " "; return "for ([int]`$i = 0; `$i -lt 42; `$i++) {" }
|
||||
19 { return $Tabs + "`$StopWatch = [system.diagnostics.stopwatch]::startNew()" }
|
||||
20 { return $Tabs + "[int]`$Elapsed = `$StopWatch.Elapsed.TotalSeconds" }
|
||||
19 { return $Tabs + "`$stopWatch = [system.diagnostics.stopwatch]::startNew()" }
|
||||
20 { return $Tabs + "[int]`$elapsed = `$stopWatch.Elapsed.TotalSeconds" }
|
||||
21 { $global:Tabs = " "; return "if (`$count -eq 42) {" }
|
||||
22 { $global:Tabs = " "; return "} finally {" }
|
||||
23 { return $Tabs + "throw `"Can't open file`" " }
|
||||
24 { return $Tabs + "Start-Sleep -milliseconds 42" }
|
||||
25 { return $Tabs + "`$Choice = Read-Host `"Red or blue pill?`"" }
|
||||
26 { return $Tabs + "[int]`$Answer = 42" }
|
||||
26 { return $Tabs + "[int]`$answer = 42" }
|
||||
27 { $global:Tabs = ""; return "}" }
|
||||
28 { $global:Tabs = " "; return "try {" }
|
||||
29 { $global:Tabs = " "; return "foreach(`$Row in `$Table) {" }
|
||||
30 { $global:Tabs = " "; return "foreach(`$File in `$Files) {" }
|
||||
29 { $global:Tabs = " "; return "foreach(`$row in `$table) {" }
|
||||
30 { $global:Tabs = " "; return "foreach(`$file in `$files) {" }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4,7 +4,7 @@
|
||||
.DESCRIPTION
|
||||
This PowerShell script writes an animated Mandelbrot fractal.
|
||||
.EXAMPLE
|
||||
PS> ./write-fractal
|
||||
PS> ./write-fractal.ps1
|
||||
.LINK
|
||||
https://github.com/fleschutz/PowerShell
|
||||
.NOTES
|
||||
|
31
Scripts/write-in-emojis.ps1
Executable file
31
Scripts/write-in-emojis.ps1
Executable file
@ -0,0 +1,31 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Writes text in Emojis
|
||||
.DESCRIPTION
|
||||
This PowerShell script replaces certain words in the given text by Emojis and writes it to the console.
|
||||
.PARAMETER text
|
||||
Specifies the text
|
||||
.EXAMPLE
|
||||
PS> ./write-in-emojis.ps1 "I love my folder"
|
||||
I💘️my📂
|
||||
.LINK
|
||||
https://github.com/fleschutz/PowerShell
|
||||
.NOTES
|
||||
Author: Markus Fleschutz | License: CC0
|
||||
#>
|
||||
|
||||
param([string]$text = "")
|
||||
|
||||
try {
|
||||
if ($text -eq "") { $text = Read-Host "Enter the text" }
|
||||
|
||||
$table = Import-CSV "$PSScriptRoot/../Data/emojis.csv"
|
||||
foreach($row in $table) {
|
||||
$text = $text -Replace "\s?$($row.WORD)\s?","$($row.EMOJI)️"
|
||||
}
|
||||
Write-Output $text
|
||||
exit 0 # success
|
||||
} catch {
|
||||
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
exit 1
|
||||
}
|
@ -1,11 +1,11 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Writes a random Juck Norris joke to the console
|
||||
Writes a random joke
|
||||
.DESCRIPTION
|
||||
This PowerShell script writes a random Juck Norris joke to the console.
|
||||
This PowerShell script selects a random joke from Data/jokes.csv and writes it to the console.
|
||||
.EXAMPLE
|
||||
PS> ./write-joke
|
||||
When Chuck Norris does division, there are no remainders. 😂
|
||||
PS> ./write-joke.ps1
|
||||
Chuck Norris can dribble a bowling ball. 😂
|
||||
.LINK
|
||||
https://github.com/fleschutz/PowerShell
|
||||
.NOTES
|
||||
@ -13,13 +13,13 @@
|
||||
#>
|
||||
|
||||
try {
|
||||
$Table = import-csv "$PSScriptRoot/../Data/jokes.csv"
|
||||
$table = Import-CSV "$PSScriptRoot/../Data/jokes.csv"
|
||||
|
||||
$Generator = New-Object System.Random
|
||||
$Index = [int]$Generator.next(0, $Table.Count - 1)
|
||||
$Joke = $Table[$Index].Joke
|
||||
$randomNumberGenerator = New-Object System.Random
|
||||
$row = [int]$randomNumberGenerator.next(0, $table.Count - 1)
|
||||
$joke = $table[$row].JOKE
|
||||
|
||||
"$Joke 😂"
|
||||
Write-Host "`n$Joke 😂" -foregroundColor Magenta
|
||||
exit 0 # success
|
||||
} catch {
|
||||
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
|
@ -58,4 +58,5 @@ while ($true) {
|
||||
Write-Host -foreground green $screen -noNewline
|
||||
Start-Sleep -milliseconds 30
|
||||
}
|
||||
exit 0 # success
|
||||
exit 0 # success
|
||||
|
||||
|
0
Scripts/write-qr-code.ps1
Normal file → Executable file
0
Scripts/write-qr-code.ps1
Normal file → Executable file
@ -1,8 +1,8 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Writes a quote
|
||||
Writes a random quote
|
||||
.DESCRIPTION
|
||||
This PowerShell script selects a random quote and prints it to the console.
|
||||
This PowerShell script selects a random quote from Data/quotes.csv and writes it to the console.
|
||||
.EXAMPLE
|
||||
PS> ./write-quote.ps1
|
||||
“ We must become the change we want to see. „
|
||||
@ -23,7 +23,7 @@ try {
|
||||
$spaces = " "
|
||||
$spaces = $spaces.Substring(0, $quote.Length - $author.Length)
|
||||
|
||||
Write-Host "`n"'“'"$quote"'„'"`n$spaces- $author"
|
||||
Write-Host "`n"'“'"$quote"'„'"`n$spaces- $author" -foregroundColor Magenta
|
||||
exit 0 # success
|
||||
} catch {
|
||||
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
|
17
Scripts/write-shit.ps1
Normal file → Executable file
17
Scripts/write-shit.ps1
Normal file → Executable file
@ -1 +1,16 @@
|
||||
"💩"
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Writes shit
|
||||
.DESCRIPTION
|
||||
This PowerShell script writes shit to the console (fun).
|
||||
.EXAMPLE
|
||||
PS> ./write-shit.ps1
|
||||
💩
|
||||
.LINK
|
||||
https://github.com/fleschutz/PowerShell
|
||||
.NOTES
|
||||
Author: Markus Fleschutz | License: CC0
|
||||
#>
|
||||
|
||||
Write-Output "💩"
|
||||
exit 0 # success
|
Reference in New Issue
Block a user