Added Files
This commit is contained in:
18
Powershell/Scripts/MD5.ps1
Normal file
18
Powershell/Scripts/MD5.ps1
Normal file
@@ -0,0 +1,18 @@
|
||||
<#
|
||||
.SYNTAX MD5.ps1 [<file>]
|
||||
.DESCRIPTION prints the MD5 checksum of the given file
|
||||
.LINK https://github.com/fleschutz/PowerShell
|
||||
.NOTES Author: Markus Fleschutz / License: CC0
|
||||
#>
|
||||
|
||||
param($File = "")
|
||||
if ($File -eq "" ) { $File = read-host "Enter path to file" }
|
||||
|
||||
try {
|
||||
$Result = get-filehash $File -algorithm MD5
|
||||
"MD5 hash is" $Result.Hash
|
||||
exit 0
|
||||
} catch {
|
||||
write-error "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
exit 1
|
||||
}
|
||||
18
Powershell/Scripts/SHA1.ps1
Normal file
18
Powershell/Scripts/SHA1.ps1
Normal file
@@ -0,0 +1,18 @@
|
||||
<#
|
||||
.SYNTAX SHA1.ps1 [<file>]
|
||||
.DESCRIPTION prints the SHA1 checksum of the given file
|
||||
.LINK https://github.com/fleschutz/PowerShell
|
||||
.NOTES Author: Markus Fleschutz / License: CC0
|
||||
#>
|
||||
|
||||
param($File = "")
|
||||
if ($File -eq "" ) { $File = read-host "Enter the filename" }
|
||||
|
||||
try {
|
||||
$Result = get-filehash $File -algorithm SHA1
|
||||
write-output "SHA1 hash is" $Result.Hash
|
||||
exit 0
|
||||
} catch {
|
||||
write-error "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
exit 1
|
||||
}
|
||||
18
Powershell/Scripts/SHA256.ps1
Normal file
18
Powershell/Scripts/SHA256.ps1
Normal file
@@ -0,0 +1,18 @@
|
||||
<#
|
||||
.SYNTAX SHA256.ps1 [<file>]
|
||||
.DESCRIPTION prints the SHA256 checksum of the given file
|
||||
.LINK https://github.com/fleschutz/PowerShell
|
||||
.NOTES Author: Markus Fleschutz / License: CC0
|
||||
#>
|
||||
|
||||
param($File = "")
|
||||
if ($File -eq "" ) { $File = read-host "Enter the filename" }
|
||||
|
||||
try {
|
||||
$Result = get-filehash $File -algorithm SHA256
|
||||
write-output "SHA256 hash is:" $Result.Hash
|
||||
exit 0
|
||||
} catch {
|
||||
write-error "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
exit 1
|
||||
}
|
||||
53
Powershell/Scripts/add-firewall-rules.ps1
Normal file
53
Powershell/Scripts/add-firewall-rules.ps1
Normal file
@@ -0,0 +1,53 @@
|
||||
<#
|
||||
.SYNTAX add-firewall-rules.ps1 [<path-to-executables>]
|
||||
.DESCRIPTION adds firewall rules for the given executables, administrator rights are required
|
||||
.LINK https://github.com/fleschutz/PowerShell
|
||||
.NOTES Author: Markus Fleschutz / License: CC0
|
||||
#>
|
||||
|
||||
#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'');
|
||||
'
|
||||
|
||||
|
||||
try {
|
||||
if ($PathToExecutables -eq "" ) {
|
||||
$PathToExecutables = read-host "Enter path to executables"
|
||||
}
|
||||
|
||||
$PathToExecutables = Convert-Path -Path $PathToExecutables
|
||||
|
||||
$Apps = Get-ChildItem "$PathToExecutables\*.exe" -Name
|
||||
|
||||
if($Apps.count -eq 0){
|
||||
write-warning "No executables found. No Firewall rules have been created."
|
||||
Write-Host -NoNewhLine 'Press any key to continue...';
|
||||
[void]$Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown');
|
||||
exit 1
|
||||
}
|
||||
|
||||
$arg = "PathToExecutables $Apps"
|
||||
Start-Process powershell -Verb runAs -ArgumentList "-command & {$command} $arg"
|
||||
exit 0
|
||||
} catch {
|
||||
write-error "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
exit 1
|
||||
}
|
||||
27
Powershell/Scripts/add-memo.ps1
Normal file
27
Powershell/Scripts/add-memo.ps1
Normal file
@@ -0,0 +1,27 @@
|
||||
<#
|
||||
.SYNTAX add-memo.ps1 [<text>]
|
||||
.DESCRIPTION adds the given memo text to $HOME/Memos.csv
|
||||
.LINK https://github.com/fleschutz/PowerShell
|
||||
.NOTES Author: Markus Fleschutz / License: CC0
|
||||
#>
|
||||
|
||||
param($Text = "")
|
||||
if ($Text -eq "" ) { $Text = read-host "Enter the memo text to add" }
|
||||
|
||||
try {
|
||||
$Path = "$HOME/Memos.csv"
|
||||
$Time = get-date -format "yyyy-MM-ddTHH:mm:ssZ" -asUTC
|
||||
$User = $(whoami)
|
||||
$Line = "$Time,$User,$Text"
|
||||
|
||||
if (-not(test-path "$Path" -pathType leaf)) {
|
||||
write-output "Time,User,Text" > "$Path"
|
||||
}
|
||||
write-output $Line >> "$Path"
|
||||
|
||||
"✔️ added to 📄$Path"
|
||||
exit 0
|
||||
} catch {
|
||||
write-error "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
exit 1
|
||||
}
|
||||
23
Powershell/Scripts/alert.ps1
Normal file
23
Powershell/Scripts/alert.ps1
Normal file
@@ -0,0 +1,23 @@
|
||||
<#
|
||||
.SYNTAX alert.ps1 [<message>]
|
||||
.DESCRIPTION handle and escalate the given alert message
|
||||
.LINK https://github.com/fleschutz/PowerShell
|
||||
.NOTES Author: Markus Fleschutz / License: CC0
|
||||
#>
|
||||
|
||||
param($Message = "")
|
||||
|
||||
if ($Message -eq "" ) {
|
||||
$URL = read-host "Enter alert message"
|
||||
}
|
||||
|
||||
try {
|
||||
echo "ALERT: $Message"
|
||||
|
||||
curl --header "Access-Token: o.PZl5XCp6SBl4F5PpaNXGDfFpUJZKAlEb" --header "Content-Type: application/json" --data-binary '{"type": "note", "title": "ALERT", "body": "$Message"}' --request POST https://api.pushbullet.com/v2/pushes
|
||||
|
||||
exit 0
|
||||
} catch {
|
||||
write-error "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
exit 1
|
||||
}
|
||||
12
Powershell/Scripts/calibre-server.sh
Normal file
12
Powershell/Scripts/calibre-server.sh
Normal file
@@ -0,0 +1,12 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Syntax: ./calibre-server
|
||||
# Description: starts a Calibre server
|
||||
# Author: Markus Fleschutz
|
||||
# Source: github.com/fleschutz/PowerShell
|
||||
# License: CC0
|
||||
|
||||
echo "Starting Calibre Server ..."
|
||||
calibre-server --port 8099 --num-per-page 100 --userdb $HOME/CalibreUsers.sqlite --log $HOME/CalibreServer.log --daemonize $HOME/'Calibre Library'
|
||||
echo "OK - Calibre Server started."
|
||||
exit 0
|
||||
15
Powershell/Scripts/cd-desktop.ps1
Normal file
15
Powershell/Scripts/cd-desktop.ps1
Normal file
@@ -0,0 +1,15 @@
|
||||
<#
|
||||
.SYNTAX cd-desktop.ps1
|
||||
.DESCRIPTION go to the user's desktop folder
|
||||
.LINK https://github.com/fleschutz/PowerShell
|
||||
.NOTES Author: Markus Fleschutz / License: CC0
|
||||
#>
|
||||
|
||||
$TargetDir = resolve-path "$HOME/Desktop"
|
||||
if (-not(test-path "$TargetDir" -pathType container)) {
|
||||
write-warning "Sorry, there is no folder 📂$TargetDir (yet)"
|
||||
exit 1
|
||||
}
|
||||
set-location "$TargetDir"
|
||||
"📂$TargetDir"
|
||||
exit 0
|
||||
15
Powershell/Scripts/cd-docs.ps1
Normal file
15
Powershell/Scripts/cd-docs.ps1
Normal file
@@ -0,0 +1,15 @@
|
||||
<#
|
||||
.SYNTAX cd-docs.ps1
|
||||
.DESCRIPTION go to the user's documents folder
|
||||
.LINK https://github.com/fleschutz/PowerShell
|
||||
.NOTES Author: Markus Fleschutz / License: CC0
|
||||
#>
|
||||
|
||||
$TargetDir = resolve-path "$HOME/Documents"
|
||||
if (-not(test-path "$TargetDir" -pathType container)) {
|
||||
write-warning "Sorry, there is no folder 📂$TargetDir (yet)"
|
||||
exit 1
|
||||
}
|
||||
set-location "$TargetDir"
|
||||
"📂$TargetDir"
|
||||
exit 0
|
||||
15
Powershell/Scripts/cd-downloads.ps1
Normal file
15
Powershell/Scripts/cd-downloads.ps1
Normal file
@@ -0,0 +1,15 @@
|
||||
<#
|
||||
.SYNTAX cd-downloads.ps1
|
||||
.DESCRIPTION go to the user's downloads folder
|
||||
.LINK https://github.com/fleschutz/PowerShell
|
||||
.NOTES Author: Markus Fleschutz / License: CC0
|
||||
#>
|
||||
|
||||
$TargetDir = resolve-path "$HOME/Downloads"
|
||||
if (-not(test-path "$TargetDir" -pathType container)) {
|
||||
write-warning "Sorry, there is no folder 📂$TargetDir (yet)"
|
||||
exit 1
|
||||
}
|
||||
set-location "$TargetDir"
|
||||
"📂$TargetDir"
|
||||
exit 0
|
||||
15
Powershell/Scripts/cd-dropbox.ps1
Normal file
15
Powershell/Scripts/cd-dropbox.ps1
Normal file
@@ -0,0 +1,15 @@
|
||||
<#
|
||||
.SYNTAX cd-dropbox.ps1
|
||||
.DESCRIPTION go to the user's Dropbox folder
|
||||
.LINK https://github.com/fleschutz/PowerShell
|
||||
.NOTES Author: Markus Fleschutz / License: CC0
|
||||
#>
|
||||
|
||||
$TargetDir = resolve-path "$HOME/Dropbox"
|
||||
if (-not(test-path "$TargetDir" -pathType container)) {
|
||||
write-warning "Sorry, there is no folder 📂$TargetDir (yet)"
|
||||
exit 1
|
||||
}
|
||||
set-location "$TargetDir"
|
||||
"📂$TargetDir"
|
||||
exit 0
|
||||
15
Powershell/Scripts/cd-home.ps1
Normal file
15
Powershell/Scripts/cd-home.ps1
Normal file
@@ -0,0 +1,15 @@
|
||||
<#
|
||||
.SYNTAX cd-home.ps1
|
||||
.DESCRIPTION go to the user's home folder
|
||||
.LINK https://github.com/fleschutz/PowerShell
|
||||
.NOTES Author: Markus Fleschutz / License: CC0
|
||||
#>
|
||||
|
||||
$TargetDir = resolve-path "$HOME"
|
||||
if (-not(test-path "$TargetDir" -pathType container)) {
|
||||
write-warning "Sorry, there is no folder 📂$TargetDir (yet)"
|
||||
exit 1
|
||||
}
|
||||
set-location "$TargetDir"
|
||||
"📂$TargetDir"
|
||||
exit 0
|
||||
15
Powershell/Scripts/cd-music.ps1
Normal file
15
Powershell/Scripts/cd-music.ps1
Normal file
@@ -0,0 +1,15 @@
|
||||
<#
|
||||
.SYNTAX cd-music.ps1
|
||||
.DESCRIPTION go to the user's music folder
|
||||
.LINK https://github.com/fleschutz/PowerShell
|
||||
.NOTES Author: Markus Fleschutz / License: CC0
|
||||
#>
|
||||
|
||||
$TargetDir = resolve-path "$HOME/Music"
|
||||
if (-not(test-path "$TargetDir" -pathType container)) {
|
||||
write-warning "Sorry, there is no folder 📂$TargetDir (yet)"
|
||||
exit 1
|
||||
}
|
||||
set-location "$TargetDir"
|
||||
"📂$TargetDir"
|
||||
exit 0
|
||||
15
Powershell/Scripts/cd-onedrive.ps1
Normal file
15
Powershell/Scripts/cd-onedrive.ps1
Normal file
@@ -0,0 +1,15 @@
|
||||
<#
|
||||
.SYNTAX cd-onedrive.ps1
|
||||
.DESCRIPTION go to the user's OneDrive folder
|
||||
.LINK https://github.com/fleschutz/PowerShell
|
||||
.NOTES Author: Markus Fleschutz / License: CC0
|
||||
#>
|
||||
|
||||
$TargetDir = resolve-path "$HOME/OneDrive"
|
||||
if (-not(test-path "$TargetDir" -pathType container)) {
|
||||
write-warning "Sorry, there is no folder 📂$TargetDir (yet)"
|
||||
exit 1
|
||||
}
|
||||
set-location "$TargetDir"
|
||||
"📂$TargetDir"
|
||||
exit 0
|
||||
15
Powershell/Scripts/cd-pics.ps1
Normal file
15
Powershell/Scripts/cd-pics.ps1
Normal file
@@ -0,0 +1,15 @@
|
||||
<#
|
||||
.SYNTAX cd-pics.ps1
|
||||
.DESCRIPTION go to the user's pictures folder
|
||||
.LINK https://github.com/fleschutz/PowerShell
|
||||
.NOTES Author: Markus Fleschutz / License: CC0
|
||||
#>
|
||||
|
||||
$TargetDir = resolve-path "$HOME/Pictures"
|
||||
if (-not(test-path "$TargetDir" -pathType container)) {
|
||||
write-warning "Sorry, there is no folder 📂$TargetDir (yet)"
|
||||
exit 1
|
||||
}
|
||||
set-location "$TargetDir"
|
||||
"📂$TargetDir"
|
||||
exit 0
|
||||
21
Powershell/Scripts/cd-recycle-bin.ps1
Normal file
21
Powershell/Scripts/cd-recycle-bin.ps1
Normal file
@@ -0,0 +1,21 @@
|
||||
<#
|
||||
.SYNTAX cd-recycle-bin.ps1
|
||||
.DESCRIPTION go to the user's recycle bin folder
|
||||
.LINK https://github.com/fleschutz/PowerShell
|
||||
.NOTES Author: Markus Fleschutz / License: CC0
|
||||
#>
|
||||
|
||||
function Get-CurrentUserSID { [CmdletBinding()] param()
|
||||
Add-Type -AssemblyName System.DirectoryServices.AccountManagement
|
||||
return ([System.DirectoryServices.AccountManagement.UserPrincipal]::Current).SID.Value
|
||||
}
|
||||
|
||||
|
||||
$TargetDir = 'C:\$Recycle.Bin\' + "$(Get-CurrentUserSID)"
|
||||
if (-not(test-path "$TargetDir" -pathType container)) {
|
||||
write-warning "Sorry, there is no folder 📂$TargetDir (yet)"
|
||||
exit 1
|
||||
}
|
||||
set-location "$TargetDir"
|
||||
"📂$TargetDir"
|
||||
exit 0
|
||||
15
Powershell/Scripts/cd-repos.ps1
Normal file
15
Powershell/Scripts/cd-repos.ps1
Normal file
@@ -0,0 +1,15 @@
|
||||
<#
|
||||
.SYNTAX cd-repos.ps1
|
||||
.DESCRIPTION go to the user's Git repositories folder
|
||||
.LINK https://github.com/fleschutz/PowerShell
|
||||
.NOTES Author: Markus Fleschutz / License: CC0
|
||||
#>
|
||||
|
||||
$TargetDir = resolve-path "$HOME/Repos"
|
||||
if (-not(test-path "$TargetDir" -pathType container)) {
|
||||
write-warning "Sorry, there is no folder 📂$TargetDir (yet)"
|
||||
exit 1
|
||||
}
|
||||
set-location "$TargetDir"
|
||||
"📂$TargetDir"
|
||||
exit 0
|
||||
19
Powershell/Scripts/cd-root.ps1
Normal file
19
Powershell/Scripts/cd-root.ps1
Normal file
@@ -0,0 +1,19 @@
|
||||
<#
|
||||
.SYNTAX cd-root.ps1
|
||||
.DESCRIPTION go to the root directory (C: on Windows)
|
||||
.LINK https://github.com/fleschutz/PowerShell
|
||||
.NOTES Author: Markus Fleschutz / License: CC0
|
||||
#>
|
||||
|
||||
if ($IsLinux) {
|
||||
$TargetDir = resolve-path "/"
|
||||
} else {
|
||||
$TargetDir = resolve-path "C:/"
|
||||
}
|
||||
if (-not(test-path "$TargetDir" -pathType container)) {
|
||||
write-warning "Sorry, there is no folder 📂$TargetDir (yet)"
|
||||
exit 1
|
||||
}
|
||||
set-location "$TargetDir"
|
||||
"📂$TargetDir"
|
||||
exit 0
|
||||
15
Powershell/Scripts/cd-scripts.ps1
Normal file
15
Powershell/Scripts/cd-scripts.ps1
Normal file
@@ -0,0 +1,15 @@
|
||||
<#
|
||||
.SYNTAX cd-scripts.ps1
|
||||
.DESCRIPTION go to the PowerShell Scripts folder
|
||||
.LINK https://github.com/fleschutz/PowerShell
|
||||
.NOTES Author: Markus Fleschutz / License: CC0
|
||||
#>
|
||||
|
||||
$TargetDir = resolve-path "$PSScriptRoot"
|
||||
if (-not(test-path "$TargetDir" -pathType container)) {
|
||||
write-warning "Sorry, there is no folder 📂$TargetDir (yet)"
|
||||
exit 1
|
||||
}
|
||||
set-location "$TargetDir"
|
||||
"📂$TargetDir"
|
||||
exit 0
|
||||
15
Powershell/Scripts/cd-up.ps1
Normal file
15
Powershell/Scripts/cd-up.ps1
Normal file
@@ -0,0 +1,15 @@
|
||||
<#
|
||||
.SYNTAX cd-up.ps1
|
||||
.DESCRIPTION go one directory level up
|
||||
.LINK https://github.com/fleschutz/PowerShell
|
||||
.NOTES Author: Markus Fleschutz / License: CC0
|
||||
#>
|
||||
|
||||
$TargetDir = resolve-path ".."
|
||||
if (-not(test-path "$TargetDir" -pathType container)) {
|
||||
write-warning "Sorry, there is no folder 📂$TargetDir (yet)"
|
||||
exit 1
|
||||
}
|
||||
set-location "$TargetDir"
|
||||
"📂$TargetDir"
|
||||
exit 0
|
||||
15
Powershell/Scripts/cd-up2.ps1
Normal file
15
Powershell/Scripts/cd-up2.ps1
Normal file
@@ -0,0 +1,15 @@
|
||||
<#
|
||||
.SYNTAX cd-up2.ps1
|
||||
.DESCRIPTION go two directory levels up
|
||||
.LINK https://github.com/fleschutz/PowerShell
|
||||
.NOTES Author: Markus Fleschutz / License: CC0
|
||||
#>
|
||||
|
||||
$TargetDir = resolve-path "../.."
|
||||
if (-not(test-path "$TargetDir" -pathType container)) {
|
||||
write-warning "Sorry, there is no folder 📂$TargetDir (yet)"
|
||||
exit 1
|
||||
}
|
||||
set-location "$TargetDir"
|
||||
"📂$TargetDir"
|
||||
exit 0
|
||||
15
Powershell/Scripts/cd-up3.ps1
Normal file
15
Powershell/Scripts/cd-up3.ps1
Normal file
@@ -0,0 +1,15 @@
|
||||
<#
|
||||
.SYNTAX cd-up3.ps1
|
||||
.DESCRIPTION go three directory levels up
|
||||
.LINK https://github.com/fleschutz/PowerShell
|
||||
.NOTES Author: Markus Fleschutz / License: CC0
|
||||
#>
|
||||
|
||||
$TargetDir = resolve-path "../../.."
|
||||
if (-not(test-path "$TargetDir" -pathType container)) {
|
||||
write-warning "Sorry, there is no folder 📂$TargetDir (yet)"
|
||||
exit 1
|
||||
}
|
||||
set-location "$TargetDir"
|
||||
"📂$TargetDir"
|
||||
exit 0
|
||||
15
Powershell/Scripts/cd-up4.ps1
Normal file
15
Powershell/Scripts/cd-up4.ps1
Normal file
@@ -0,0 +1,15 @@
|
||||
<#
|
||||
.SYNTAX cd-up4.ps1
|
||||
.DESCRIPTION go four directory levels up
|
||||
.LINK https://github.com/fleschutz/PowerShell
|
||||
.NOTES Author: Markus Fleschutz / License: CC0
|
||||
#>
|
||||
|
||||
$TargetDir = resolve-path "../../../.."
|
||||
if (-not(test-path "$TargetDir" -pathType container)) {
|
||||
write-warning "Sorry, there is no folder 📂$TargetDir (yet)"
|
||||
exit 1
|
||||
}
|
||||
set-location "$TargetDir"
|
||||
"📂$TargetDir"
|
||||
exit 0
|
||||
15
Powershell/Scripts/cd-videos.ps1
Normal file
15
Powershell/Scripts/cd-videos.ps1
Normal file
@@ -0,0 +1,15 @@
|
||||
<#
|
||||
.SYNTAX cd-videos.ps1
|
||||
.DESCRIPTION go to the user's videos folder
|
||||
.LINK https://github.com/fleschutz/PowerShell
|
||||
.NOTES Author: Markus Fleschutz / License: CC0
|
||||
#>
|
||||
|
||||
$TargetDir = resolve-path "$HOME/Videos"
|
||||
if (-not(test-path "$TargetDir" -pathType container)) {
|
||||
write-warning "Sorry, there is no folder 📂$TargetDir (yet)"
|
||||
exit 1
|
||||
}
|
||||
set-location "$TargetDir"
|
||||
"📂$TargetDir"
|
||||
exit 0
|
||||
35
Powershell/Scripts/check-cpu-temp.ps1
Normal file
35
Powershell/Scripts/check-cpu-temp.ps1
Normal file
@@ -0,0 +1,35 @@
|
||||
<#
|
||||
.SYNTAX check-cpu-temp.ps1
|
||||
.DESCRIPTION checks the CPU temperature
|
||||
.LINK https://github.com/fleschutz/PowerShell
|
||||
.NOTES Author: Markus Fleschutz / License: CC0
|
||||
#>
|
||||
|
||||
try {
|
||||
if (test-path "/sys/class/thermal/thermal_zone0/temp" -pathType leaf) {
|
||||
[int]$IntTemp = get-content "/sys/class/thermal/thermal_zone0/temp"
|
||||
$Temp = [math]::round($IntTemp / 1000.0, 1)
|
||||
} else {
|
||||
$data = Get-WMIObject -Query "SELECT * FROM Win32_PerfFormattedData_Counters_ThermalZoneInformation" -Namespace "root/CIMV2"
|
||||
$Temp = @($data)[0].HighPrecisionTemperature
|
||||
$Temp = [math]::round($Temp / 100.0, 1)
|
||||
}
|
||||
|
||||
if ($Temp -gt "80") {
|
||||
write-error "⚠️ $Temp °C CPU temperature is too high!"
|
||||
exit 1
|
||||
} elseif ($Temp -lt "-20") {
|
||||
write-error "⚠️ $Temp °C CPU temperature is too low!"
|
||||
exit 1
|
||||
} elseif ($Temp -gt "50") {
|
||||
"✔️ $Temp °C CPU temperature - quite high"
|
||||
} elseif ($Temp -lt "0") {
|
||||
"✔️ $Temp °C CPU temperature - quite low"
|
||||
} else {
|
||||
"✔️ $Temp °C CPU temperature - good"
|
||||
}
|
||||
exit 0
|
||||
} catch {
|
||||
write-error "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
exit 1
|
||||
}
|
||||
32
Powershell/Scripts/check-dns-resolution.ps1
Normal file
32
Powershell/Scripts/check-dns-resolution.ps1
Normal file
@@ -0,0 +1,32 @@
|
||||
<#
|
||||
.SYNTAX check-dns-resolution.ps1
|
||||
.DESCRIPTION checks the DNS resolution with frequently used domain names
|
||||
.LINK https://github.com/fleschutz/PowerShell
|
||||
.NOTES Author: Markus Fleschutz / License: CC0
|
||||
#>
|
||||
|
||||
try {
|
||||
$StopWatch = [system.diagnostics.stopwatch]::startNew()
|
||||
write-progress "Reading Data/domain-names.csv..."
|
||||
|
||||
$PathToRepo = "$PSScriptRoot/.."
|
||||
$Table = import-csv "$PathToRepo/Data/domain-names.csv"
|
||||
|
||||
foreach($Row in $Table) {
|
||||
write-progress "Resolving $($Row.Domain) ..."
|
||||
if ($IsLinux) {
|
||||
$Ignore = nslookup $Row.Domain
|
||||
} else {
|
||||
$Ignore = resolve-dnsName $Row.Domain
|
||||
}
|
||||
}
|
||||
$Count = $Table.Length
|
||||
|
||||
[int]$Elapsed = $StopWatch.Elapsed.TotalSeconds
|
||||
$Average = [math]::round($Count / $Elapsed, 1)
|
||||
"✔️ $Average domains/s ($Count domains resolved in $Elapsed sec)"
|
||||
exit 0
|
||||
} catch {
|
||||
write-error "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
exit 1
|
||||
}
|
||||
27
Powershell/Scripts/check-drive-space.ps1
Normal file
27
Powershell/Scripts/check-drive-space.ps1
Normal file
@@ -0,0 +1,27 @@
|
||||
<#
|
||||
.SYNTAX check-drive-space.ps1 [<drive>] [<min-level>]
|
||||
.DESCRIPTION checks the given drive for free space left
|
||||
.LINK https://github.com/fleschutz/PowerShell
|
||||
.NOTES Author: Markus Fleschutz / License: CC0
|
||||
#>
|
||||
|
||||
param($Drive = "", [int]$MinLevel = 20) # minimum level in GB
|
||||
|
||||
if ($Drive -eq "" ) { $Drive = read-host "Enter drive to check" }
|
||||
|
||||
try {
|
||||
$DriveDetails = (get-psdrive $Drive)
|
||||
[int]$Free = (($DriveDetails.Free / 1024) / 1024) / 1024
|
||||
[int]$Used = (($DriveDetails.Used / 1024) / 1024) / 1024
|
||||
[int]$Total = ($Used + $Free)
|
||||
|
||||
if ($Free -lt $MinLevel) {
|
||||
write-warning "Drive $Drive has only $Free GB left to use! ($Used GB out of $Total GB in use, minimum is $MinLevel GB)"
|
||||
exit 1
|
||||
}
|
||||
"✔️ $Free GB left on drive $Drive ($Used GB of $Total GB used)"
|
||||
exit 0
|
||||
} catch {
|
||||
write-error "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
exit 1
|
||||
}
|
||||
25
Powershell/Scripts/check-file-system.ps1
Normal file
25
Powershell/Scripts/check-file-system.ps1
Normal file
@@ -0,0 +1,25 @@
|
||||
<#
|
||||
.SYNTAX check-file-system.ps1 [<drive>]
|
||||
.DESCRIPTION checks the validity of the file system (needs admin rights)
|
||||
.LINK https://github.com/fleschutz/PowerShell
|
||||
.NOTES Author: Markus Fleschutz / License: CC0
|
||||
#>
|
||||
|
||||
#Requires -RunAsAdministrator
|
||||
|
||||
param($Drive = "")
|
||||
|
||||
if ($Drive -eq "" ) {
|
||||
$Drive = read-host "Enter drive (letter) to check"
|
||||
}
|
||||
|
||||
try {
|
||||
$Result = repair-volume -driveLetter $Drive -scan
|
||||
if ($Result -ne "NoErrorsFound") { throw "'repair-volume' failed" }
|
||||
|
||||
write-host -foregroundColor green "✔️ file system on drive $Drive is clean"
|
||||
exit 0
|
||||
} catch {
|
||||
write-error "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
exit 1
|
||||
}
|
||||
38
Powershell/Scripts/check-health.ps1
Normal file
38
Powershell/Scripts/check-health.ps1
Normal file
@@ -0,0 +1,38 @@
|
||||
<#
|
||||
.SYNTAX check-health.ps1
|
||||
.DESCRIPTION checks the health of the local computer
|
||||
.LINK https://github.com/fleschutz/PowerShell
|
||||
.NOTES Author: Markus Fleschutz / License: CC0
|
||||
#>
|
||||
|
||||
$Hostname = $(hostname)
|
||||
$Healthy = 1
|
||||
"Checking health of $Hostname ..."
|
||||
|
||||
& "$PSScriptRoot/check-swap-space.ps1"
|
||||
if ($lastExitCode -ne "0") { $Healthy = 0 }
|
||||
|
||||
if ($IsLinux) {
|
||||
& "$PSScriptRoot/check-drive-space.ps1" /
|
||||
if ($lastExitCode -ne "0") { $Healthy = 0 }
|
||||
} else {
|
||||
& "$PSScriptRoot/check-drive-space.ps1" C
|
||||
if ($lastExitCode -ne "0") { $Healthy = 0 }
|
||||
}
|
||||
|
||||
& "$PSScriptRoot/check-cpu-temp.ps1"
|
||||
if ($lastExitCode -ne "0") { $Healthy = 0 }
|
||||
|
||||
& "$PSScriptRoot/check-dns-resolution.ps1"
|
||||
if ($lastExitCode -ne "0") { $Healthy = 0 }
|
||||
|
||||
& "$PSScriptRoot/check-ping.ps1"
|
||||
if ($lastExitCode -ne "0") { $Healthy = 0 }
|
||||
|
||||
if ($Healthy) {
|
||||
"✔️ $Hostname is healthy"
|
||||
exit 0
|
||||
} else {
|
||||
write-warning "$Hostname is NOT healthy"
|
||||
exit 1
|
||||
}
|
||||
33
Powershell/Scripts/check-ipv4-address.ps1
Normal file
33
Powershell/Scripts/check-ipv4-address.ps1
Normal file
@@ -0,0 +1,33 @@
|
||||
<#
|
||||
.SYNTAX check-ipv4-address.ps1 [<address>]
|
||||
.DESCRIPTION checks the given IPv4 address for validity
|
||||
.LINK https://github.com/fleschutz/PowerShell
|
||||
.NOTES Author: Markus Fleschutz / License: CC0
|
||||
#>
|
||||
|
||||
param($Address = "")
|
||||
|
||||
function IsIPv4AddressValid { param([string]$IP)
|
||||
$RegEx = "^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$"
|
||||
if ($IP -match $RegEx) {
|
||||
return $true
|
||||
} else {
|
||||
return $false
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
if ($Address -eq "" ) {
|
||||
$Address = read-host "Enter IPv4 address to validate"
|
||||
}
|
||||
if (IsIPv4AddressValid $Address) {
|
||||
write-host -foregroundColor green "OK - IPv4 address $Address is valid"
|
||||
exit 0
|
||||
} else {
|
||||
write-warning "Invalid IPv4 address: $Address"
|
||||
exit 1
|
||||
}
|
||||
} catch {
|
||||
write-error "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
exit 1
|
||||
}
|
||||
46
Powershell/Scripts/check-ipv6-address.ps1
Normal file
46
Powershell/Scripts/check-ipv6-address.ps1
Normal file
@@ -0,0 +1,46 @@
|
||||
<#
|
||||
.SYNTAX check-ipv6-address.ps1 [<address>]
|
||||
.DESCRIPTION checks the given IPv6 address for validity
|
||||
.LINK https://github.com/fleschutz/PowerShell
|
||||
.NOTES Author: Markus Fleschutz / License: CC0
|
||||
#>
|
||||
|
||||
param($Address = "")
|
||||
|
||||
function IsIPv6AddressValid { param([string]$IP)
|
||||
$IPv4Regex = '(((25[0-5]|2[0-4][0-9]|[0-1]?[0-9]{1,2})\.){3}(25[0-5]|2[0-4][0-9]|[0-1]?[0-9]{1,2}))'
|
||||
$G = '[a-f\d]{1,4}'
|
||||
$Tail = @(":",
|
||||
"(:($G)?|$IPv4Regex)",
|
||||
":($IPv4Regex|$G(:$G)?|)",
|
||||
"(:$IPv4Regex|:$G(:$IPv4Regex|(:$G){0,2})|:)",
|
||||
"((:$G){0,2}(:$IPv4Regex|(:$G){1,2})|:)",
|
||||
"((:$G){0,3}(:$IPv4Regex|(:$G){1,2})|:)",
|
||||
"((:$G){0,4}(:$IPv4Regex|(:$G){1,2})|:)")
|
||||
[string] $IPv6RegexString = $G
|
||||
$Tail | foreach { $IPv6RegexString = "${G}:($IPv6RegexString|$_)" }
|
||||
$IPv6RegexString = ":(:$G){0,5}((:$G){1,2}|:$IPv4Regex)|$IPv6RegexString"
|
||||
$IPv6RegexString = $IPv6RegexString -replace '\(' , '(?:' # make all groups non-capturing
|
||||
[regex] $IPv6Regex = $IPv6RegexString
|
||||
if ($IP -imatch "^$IPv6Regex$") {
|
||||
return $true
|
||||
} else {
|
||||
return $false
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
if ($Address -eq "" ) {
|
||||
$Address = read-host "Enter IPv6 address to validate"
|
||||
}
|
||||
if (IsIPv6AddressValid $Address) {
|
||||
write-host -foregroundColor green "OK - IPv6 address $Address is valid"
|
||||
exit 0
|
||||
} else {
|
||||
write-warning "Invalid IPv6 address: $Address"
|
||||
exit 1
|
||||
}
|
||||
} catch {
|
||||
write-error "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
exit 1
|
||||
}
|
||||
34
Powershell/Scripts/check-mac-address.ps1
Normal file
34
Powershell/Scripts/check-mac-address.ps1
Normal file
@@ -0,0 +1,34 @@
|
||||
<#
|
||||
.SYNTAX check-mac-address.ps1 [<MAC>]
|
||||
.DESCRIPTION checks the given MAC address for validity
|
||||
MAC address like 00:00:00:00:00:00 or 00-00-00-00-00-00 or 000000000000
|
||||
.LINK https://github.com/fleschutz/PowerShell
|
||||
.NOTES Author: Markus Fleschutz / License: CC0
|
||||
#>
|
||||
|
||||
param($MAC = "")
|
||||
|
||||
function IsMACAddressValid { param([string]$mac)
|
||||
$RegEx = "^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})|([0-9A-Fa-f]{2}){6}$"
|
||||
if ($mac -match $RegEx) {
|
||||
return $true
|
||||
} else {
|
||||
return $false
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
if ($MAC -eq "" ) {
|
||||
$MAC = read-host "Enter MAC address to validate"
|
||||
}
|
||||
if (IsMACAddressValid $MAC) {
|
||||
write-host -foregroundColor green "OK - MAC address $MAC is valid"
|
||||
exit 0
|
||||
} else {
|
||||
write-warning "Invalid MAC address: $MAC"
|
||||
exit 1
|
||||
}
|
||||
} catch {
|
||||
write-error "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
exit 1
|
||||
}
|
||||
32
Powershell/Scripts/check-ping.ps1
Normal file
32
Powershell/Scripts/check-ping.ps1
Normal file
@@ -0,0 +1,32 @@
|
||||
<#
|
||||
.SYNTAX check-ping.ps1
|
||||
.DESCRIPTION checks the ping latency to the internet
|
||||
.LINK https://github.com/fleschutz/PowerShell
|
||||
.NOTES Author: Markus Fleschutz / License: CC0
|
||||
#>
|
||||
|
||||
try {
|
||||
write-verbose "Sending pings to the internet ..."
|
||||
$Pings = test-connection -count 1 -computerName heise.de,cnn.com,github.com,www.microsoft.com,dropbox.com,amazon.com,google.com,bing.com,youtube.com
|
||||
|
||||
[int]$Min = 9999999
|
||||
[int]$Max = 0
|
||||
[int]$Avg = 0
|
||||
foreach($Ping in $Pings) {
|
||||
if ($IsLinux) {
|
||||
[int]$Latency = $Ping.latency
|
||||
} else {
|
||||
[int]$Latency = $Ping.ResponseTime
|
||||
}
|
||||
if ($Latency -lt $Min) { $Min = $Latency }
|
||||
if ($Latency -gt $Max) { $Max = $Latency }
|
||||
$Avg += $Latency
|
||||
}
|
||||
$Avg = $Avg / $Pings.count
|
||||
|
||||
"✔️ $Avg ms average ping latency ($Min ms min, $Max ms max)"
|
||||
exit 0
|
||||
} catch {
|
||||
write-error "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
exit 1
|
||||
}
|
||||
38
Powershell/Scripts/check-swap-space.ps1
Normal file
38
Powershell/Scripts/check-swap-space.ps1
Normal file
@@ -0,0 +1,38 @@
|
||||
<#
|
||||
.SYNTAX check-swap-space.ps1 [<min-level>]
|
||||
.DESCRIPTION checks the free swap space
|
||||
.LINK https://github.com/fleschutz/PowerShell
|
||||
.NOTES Author: Markus Fleschutz / License: CC0
|
||||
#>
|
||||
|
||||
param([int]$MinLevel = 50) # minimum level in GB
|
||||
|
||||
try {
|
||||
if ($IsLinux) {
|
||||
$Result = $(free --mega | grep Swap:)
|
||||
[int]$Total = $Result.subString(5,14)
|
||||
[int]$Used = $Result.substring(20,13)
|
||||
[int]$Free = $Result.substring(31,12)
|
||||
} else {
|
||||
$Items = get-wmiobject -class "Win32_PageFileUsage" -namespace "root\CIMV2" -computername localhost
|
||||
foreach ($Item in $Items) {
|
||||
[int]$Total = $Item.AllocatedBaseSize
|
||||
[int]$Used = $Item.CurrentUsage
|
||||
[int]$Free = ($Total - $Used)
|
||||
}
|
||||
}
|
||||
|
||||
if ($Total -eq "0") {
|
||||
write-warning "No swap space configured!"
|
||||
exit 1
|
||||
}
|
||||
if ($Free -lt $MinLevel) {
|
||||
write-warning "Swap space has only $Free GB left to use! ($Used GB out of $Total GB in use, minimum is $MinLevel GB)"
|
||||
exit 1
|
||||
}
|
||||
"✔️ $Free GB left on swap space ($Used GB of $Total GB used)"
|
||||
exit 0
|
||||
} catch {
|
||||
write-error "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
exit 1
|
||||
}
|
||||
35
Powershell/Scripts/check-symlinks.ps1
Normal file
35
Powershell/Scripts/check-symlinks.ps1
Normal file
@@ -0,0 +1,35 @@
|
||||
<#
|
||||
.SYNTAX check-symlinks.ps1 [<dir-tree>]
|
||||
.DESCRIPTION checks every symlink in the given directory tree
|
||||
.LINK https://github.com/fleschutz/PowerShell
|
||||
.NOTES Author: Markus Fleschutz / License: CC0
|
||||
#>
|
||||
|
||||
param($DirTree = "")
|
||||
|
||||
if ($DirTree -eq "" ) {
|
||||
$DirTree = read-host "Enter the path to the directory tree"
|
||||
}
|
||||
|
||||
try {
|
||||
write-progress "Checking symlinks in $DirTree..."
|
||||
[int]$SymlinksTotal = [int]$SymlinksBroken = 0
|
||||
Get-ChildItem $DirTree -recurse | Where { $_.Attributes -match "ReparsePoint" } | ForEach-Object {
|
||||
$Symlink = $_.FullName
|
||||
$Target = ($_ | Select-Object -ExpandProperty Target -ErrorAction Ignore)
|
||||
if ($Target) {
|
||||
$path = $_.FullName + "\..\" + ($_ | Select-Object -ExpandProperty Target)
|
||||
$item = Get-Item $path -ErrorAction Ignore
|
||||
if (!$item) {
|
||||
write-warning "Broken symlink: $Symlink -> $Target"
|
||||
$SymlinksBroken++
|
||||
}
|
||||
}
|
||||
$SymlinksTotal++
|
||||
}
|
||||
write-host -foregroundColor green "OK - found $SymlinksTotal symlinks total, $SymlinksBroken symlinks are broken"
|
||||
exit $SymlinksBroken
|
||||
} catch {
|
||||
write-error "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
exit 1
|
||||
}
|
||||
51
Powershell/Scripts/check-weather.ps1
Normal file
51
Powershell/Scripts/check-weather.ps1
Normal file
@@ -0,0 +1,51 @@
|
||||
<#
|
||||
.SYNTAX check-weather.ps1 [<location>]
|
||||
.DESCRIPTION checks the weather for critical values
|
||||
.LINK https://github.com/fleschutz/PowerShell
|
||||
.NOTES Author: Markus Fleschutz / License: CC0
|
||||
#>
|
||||
|
||||
param($Location = "") # empty means determine automatically
|
||||
|
||||
function Check { param([int]$Value, [int]$NormalMin, [int]$NormalMax, [string]$Unit)
|
||||
if ($Value -lt $NormalMin) {
|
||||
return "$Value $Unit ! "
|
||||
}
|
||||
if ($Value -gt $NormalMax) {
|
||||
return "$Value $Unit ! "
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
try {
|
||||
$Weather = (Invoke-WebRequest http://wttr.in/${Location}?format=j1 -UserAgent "curl" ).Content | ConvertFrom-Json
|
||||
|
||||
$Temp = $Weather.current_condition.temp_C
|
||||
$Precip = $Weather.current_condition.precipMM
|
||||
$Humidity = $Weather.current_condition.humidity
|
||||
$Pressure = $Weather.current_condition.pressure
|
||||
$WindSpeed = $Weather.current_condition.windspeedKmph
|
||||
$WindDir = $Weather.current_condition.winddir16Point
|
||||
$UV = $Weather.current_condition.uvIndex
|
||||
$Visib = $Weather.current_condition.visibility
|
||||
$Clouds = $Weather.current_condition.cloudcover
|
||||
$Desc = $Weather.current_condition.weatherDesc.value
|
||||
$Area = $Weather.nearest_area.areaName.value
|
||||
$Region = $Weather.nearest_area.region.value
|
||||
"Now: $($Temp)°C $($Precip)mm $($Humidity)% $($WindSpeed)km/h from $WindDir $($Pressure)hPa UV$($UV) $($Visib)km $($Clouds)% $Desc at $Area ($Region)"
|
||||
|
||||
$Result+=Check $Weather.current_condition.windspeedKmph 0 48 "km/h"
|
||||
$Result+=Check $Weather.current_condition.visibility 1 1000 "km visibility"
|
||||
$Result+=Check $Weather.current_condition.temp_C -20 40 "°C"
|
||||
$Result+=Check $Weather.current_condition.uvIndex 0 6 "UV"
|
||||
|
||||
if ($Result -eq "") {
|
||||
"Calm weather"
|
||||
} else {
|
||||
"WEATHER ALERT: $Result"
|
||||
}
|
||||
exit 0
|
||||
} catch {
|
||||
write-error "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
exit 1
|
||||
}
|
||||
19
Powershell/Scripts/check-windows-system-files.ps1
Normal file
19
Powershell/Scripts/check-windows-system-files.ps1
Normal file
@@ -0,0 +1,19 @@
|
||||
<#
|
||||
.SYNTAX check-windows-system-files.ps1
|
||||
.DESCRIPTION checks the validity of the Windows system files (requires admin rights)
|
||||
.LINK https://github.com/fleschutz/PowerShell
|
||||
.NOTES Author: Markus Fleschutz / License: CC0
|
||||
#>
|
||||
|
||||
#Requires -RunAsAdministrator
|
||||
|
||||
try {
|
||||
sfc /verifyOnly
|
||||
if ($lastExitCode -ne "0") { throw "'sfc /verifyOnly' failed" }
|
||||
|
||||
write-host -foregroundColor green "✔️ checked Windows system files"
|
||||
exit 0
|
||||
} catch {
|
||||
write-error "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
exit 1
|
||||
}
|
||||
37
Powershell/Scripts/check-xml-file.ps1
Normal file
37
Powershell/Scripts/check-xml-file.ps1
Normal file
@@ -0,0 +1,37 @@
|
||||
<#
|
||||
.SYNTAX check-xml-file [<file>]
|
||||
.DESCRIPTION checks the given XML file for validity
|
||||
.LINK https://github.com/fleschutz/PowerShell
|
||||
.NOTES Author: Markus Fleschutz / License: CC0
|
||||
#>
|
||||
|
||||
param($File = "")
|
||||
|
||||
if ($File -eq "" ) {
|
||||
$File = read-host "Enter path to XML file"
|
||||
}
|
||||
|
||||
try {
|
||||
$XmlFile = Get-Item $File
|
||||
|
||||
$script:ErrorCount = 0
|
||||
|
||||
# Perform the XSD Validation
|
||||
$ReaderSettings = New-Object -TypeName System.Xml.XmlReaderSettings
|
||||
$ReaderSettings.ValidationType = [System.Xml.ValidationType]::Schema
|
||||
$ReaderSettings.ValidationFlags = [System.Xml.Schema.XmlSchemaValidationFlags]::ProcessInlineSchema -bor [System.Xml.Schema.XmlSchemaValidationFlags]::ProcessSchemaLocation
|
||||
$ReaderSettings.add_ValidationEventHandler({ $script:ErrorCount++ })
|
||||
$Reader = [System.Xml.XmlReader]::Create($XmlFile.FullName, $ReaderSettings)
|
||||
while ($Reader.Read()) { }
|
||||
$Reader.Close()
|
||||
|
||||
if ($script:ErrorCount -gt 0) {
|
||||
write-warning "Invalid XML file"
|
||||
exit 1
|
||||
}
|
||||
write-host -foregroundColor green "OK - XML file is valid"
|
||||
exit 0
|
||||
} catch {
|
||||
write-error "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
exit 1
|
||||
}
|
||||
58
Powershell/Scripts/cherry-picker.ps1
Normal file
58
Powershell/Scripts/cherry-picker.ps1
Normal file
@@ -0,0 +1,58 @@
|
||||
<#
|
||||
.SYNTAX cherry-picker.ps1 [<commit-id>] [<commit-message>] [<branches>] [<repo-dir>]
|
||||
.DESCRIPTION cherry-picks a Git commit into multiple branches
|
||||
.LINK https://github.com/fleschutz/PowerShell
|
||||
.NOTES Author: Markus Fleschutz / License: CC0
|
||||
#>
|
||||
|
||||
param($CommitID = "", $CommitMessage = "", $Branches = "", $RepoDir = "$PWD")
|
||||
|
||||
if ($CommitID -eq "" ) { $CommitID = read-host "Enter the commit id to cherry-pick" }
|
||||
if ($CommitMessage -eq "" ) { $CommitMessage = read-host "Enter the commit message to use" }
|
||||
if ($Branches -eq "" ) { $Branches = read-host "Enter the target branches" }
|
||||
|
||||
try {
|
||||
if (-not(test-path "$RepoDir" -pathType container)) { throw "Can't access directory: $RepoDir" }
|
||||
set-location "$RepoDir"
|
||||
|
||||
foreach($Branch in $Branches) {
|
||||
|
||||
"STEP: Switching to branch $Branch (git checkout)..."
|
||||
& git checkout --recurse-submodules --force $Branch
|
||||
if ($lastExitCode -ne "0") { throw "'git checkout' failed" }
|
||||
|
||||
"STEP: Updating submodules (git submodule update)..."
|
||||
& git submodule update --init --recursive
|
||||
if ($lastExitCode -ne "0") { throw "'git submodule update' failed" }
|
||||
|
||||
"STEP: Cleaning the repository (git clean -fdx)..."
|
||||
& git clean -fdx
|
||||
if ($lastExitCode -ne "0") { throw "'git clean -fdx' failed" }
|
||||
|
||||
& git submodule foreach --recursive git clean -fdx
|
||||
if ($lastExitCode -ne "0") { throw "'git clean -fdx' in submodules failed" }
|
||||
|
||||
"STEP: Pulling latest updates (git pull)..."
|
||||
& git pull --recurse-submodules
|
||||
if ($lastExitCode -ne "0") { throw "'git pull' failed" }
|
||||
|
||||
"STEP: Checking the status (git status)..."
|
||||
$Result = (git status)
|
||||
if ($lastExitCode -ne "0") { throw "'git status' failed" }
|
||||
if ("$Result" -notmatch "nothing to commit, working tree clean") { throw "Branch is NOT clean: $Result" }
|
||||
|
||||
& git cherry-pick --no-commit "$CommitID"
|
||||
if ($lastExitCode -ne "0") { throw "'git cherry-pick $CommitID' failed" }
|
||||
|
||||
& git commit -m "$CommitMessage"
|
||||
if ($lastExitCode -ne "0") { throw "'git commit' failed" }
|
||||
|
||||
& git push
|
||||
if ($lastExitCode -ne "0") { throw "'git push' failed" }
|
||||
}
|
||||
"DONE."
|
||||
exit 0
|
||||
} catch {
|
||||
write-error "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
exit 1
|
||||
}
|
||||
33
Powershell/Scripts/clean-repo.ps1
Normal file
33
Powershell/Scripts/clean-repo.ps1
Normal file
@@ -0,0 +1,33 @@
|
||||
<#
|
||||
.SYNTAX clean-repo.ps1 [<repo-dir>]
|
||||
.DESCRIPTION cleans a Git repository from untracked files (including submodules, e.g. for a fresh build)
|
||||
.LINK https://github.com/fleschutz/PowerShell
|
||||
.NOTES Author: Markus Fleschutz / License: CC0
|
||||
#>
|
||||
|
||||
param($RepoDir = "$PWD")
|
||||
|
||||
try {
|
||||
$StopWatch = [system.diagnostics.stopwatch]::startNew()
|
||||
|
||||
if (-not(test-path "$RepoDir" -pathType container)) { throw "Can't access directory: $RepoDir" }
|
||||
$RepoDirName = (get-item "$RepoDir").Name
|
||||
|
||||
"🧹 Cleaning Git repository 📂$RepoDirName from untracked files..."
|
||||
|
||||
$Null = (git --version)
|
||||
if ($lastExitCode -ne "0") { throw "Can't execute 'git' - make sure Git is installed and available" }
|
||||
|
||||
& git -C "$RepoDir" clean -xfd -f # force + recurse into dirs + don't use the standard ignore rules
|
||||
if ($lastExitCode -ne "0") { throw "'git clean -xfd -f' failed" }
|
||||
|
||||
& git -C "$RepoDir" submodule foreach --recursive git clean -xfd -f
|
||||
if ($lastExitCode -ne "0") { throw "'git clean -xfd -f' in submodules failed" }
|
||||
|
||||
[int]$Elapsed = $StopWatch.Elapsed.TotalSeconds
|
||||
"✔️ cleaned Git repository 📂$RepoDirName in $Elapsed sec"
|
||||
exit 0
|
||||
} catch {
|
||||
write-error "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
exit 1
|
||||
}
|
||||
43
Powershell/Scripts/clean-repos.ps1
Normal file
43
Powershell/Scripts/clean-repos.ps1
Normal file
@@ -0,0 +1,43 @@
|
||||
<#
|
||||
.SYNTAX clean-repos.ps1 [<parent-dir>]
|
||||
.DESCRIPTION cleans all Git repositories under the current/given directory from untracked files (including submodules)
|
||||
.LINK https://github.com/fleschutz/PowerShell
|
||||
.NOTES Author: Markus Fleschutz / License: CC0
|
||||
#>
|
||||
|
||||
param($ParentDir = "$PWD")
|
||||
|
||||
try {
|
||||
$StopWatch = [system.diagnostics.stopwatch]::startNew()
|
||||
|
||||
if (-not(test-path "$ParentDir" -pathType container)) { throw "Can't access directory: $ParentDir" }
|
||||
|
||||
$Null = (git --version)
|
||||
if ($lastExitCode -ne "0") { throw "Can't execute 'git' - make sure Git is installed and available" }
|
||||
|
||||
$Folders = (get-childItem "$ParentDir" -attributes Directory)
|
||||
$FolderCount = $Folders.Count
|
||||
$ParentDirName = (get-item "$ParentDir").Name
|
||||
"Found $FolderCount subfolders in 📂$ParentDirName, cleaning from untracked files..."
|
||||
|
||||
[int]$Step = 1
|
||||
foreach ($Folder in $Folders) {
|
||||
$FolderName = (get-item "$Folder").Name
|
||||
"🧹 Cleaning 📂$FolderName ($Step/$FolderCount)..."
|
||||
|
||||
& git -C "$Folder" clean -xfd -f # force + recurse into dirs + don't use the standard ignore rules
|
||||
if ($lastExitCode -ne "0") { throw "'git clean -xfd -f' failed" }
|
||||
|
||||
& git -C "$Folder" submodule foreach --recursive git clean -xfd -f
|
||||
if ($lastExitCode -ne "0") { throw "'git clean -xfd -f' in submodules failed" }
|
||||
|
||||
$Step++
|
||||
}
|
||||
|
||||
[int]$Elapsed = $StopWatch.Elapsed.TotalSeconds
|
||||
"✔️ cleaned $FolderCount Git repositories at 📂$ParentDirName in $Elapsed sec"
|
||||
exit 0
|
||||
} catch {
|
||||
write-error "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
exit 1
|
||||
}
|
||||
15
Powershell/Scripts/clear-recycle-bin.ps1
Normal file
15
Powershell/Scripts/clear-recycle-bin.ps1
Normal file
@@ -0,0 +1,15 @@
|
||||
<#
|
||||
.SYNTAX clear-recycle-bin.ps1
|
||||
.DESCRIPTION removes the content of the recycle bin folder (can not be undo!)
|
||||
.LINK https://github.com/fleschutz/PowerShell
|
||||
.NOTES Author: Markus Fleschutz / License: CC0
|
||||
#>
|
||||
|
||||
try {
|
||||
Clear-RecycleBin -Confirm:$false
|
||||
"✔️ recycle bin have been emptied"
|
||||
exit 0
|
||||
} catch {
|
||||
write-error "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
exit 1
|
||||
}
|
||||
49
Powershell/Scripts/clone-repos.ps1
Normal file
49
Powershell/Scripts/clone-repos.ps1
Normal file
@@ -0,0 +1,49 @@
|
||||
<#
|
||||
.SYNTAX clone-repos.ps1 [<parent-dir>]
|
||||
.DESCRIPTION clones well-known Git repositories under the current/given directory.
|
||||
.LINK https://github.com/fleschutz/PowerShell
|
||||
.NOTES Author: Markus Fleschutz / License: CC0
|
||||
#>
|
||||
|
||||
param($ParentDir = "$PWD")
|
||||
|
||||
try {
|
||||
$StopWatch = [system.diagnostics.stopwatch]::startNew()
|
||||
|
||||
if (-not(test-path "$ParentDir" -pathType container)) { throw "Can't access directory: $ParentDir" }
|
||||
|
||||
$Null = (git --version)
|
||||
if ($lastExitCode -ne "0") { throw "Can't execute 'git' - make sure Git is installed and available" }
|
||||
|
||||
$Table = import-csv "$PSScriptRoot/../Data/git-repos.csv"
|
||||
$TableCount = $Table.count
|
||||
"Found $TableCount entries in Data/git-repos.csv database..."
|
||||
|
||||
[int]$Count = 0
|
||||
foreach($Row in $Table) {
|
||||
[string]$FolderName = $Row.FolderName
|
||||
[string]$Branch = $Row.Branch
|
||||
[string]$Shallow = $Row.Shallow
|
||||
[string]$URL = $Row.URL
|
||||
|
||||
if (test-path "$ParentDir/$FolderName" -pathType container) {
|
||||
"📂$FolderName exists, skipping..."
|
||||
continue
|
||||
}
|
||||
if ($Shallow -eq "yes") {
|
||||
"🢃 Cloning to 📂$FolderName, $Branch branch, shallow..."
|
||||
& git clone --branch "$Branch" --depth 1 --shallow-submodules --recurse-submodules "$URL" "$ParentDir/$FolderName"
|
||||
} else {
|
||||
"🢃 Cloning to 📂$FolderName, $Branch branch, full history..."
|
||||
& git clone --branch "$Branch" --recurse-submodules "$URL" "$ParentDir/$FolderName"
|
||||
}
|
||||
if ($lastExitCode -ne "0") { throw "'git clone $URL' failed" }
|
||||
$Count++
|
||||
}
|
||||
[int]$Elapsed = $StopWatch.Elapsed.TotalSeconds
|
||||
"✔️ cloned $Count Git repositories at 📂$ParentDir in $Elapsed sec"
|
||||
exit 0
|
||||
} catch {
|
||||
write-error "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
exit 1
|
||||
}
|
||||
9
Powershell/Scripts/close-calculator.ps1
Normal file
9
Powershell/Scripts/close-calculator.ps1
Normal file
@@ -0,0 +1,9 @@
|
||||
<#
|
||||
.SYNTAX close-calculator.ps1
|
||||
.DESCRIPTION closes the calculator program gracefully
|
||||
.LINK https://github.com/fleschutz/PowerShell
|
||||
.NOTES Author: Markus Fleschutz / License: CC0
|
||||
#>
|
||||
|
||||
& "$PSScriptRoot/close-program.ps1" "Calculator" "Calculator" "calc"
|
||||
exit 0
|
||||
9
Powershell/Scripts/close-chrome.ps1
Normal file
9
Powershell/Scripts/close-chrome.ps1
Normal file
@@ -0,0 +1,9 @@
|
||||
<#
|
||||
.SYNTAX close-chrome.ps1
|
||||
.DESCRIPTION closes Google Chrome gracefully
|
||||
.LINK https://github.com/fleschutz/PowerShell
|
||||
.NOTES Author: Markus Fleschutz / License: CC0
|
||||
#>
|
||||
|
||||
& "$PSScriptRoot/close-program.ps1" "Google Chrome" "chrome" "chrome"
|
||||
exit 0
|
||||
9
Powershell/Scripts/close-cortana.ps1
Normal file
9
Powershell/Scripts/close-cortana.ps1
Normal file
@@ -0,0 +1,9 @@
|
||||
<#
|
||||
.SYNTAX close-cortana.ps1
|
||||
.DESCRIPTION closes Cortana gracefully
|
||||
.LINK https://github.com/fleschutz/PowerShell
|
||||
.NOTES Author: Markus Fleschutz / License: CC0
|
||||
#>
|
||||
|
||||
& "$PSScriptRoot/close-program.ps1" "Cortana" "Cortana" "Cortana"
|
||||
exit 0
|
||||
9
Powershell/Scripts/close-edge.ps1
Normal file
9
Powershell/Scripts/close-edge.ps1
Normal file
@@ -0,0 +1,9 @@
|
||||
<#
|
||||
.SYNTAX close-edge.ps1
|
||||
.DESCRIPTION closes Microsoft Edge gracefully
|
||||
.LINK https://github.com/fleschutz/PowerShell
|
||||
.NOTES Author: Markus Fleschutz / License: CC0
|
||||
#>
|
||||
|
||||
& "$PSScriptRoot/close-program.ps1" "Microsoft Edge" "msedge" "msedge"
|
||||
exit 0
|
||||
9
Powershell/Scripts/close-file-explorer.ps1
Normal file
9
Powershell/Scripts/close-file-explorer.ps1
Normal file
@@ -0,0 +1,9 @@
|
||||
<#
|
||||
.SYNTAX close-file-explorer.ps1
|
||||
.DESCRIPTION closes Microsoft File Explorer gracefully
|
||||
.LINK https://github.com/fleschutz/PowerShell
|
||||
.NOTES Author: Markus Fleschutz / License: CC0
|
||||
#>
|
||||
|
||||
& "$PSScriptRoot/close-program.ps1" "File Explorer" "explorer" "explorer"
|
||||
exit 0
|
||||
43
Powershell/Scripts/close-program.ps1
Normal file
43
Powershell/Scripts/close-program.ps1
Normal file
@@ -0,0 +1,43 @@
|
||||
<#
|
||||
.SYNTAX close-program.ps1 [<full-program-name>] [<program-name>] [<program-alias-name>]
|
||||
.DESCRIPTION closes the processes of the given program gracefully
|
||||
.LINK https://github.com/fleschutz/PowerShell
|
||||
.NOTES Author: Markus Fleschutz / License: CC0
|
||||
#>
|
||||
|
||||
param($FullProgramName = "", $ProgramName = "", $ProgramAliasName = "")
|
||||
|
||||
if ($ProgramName -eq "") {
|
||||
get-process | where-object {$_.mainWindowTitle} | format-table Id, Name, mainWindowtitle -AutoSize
|
||||
$ProgramName = read-host "Enter program name"
|
||||
}
|
||||
if ($FullProgramName -eq "") {
|
||||
$FullProgramName = $ProgramName
|
||||
}
|
||||
|
||||
try {
|
||||
$Processes = get-process -name $ProgramName -errorAction 'silentlycontinue'
|
||||
if ($Processes.Count -ne 0) {
|
||||
foreach ($Process in $Processes) {
|
||||
$Process.CloseMainWindow() | Out-Null
|
||||
}
|
||||
start-sleep -milliseconds 100
|
||||
stop-process -name $ProgramName -force -errorAction 'silentlycontinue'
|
||||
} else {
|
||||
|
||||
$Processes = get-process -name $ProgramAliasName -errorAction 'silentlycontinue'
|
||||
if ($Processes.Count -eq 0) {
|
||||
throw "$FullProgramName is not started yet"
|
||||
}
|
||||
foreach ($Process in $Processes) {
|
||||
$_.CloseMainWindow() | Out-Null
|
||||
}
|
||||
start-sleep -milliseconds 100
|
||||
stop-process -name $ProgramName -force -errorAction 'silentlycontinue'
|
||||
}
|
||||
write-host -foregroundColor green "✔️ closed $FullProgramName, found ($($Processes.Count) process(es)"
|
||||
exit 0
|
||||
} catch {
|
||||
write-error "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
exit 1
|
||||
}
|
||||
9
Powershell/Scripts/close-system-settings.ps1
Normal file
9
Powershell/Scripts/close-system-settings.ps1
Normal file
@@ -0,0 +1,9 @@
|
||||
<#
|
||||
.SYNTAX close-system-settings.ps1
|
||||
.DESCRIPTION closes the System Settings gracefully
|
||||
.LINK https://github.com/fleschutz/PowerShell
|
||||
.NOTES Author: Markus Fleschutz / License: CC0
|
||||
#>
|
||||
|
||||
& "$PSScriptRoot/close-program.ps1" "System Settings" "SystemSettings" "SystemSettings"
|
||||
exit 0
|
||||
9
Powershell/Scripts/close-thunderbird.ps1
Normal file
9
Powershell/Scripts/close-thunderbird.ps1
Normal file
@@ -0,0 +1,9 @@
|
||||
<#
|
||||
.SYNTAX close-thunderbird.ps1
|
||||
.DESCRIPTION closes Mozilla Thunderbird gracefully
|
||||
.LINK https://github.com/fleschutz/PowerShell
|
||||
.NOTES Author: Markus Fleschutz / License: CC0
|
||||
#>
|
||||
|
||||
& "$PSScriptRoot/close-program.ps1" "Mozilla Thunderbird" "thunderbird" "thunderbird"
|
||||
exit 0
|
||||
9
Powershell/Scripts/close-vlc.ps1
Normal file
9
Powershell/Scripts/close-vlc.ps1
Normal file
@@ -0,0 +1,9 @@
|
||||
<#
|
||||
.SYNTAX close-vlc.ps1
|
||||
.DESCRIPTION closes the VLC media player gracefully
|
||||
.LINK https://github.com/fleschutz/PowerShell
|
||||
.NOTES Author: Markus Fleschutz / License: CC0
|
||||
#>
|
||||
|
||||
& "$PSScriptRoot/close-program.ps1" "VLC media player" "vlc" "vlc"
|
||||
exit 0
|
||||
9
Powershell/Scripts/close-windows-terminal.ps1
Normal file
9
Powershell/Scripts/close-windows-terminal.ps1
Normal file
@@ -0,0 +1,9 @@
|
||||
<#
|
||||
.SYNTAX close-windows-terminal.ps1
|
||||
.DESCRIPTION closes Windows Terminal gracefully
|
||||
.LINK https://github.com/fleschutz/PowerShell
|
||||
.NOTES Author: Markus Fleschutz / License: CC0
|
||||
#>
|
||||
|
||||
& "$PSScriptRoot/close-program.ps1" "Windows Terminal" "WindowsTerminal" "WindowsTerminal"
|
||||
exit 0
|
||||
49
Powershell/Scripts/configure-git.ps1
Normal file
49
Powershell/Scripts/configure-git.ps1
Normal file
@@ -0,0 +1,49 @@
|
||||
<#
|
||||
.SYNTAX configure-git.ps1 [<full-name>] [<email-address>] [<favorite-editor>]
|
||||
.DESCRIPTION sets up the Git user configuration
|
||||
.LINK https://github.com/fleschutz/PowerShell
|
||||
.NOTES Author: Markus Fleschutz / License: CC0
|
||||
#>
|
||||
|
||||
param($FullName = "", $EmailAddress = "", $FavoriteEditor = "")
|
||||
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 (emacs,nano,vi,vim,...)" }
|
||||
|
||||
try {
|
||||
$Null = (git --version)
|
||||
if ($lastExitCode -ne "0") { throw "Can't execute 'git' - make sure Git is installed and available" }
|
||||
|
||||
# Basic settings:
|
||||
& git config --global user.name $FullName
|
||||
& git config --global user.email $EmailAddress
|
||||
& git config --global core.editor $FavoriteEditor
|
||||
& git config --global http.sslVerify false
|
||||
& git config --global core.autocrlf false
|
||||
& git config --global core.symlinks true
|
||||
& git config --global core.longpaths true
|
||||
& git config --global init.defaultBranch main
|
||||
& git config --global merge.renamelimit 99999
|
||||
if ($lastExitCode -ne "0") { throw "'git config' failed (in basic settings)" }
|
||||
|
||||
# Basic shortcuts:
|
||||
& git config --global alias.co "checkout"
|
||||
& git config --global alias.br "branch"
|
||||
& git config --global alias.ci "commit"
|
||||
& git config --global alias.st "status"
|
||||
& 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"
|
||||
if ($lastExitCode -ne "0") { throw "'git config' failed (in basic shortcuts)" }
|
||||
|
||||
"✔️ saved your Git configuration, it's now:"
|
||||
& git config --list
|
||||
if ($lastExitCode -ne "0") { throw "'git config --list' failed" }
|
||||
exit 0
|
||||
} catch {
|
||||
write-error "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
exit 1
|
||||
}
|
||||
21
Powershell/Scripts/convert-csv2txt.ps1
Normal file
21
Powershell/Scripts/convert-csv2txt.ps1
Normal file
@@ -0,0 +1,21 @@
|
||||
<#
|
||||
.SYNTAX convert-csv2txt.ps1 [<csv-file>]
|
||||
.DESCRIPTION converts the given CSV file into a text list
|
||||
.LINK https://github.com/fleschutz/PowerShell
|
||||
.NOTES Author: Markus Fleschutz / License: CC0
|
||||
#>
|
||||
|
||||
param($Path = "")
|
||||
if ($Path -eq "" ) { $Path = read-host "Enter path to CSV file" }
|
||||
|
||||
try {
|
||||
$Table = Import-CSV -path "$Path" -header A,B,C,D,E,F,G,H
|
||||
|
||||
foreach($Row in $Table) {
|
||||
write-output "* $($Row.A) $($Row.B) $($Row.C) $($Row.D) $($Row.E) $($Row.F) $($Row.G) $($Row.H)"
|
||||
}
|
||||
exit 0
|
||||
} catch {
|
||||
write-error "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
exit 1
|
||||
}
|
||||
24
Powershell/Scripts/convert-mysql2csv.ps1
Normal file
24
Powershell/Scripts/convert-mysql2csv.ps1
Normal file
@@ -0,0 +1,24 @@
|
||||
<#
|
||||
.SYNTAX convert-mysql2csv.ps1 [<server>] [<database>] [<username>] [<password>] [<query>]
|
||||
.DESCRIPTION convert the MySQL database table to a CSV file
|
||||
.LINK https://github.com/fleschutz/PowerShell
|
||||
.NOTES Author: Markus Fleschutz / License: CC0
|
||||
#>
|
||||
|
||||
|
||||
param($server = "", $database = "", $username = "", $password = "", $query = "")
|
||||
if ($server -eq "") { $server = read-host "Enter the hostname/IP address of the MySQL server" }
|
||||
if ($database -eq "") { $database = read-host "Enter the database name" }
|
||||
if ($username -eq "") { $username = read-host "Enter the database username" }
|
||||
if ($password -eq "") { $password = read-host "Enter the database user password" }
|
||||
if ($query -eq "") { $query = read-host "Enter the database query" }
|
||||
|
||||
try {
|
||||
$csvfilepath = "$PSScriptRoot\mysql_table.csv"
|
||||
$result = Invoke-MySqlQuery -ConnectionString "server=$server; database=$database; user=$username; password=$password; pooling = false; convert zero datetime=True" -Sql $query -CommandTimeout 10000
|
||||
$result | Export-Csv $csvfilepath -NoTypeInformation
|
||||
exit 0
|
||||
} catch {
|
||||
write-error "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
exit 1
|
||||
}
|
||||
38
Powershell/Scripts/convert-ps2bat.ps1
Normal file
38
Powershell/Scripts/convert-ps2bat.ps1
Normal file
@@ -0,0 +1,38 @@
|
||||
<#
|
||||
.SYNTAX convert-ps2bat.ps1 [<pattern>]
|
||||
.DESCRIPTION converts PowerShell script(s) to .bat files
|
||||
.LINK https://github.com/fleschutz/PowerShell
|
||||
.NOTES Author: Markus Fleschutz / License: CC0
|
||||
#>
|
||||
|
||||
param($Pattern = "")
|
||||
if ($Pattern -eq "") { $Pattern = read-host "Enter path to the PowerShell script(s)" }
|
||||
|
||||
function Convert-PowerShellToBatch
|
||||
{
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory,ValueFromPipeline,ValueFromPipelineByPropertyName)]
|
||||
[string]
|
||||
[Alias("FullName")]
|
||||
$Path
|
||||
)
|
||||
|
||||
process
|
||||
{
|
||||
$encoded = [Convert]::ToBase64String([System.Text.Encoding]::Unicode.GetBytes((Get-Content -Path $Path -Raw -Encoding UTF8)))
|
||||
$newPath = [Io.Path]::ChangeExtension($Path, ".bat")
|
||||
"@echo off`npowershell.exe -NoExit -encodedCommand $encoded" | Set-Content -Path $newPath -Encoding Ascii
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
$Files = get-childItem -path "$Pattern"
|
||||
foreach ($File in $Files) {
|
||||
Convert-PowerShellToBatch "$File"
|
||||
}
|
||||
exit 0
|
||||
} catch {
|
||||
write-error "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
exit 1
|
||||
}
|
||||
25
Powershell/Scripts/convert-sql2csv.ps1
Normal file
25
Powershell/Scripts/convert-sql2csv.ps1
Normal file
@@ -0,0 +1,25 @@
|
||||
<#
|
||||
.SYNTAX convert-sql2csv.ps1 [<server>] [<database>] [<username>] [<password>] [<query>]
|
||||
.DESCRIPTION convert the SQL database table to a CSV file
|
||||
.LINK https://github.com/fleschutz/PowerShell
|
||||
.NOTES Author: Markus Fleschutz / License: CC0
|
||||
#>
|
||||
|
||||
param($server = "", $database = "", $username = "", $password = "", $query = "")
|
||||
if ($server -eq "") { $server = read-host "Enter the hostname/IP address of the SQL server" }
|
||||
if ($database -eq "") { $database = read-host "Enter the database name" }
|
||||
if ($username -eq "") { $username = read-host "Enter the database username" }
|
||||
if ($password -eq "") { $password = read-host "Enter the database user password" }
|
||||
if ($query -eq "") { $query = read-host "Enter the database query" }
|
||||
|
||||
try {
|
||||
$secpasswd = ConvertTo-SecureString $password -AsPlainText -Force
|
||||
$creds = New-Object System.Management.Automation.PSCredential ($username, $secpasswd)
|
||||
$csvfilepath = "$PSScriptRoot\sqlserver_table.csv"
|
||||
$result = Invoke-SqlServerQuery -Credential $creds -ConnectionTimeout 10000 -Database $database -Server $server -Sql $query -CommandTimeout 10000
|
||||
$result | Export-Csv $csvfilepath -NoTypeInformation
|
||||
exit 0
|
||||
} catch {
|
||||
write-error "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
exit 1
|
||||
}
|
||||
22
Powershell/Scripts/convert-txt2wav.ps1
Normal file
22
Powershell/Scripts/convert-txt2wav.ps1
Normal file
@@ -0,0 +1,22 @@
|
||||
<#
|
||||
.SYNTAX convert-txt2wav.ps1 [<text>] [<wav-file>]
|
||||
.DESCRIPTION converts the given text to a .WAV audio file
|
||||
.LINK https://github.com/fleschutz/PowerShell
|
||||
.NOTES Author: Markus Fleschutz / License: CC0
|
||||
#>
|
||||
|
||||
param($Text = "", $WavFile = "")
|
||||
if ($Text -eq "") { $Text = read-host "Enter text to speak" }
|
||||
if ($WavFile -eq "") { $WavFile = read-host "Enter .WAV file to save to" }
|
||||
|
||||
try {
|
||||
Add-Type -AssemblyName System.Speech
|
||||
$SpeechSynthesizer = New-Object System.Speech.Synthesis.SpeechSynthesizer
|
||||
$SpeechSynthesizer.SetOutputToWaveFile($tWavFile)
|
||||
$SpeechSynthesizer.Speak($Text)
|
||||
$SpeechSynthesizer.Dispose()
|
||||
exit 0
|
||||
} catch {
|
||||
write-error "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
exit 1
|
||||
}
|
||||
41
Powershell/Scripts/create-branch.ps1
Normal file
41
Powershell/Scripts/create-branch.ps1
Normal file
@@ -0,0 +1,41 @@
|
||||
<#
|
||||
.SYNTAX create-branch.ps1 [<new-branch-name>] [<repo-dir>]
|
||||
.DESCRIPTION creates and switches to a new branch in a Git repository
|
||||
.LINK https://github.com/fleschutz/PowerShell
|
||||
.NOTES Author: Markus Fleschutz / License: CC0
|
||||
#>
|
||||
|
||||
param($NewBranchName = "", $RepoDir = "$PWD")
|
||||
if ($NewBranchName -eq "") { $NewBranchName = read-host "Enter new branch name" }
|
||||
|
||||
try {
|
||||
$StopWatch = [system.diagnostics.stopwatch]::startNew()
|
||||
|
||||
if (-not(test-path "$RepoDir" -pathType container)) { throw "Can't access directory: $RepoDir" }
|
||||
set-location "$RepoDir"
|
||||
|
||||
$Null = (git --version)
|
||||
if ($lastExitCode -ne "0") { throw "Can't execute 'git' - make sure Git is installed and available" }
|
||||
|
||||
$RepoDirName = (get-item "$RepoDir").Name
|
||||
"🢃 Fetching updates for Git repository 📂$RepoDirName ..."
|
||||
|
||||
& git fetch --all --recurse-submodules --jobs=4
|
||||
if ($lastExitCode -ne "0") { throw "'git fetch' failed" }
|
||||
|
||||
& git checkout -b "$NewBranchName"
|
||||
if ($lastExitCode -ne "0") { throw "'git checkout -b $NewBranchName' failed" }
|
||||
|
||||
& git push origin "$NewBranchName"
|
||||
if ($lastExitCode -ne "0") { throw "'git push origin $NewBranchName' failed" }
|
||||
|
||||
& git submodule update --init --recursive
|
||||
if ($lastExitCode -ne "0") { throw "'git submodule update' failed" }
|
||||
|
||||
[int]$Elapsed = $StopWatch.Elapsed.TotalSeconds
|
||||
"✔️ created new branch '$NewBranchName' in Git repository 📂$RepoDirName in $Elapsed sec"
|
||||
exit 0
|
||||
} catch {
|
||||
write-error "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
exit 1
|
||||
}
|
||||
27
Powershell/Scripts/create-shortcut.ps1
Normal file
27
Powershell/Scripts/create-shortcut.ps1
Normal file
@@ -0,0 +1,27 @@
|
||||
<#
|
||||
.SYNTAX create-shortcut.ps1 [<shortcut>] [<target>] [<description>]
|
||||
.DESCRIPTION creates a new shortcut
|
||||
.LINK https://github.com/fleschutz/PowerShell
|
||||
.NOTES Author: Markus Fleschutz / License: CC0
|
||||
#>
|
||||
|
||||
param($Shortcut = "", $Target = "", $Description)
|
||||
if ($Shortcut -eq "" ) { $Shortcut = read-host "Enter filename of shortcut" }
|
||||
if ($Target -eq "" ) { $Target = read-host "Enter path to target" }
|
||||
if ($Description -eq "" ) { $Description = read-host "Enter description" }
|
||||
|
||||
try {
|
||||
$sh = new-object -ComObject WScript.Shell
|
||||
$shortcut = $sh.CreateShortcut("$Shortcut.lnk")
|
||||
$shortcut.TargetPath = "$Target"
|
||||
$shortcut.WindowStyle = "1"
|
||||
$shortcut.IconLocation = "C:\Windows\System32\SHELL32.dll, 3"
|
||||
$shortcut.Description = "$Description"
|
||||
$shortcut.save()
|
||||
|
||||
write-host -foregroundColor green "✔️ shortcut $Shortcut created."
|
||||
exit 0
|
||||
} catch {
|
||||
write-error "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
exit 1
|
||||
}
|
||||
20
Powershell/Scripts/create-symlink.ps1
Normal file
20
Powershell/Scripts/create-symlink.ps1
Normal file
@@ -0,0 +1,20 @@
|
||||
<#
|
||||
.SYNTAX create-symlink.ps1 [<symlink>] [<target>]
|
||||
.DESCRIPTION creates a symbolic link
|
||||
.LINK https://github.com/fleschutz/PowerShell
|
||||
.NOTES Author: Markus Fleschutz / License: CC0
|
||||
#>
|
||||
|
||||
param($Symlink = "", $Target = "")
|
||||
if ($Symlink -eq "" ) { $Symlink = read-host "Enter filename of symlink" }
|
||||
if ($Target -eq "" ) { $Target = read-host "Enter path to target" }
|
||||
|
||||
try {
|
||||
new-item -path "$Symlink" -itemType SymbolicLink -Value "$Target"
|
||||
|
||||
write-host -foregroundColor green "✔️ symlink $Symlink created (pointing to $Target)"
|
||||
exit 0
|
||||
} catch {
|
||||
write-error "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
exit 1
|
||||
}
|
||||
36
Powershell/Scripts/create-tag.ps1
Normal file
36
Powershell/Scripts/create-tag.ps1
Normal file
@@ -0,0 +1,36 @@
|
||||
<#
|
||||
.SYNTAX create-tag.ps1 [<new-tag-name>] [<repo-dir>]
|
||||
.DESCRIPTION creates a new tag in the current/given Git repository
|
||||
.LINK https://github.com/fleschutz/PowerShell
|
||||
.NOTES Author: Markus Fleschutz / License: CC0
|
||||
#>
|
||||
|
||||
param($NewTagName = "", $RepoDir = "$PWD")
|
||||
if ($NewTagName -eq "") { $NewTagName = read-host "Enter new tag name" }
|
||||
|
||||
try {
|
||||
if (-not(test-path "$RepoDir" -pathType container)) { throw "Can't access directory: $RepoDir" }
|
||||
set-location "$RepoDir"
|
||||
|
||||
$Null = (git --version)
|
||||
if ($lastExitCode -ne "0") { throw "Can't execute 'git' - make sure Git is installed and available" }
|
||||
|
||||
$Result = (git status)
|
||||
if ($lastExitCode -ne "0") { throw "'git status' failed in $RepoDir" }
|
||||
if ("$Result" -notmatch "nothing to commit, working tree clean") { throw "Repository is NOT clean: $Result" }
|
||||
|
||||
& "$PSScriptRoot/fetch-repo.ps1"
|
||||
if ($lastExitCode -ne "0") { throw "Script 'fetch-repo.ps1' failed" }
|
||||
|
||||
& git tag "$NewTagName"
|
||||
if ($lastExitCode -ne "0") { throw "Error: 'git tag $NewTagName' failed!" }
|
||||
|
||||
& git push origin "$NewTagName"
|
||||
if ($lastExitCode -ne "0") { throw "Error: 'git push origin $NewTagName' failed!" }
|
||||
|
||||
"🔖 tag $NewTagName has been created"
|
||||
exit 0
|
||||
} catch {
|
||||
write-error "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
exit 1
|
||||
}
|
||||
18
Powershell/Scripts/daily-tasks.sh
Normal file
18
Powershell/Scripts/daily-tasks.sh
Normal file
@@ -0,0 +1,18 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Syntax: ./daily-tasks.sh
|
||||
# Description: execute PowerShell scripts automatically as daily tasks (Linux only)
|
||||
# copy this script to /etc/cron.daily and adapt it
|
||||
# Author: Markus Fleschutz
|
||||
# License: CC0
|
||||
|
||||
HOMEDIR=/home/mf
|
||||
# adapt this to your home directory
|
||||
|
||||
$HOMEDIR/PowerShell/Scripts/query-smart-data.ps1 $HOMEDIR
|
||||
# to query S.M.A.R.T. data of all your HDD's/SSD's
|
||||
|
||||
$HOMEDIR/PowerShell/Scripts/check-dns-resolution.ps1
|
||||
# to train the DNS cache with frequently used domain names
|
||||
|
||||
exit 0
|
||||
168
Powershell/Scripts/decrypt-file.ps1
Normal file
168
Powershell/Scripts/decrypt-file.ps1
Normal file
@@ -0,0 +1,168 @@
|
||||
<#
|
||||
.SYNTAX decrypt-file.ps1 [<path>] [<password>]
|
||||
.DESCRIPTION decrypts the given file
|
||||
.LINK https://github.com/fleschutz/PowerShell
|
||||
.NOTES Author: Markus Fleschutz / License: CC0
|
||||
#>
|
||||
|
||||
param([string]$Path = "", [string]$Password = "")
|
||||
|
||||
|
||||
function DecryptFile {
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Decrypts a file encrypted with Protect-File.
|
||||
|
||||
.DESCRIPTION
|
||||
Decrypts a file using a provided cryptography key.
|
||||
|
||||
.PARAMETER FileName
|
||||
File(s) to be decrypted.
|
||||
|
||||
.PARAMETER Key
|
||||
Cryptography key as a SecureString be used for decryption.
|
||||
|
||||
.PARAMETER KeyAsPlainText
|
||||
Cryptography key as a String to be used for decryption.
|
||||
|
||||
.PARAMETER CipherMode
|
||||
Specifies the block cipher mode that was used for encryption.
|
||||
|
||||
.PARAMETER PaddingMode
|
||||
Specifies the type of padding that was applied when the message data block was shorter than the full number of bytes needed for a cryptographic operation.
|
||||
|
||||
.PARAMETER Suffix
|
||||
Suffix of the encrypted file to be removed.
|
||||
|
||||
.PARAMETER RemoveSource
|
||||
Removes the source (encrypted) file after decrypting.
|
||||
|
||||
.OUTPUTS
|
||||
System.IO.FileInfo. Unprotect-File will return FileInfo with the SourceFile as an added NoteProperty
|
||||
#>
|
||||
[CmdletBinding(DefaultParameterSetName='SecureString')]
|
||||
[OutputType([System.IO.FileInfo[]])]
|
||||
Param(
|
||||
[Parameter(Mandatory=$true, Position=1, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)]
|
||||
[Alias('PSPath','LiteralPath')]
|
||||
[string[]]$FileName,
|
||||
[Parameter(Mandatory=$false, Position=2, ValueFromPipelineByPropertyName=$true)]
|
||||
[ValidateSet('AES','DES','RC2','Rijndael','TripleDES')]
|
||||
[String]$Algorithm = 'AES',
|
||||
[Parameter(Mandatory=$true, Position=3, ValueFromPipelineByPropertyName=$true, ParameterSetName='SecureString')]
|
||||
[System.Security.SecureString]$Key,
|
||||
[Parameter(Mandatory=$true, Position=3, ParameterSetName='PlainText')]
|
||||
[String]$KeyAsPlainText,
|
||||
[Parameter(Mandatory=$false, Position=4, ValueFromPipelineByPropertyName=$true)]
|
||||
[System.Security.Cryptography.CipherMode]$CipherMode = 'CBC',
|
||||
[Parameter(Mandatory=$false, Position=5, ValueFromPipelineByPropertyName=$true)]
|
||||
[System.Security.Cryptography.PaddingMode]$PaddingMode = 'PKCS7',
|
||||
[Parameter(Mandatory=$false, Position=6)]
|
||||
[String]$Suffix,
|
||||
[Parameter()]
|
||||
[Switch]$RemoveSource
|
||||
)
|
||||
Process
|
||||
{
|
||||
try
|
||||
{
|
||||
if($PSCmdlet.ParameterSetName -eq 'PlainText')
|
||||
{
|
||||
$Key = $KeyAsPlainText | ConvertTo-SecureString -AsPlainText -Force
|
||||
}
|
||||
|
||||
$BSTR = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($Key)
|
||||
$EncryptionKey = [System.Convert]::FromBase64String([System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR))
|
||||
|
||||
$Crypto = [System.Security.Cryptography.SymmetricAlgorithm]::Create($Algorithm)
|
||||
$Crypto.Mode = $CipherMode
|
||||
$Crypto.Padding = $PaddingMode
|
||||
$Crypto.KeySize = $EncryptionKey.Length*8
|
||||
$Crypto.Key = $EncryptionKey
|
||||
}
|
||||
Catch
|
||||
{
|
||||
Write-Error $_ -ErrorAction Stop
|
||||
}
|
||||
|
||||
if(-not $PSBoundParameters.ContainsKey('Suffix'))
|
||||
{
|
||||
$Suffix = ".$Algorithm"
|
||||
}
|
||||
|
||||
$Files = Get-Item -LiteralPath $FileName
|
||||
|
||||
ForEach($File in $Files)
|
||||
{
|
||||
If(-not $File.Name.EndsWith($Suffix))
|
||||
{
|
||||
Write-Error "$($File.FullName) does not have an extension of '$Suffix'."
|
||||
Continue
|
||||
}
|
||||
|
||||
$DestinationFile = $File.FullName -replace "$Suffix$"
|
||||
|
||||
Try
|
||||
{
|
||||
$FileStreamReader = New-Object System.IO.FileStream($File.FullName, [System.IO.FileMode]::Open)
|
||||
$FileStreamWriter = New-Object System.IO.FileStream($DestinationFile, [System.IO.FileMode]::Create)
|
||||
|
||||
[Byte[]]$LenIV = New-Object Byte[] 4
|
||||
$FileStreamReader.Seek(0, [System.IO.SeekOrigin]::Begin) | Out-Null
|
||||
$FileStreamReader.Read($LenIV, 0, 3) | Out-Null
|
||||
[Int]$LIV = [System.BitConverter]::ToInt32($LenIV, 0)
|
||||
[Byte[]]$IV = New-Object Byte[] $LIV
|
||||
$FileStreamReader.Seek(4, [System.IO.SeekOrigin]::Begin) | Out-Null
|
||||
$FileStreamReader.Read($IV, 0, $LIV) | Out-Null
|
||||
$Crypto.IV = $IV
|
||||
|
||||
$Transform = $Crypto.CreateDecryptor()
|
||||
$CryptoStream = New-Object System.Security.Cryptography.CryptoStream($FileStreamWriter, $Transform, [System.Security.Cryptography.CryptoStreamMode]::Write)
|
||||
$FileStreamReader.CopyTo($CryptoStream)
|
||||
|
||||
$CryptoStream.FlushFinalBlock()
|
||||
$CryptoStream.Close()
|
||||
$FileStreamReader.Close()
|
||||
$FileStreamWriter.Close()
|
||||
|
||||
if($RemoveSource){Remove-Item $File.FullName}
|
||||
|
||||
Get-Item $DestinationFile | Add-Member –MemberType NoteProperty –Name SourceFile –Value $File.FullName -PassThru
|
||||
}
|
||||
Catch
|
||||
{
|
||||
Write-Error $_
|
||||
If($FileStreamWriter)
|
||||
{
|
||||
$FileStreamWriter.Close()
|
||||
Remove-Item -LiteralPath $DestinationFile -Force
|
||||
}
|
||||
Continue
|
||||
}
|
||||
Finally
|
||||
{
|
||||
if($CryptoStream){$CryptoStream.Close()}
|
||||
if($FileStreamReader){$FileStreamReader.Close()}
|
||||
if($FileStreamWriter){$FileStreamWriter.Close()}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
if ($Path -eq "" ) {
|
||||
$Path = read-host "Enter path to file"
|
||||
}
|
||||
if ($Password -eq "" ) {
|
||||
$Password = read-host "Enter password"
|
||||
}
|
||||
|
||||
$PasswordBase64 = [System.Convert]::ToBase64String($Password)
|
||||
DecryptFile "$Path" -algorithm AES -keyAsPlainText $PasswordBase64 -removeSource
|
||||
write-host -foregroundColor green "Done."
|
||||
exit 0
|
||||
} catch {
|
||||
write-error "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
exit 1
|
||||
}
|
||||
23
Powershell/Scripts/display-time.ps1
Normal file
23
Powershell/Scripts/display-time.ps1
Normal file
@@ -0,0 +1,23 @@
|
||||
<#
|
||||
.SYNTAX display-time.ps1 [<seconds>]
|
||||
.DESCRIPTION displays the current time for 10 seconds by default
|
||||
.LINK https://github.com/fleschutz/PowerShell
|
||||
.NOTES Author: Markus Fleschutz / License: CC0
|
||||
#>
|
||||
|
||||
param([int]$Seconds = 10)
|
||||
|
||||
try {
|
||||
for ([int]$i = 0; $i -lt $Seconds; $i++) {
|
||||
clear-host
|
||||
write-output ""
|
||||
$CurrentTime = Get-Date -format "yyyy-MM-dd HH:mm:ss"
|
||||
./write-big $CurrentTime
|
||||
write-output ""
|
||||
start-sleep -s 1
|
||||
}
|
||||
exit 0
|
||||
} catch {
|
||||
write-error "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
exit 1
|
||||
}
|
||||
23
Powershell/Scripts/download-dir.ps1
Normal file
23
Powershell/Scripts/download-dir.ps1
Normal file
@@ -0,0 +1,23 @@
|
||||
<#
|
||||
.SYNTAX download-dir.ps1 [<URL>]
|
||||
.DESCRIPTION downloads a directory tree from the given URL
|
||||
.LINK https://github.com/fleschutz/PowerShell
|
||||
.NOTES Author: Markus Fleschutz / License: CC0
|
||||
#>
|
||||
|
||||
param($URL = "")
|
||||
if ($URL -eq "") { $URL = read-host "Enter directory URL to download" }
|
||||
|
||||
try {
|
||||
& wget --version
|
||||
if ($lastExitCode -ne "0") { throw "Can't execute 'wget' - make sure wget is installed and available" }
|
||||
|
||||
& wget --mirror --convert-links --adjust-extension --page-requisites --no-parent $URL --directory-prefix . --no-verbose
|
||||
if ($lastExitCode -ne "0") { throw "Can't execute 'wget --mirror $URL'" }
|
||||
|
||||
write-host -foregroundColor green "OK - directory downloaded from $URL"
|
||||
exit 0
|
||||
} catch {
|
||||
write-error "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
exit 1
|
||||
}
|
||||
23
Powershell/Scripts/download-file.ps1
Normal file
23
Powershell/Scripts/download-file.ps1
Normal file
@@ -0,0 +1,23 @@
|
||||
<#
|
||||
.SYNTAX download-file.ps1 [<URL>]
|
||||
.DESCRIPTION downloads a file from the given URL
|
||||
.LINK https://github.com/fleschutz/PowerShell
|
||||
.NOTES Author: Markus Fleschutz / License: CC0
|
||||
#>
|
||||
|
||||
param($URL = "")
|
||||
if ($URL -eq "") { $URL = read-host "Enter file URL to download" }
|
||||
|
||||
try {
|
||||
& wget --version
|
||||
if ($lastExitCode -ne "0") { throw "Can't execute 'wget' - make sure wget is installed and available" }
|
||||
|
||||
& wget --mirror --convert-links --adjust-extension --page-requisites --no-parent $URL --directory-prefix . --no-verbose
|
||||
if ($lastExitCode -ne "0") { throw "Can't execute 'wget --mirror $URL'" }
|
||||
|
||||
write-host -foregroundColor green "OK - file downloaded from $URL"
|
||||
exit 0
|
||||
} catch {
|
||||
write-error "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
exit 1
|
||||
}
|
||||
23
Powershell/Scripts/edit.ps1
Normal file
23
Powershell/Scripts/edit.ps1
Normal file
@@ -0,0 +1,23 @@
|
||||
<#
|
||||
.SYNTAX edit.ps1 <filename>
|
||||
.DESCRIPTION starts the built-in text editor to edit the given file
|
||||
.LINK https://github.com/fleschutz/PowerShell
|
||||
.NOTES Author: Markus Fleschutz / License: CC0
|
||||
#>
|
||||
|
||||
param($Filename = "")
|
||||
|
||||
try {
|
||||
if ($IsLinux) {
|
||||
& vi "$Filename"
|
||||
if ($lastExitCode -ne "0") { throw "Can't execute 'vi' - make sure vi is installed and available" }
|
||||
} else {
|
||||
& notepad.exe "$Filename"
|
||||
if ($lastExitCode -ne "0") { throw "Can't execute 'notepad.exe' - make sure notepad.exe is installed and available" }
|
||||
}
|
||||
|
||||
exit 0
|
||||
} catch {
|
||||
write-error "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
exit 1
|
||||
}
|
||||
291
Powershell/Scripts/enable-crash-dumps.ps1
Normal file
291
Powershell/Scripts/enable-crash-dumps.ps1
Normal file
@@ -0,0 +1,291 @@
|
||||
<#
|
||||
.SYNTAX enable-crash-dumps.ps1
|
||||
.DESCRIPTION enables the writing of crash dumps
|
||||
.LINK https://github.com/fleschutz/PowerShell
|
||||
.NOTES Author: Markus Fleschutz / License: CC0
|
||||
#>
|
||||
|
||||
##################################################################
|
||||
# #
|
||||
# Written by: Ryan Waters #
|
||||
# #
|
||||
# Program: Get-Dump.ps1 #
|
||||
# Date: 2-06-2020 #
|
||||
# Purpose: To set registry keys to gather a WER Usermode Dump #
|
||||
# and be able to change from a custom, mini, or FULL #
|
||||
# Dumps for ease of use for customers and others. #
|
||||
# #
|
||||
# EULA: Code is free to use for all, and free to distribute #
|
||||
# I just ask that you leave the credit information and #
|
||||
# this EULA and Comment Section in tact and do not delete. #
|
||||
# #
|
||||
# Bitwise Values: (For reference) #
|
||||
# #
|
||||
# 0x00000000 - MiniDumpNormal #
|
||||
# 0x00000001 - MiniDumpWithDataSegs #
|
||||
# 0x00000002 - MiniDumpWithFullMemory #
|
||||
# 0x00000004 - MiniDumpWithHandleData #
|
||||
# 0x00000008 - MiniDumpFilterMemory #
|
||||
# 0x00000010 - MiniDumpScanMemory #
|
||||
# 0x00000020 - MiniDumpWithUnloadedModules #
|
||||
# 0x00000040 - MiniDumpWithIndirectlyReferenced #
|
||||
# 0x00000080 - MemoryMiniDumpFilterModulePaths #
|
||||
# 0x00000100 - MiniDumpWithProcessThreadData #
|
||||
# 0x00000200 - MiniDumpWithPrivateReadWriteMemory #
|
||||
# 0x00000400 - MiniDumpWithoutOptionalData #
|
||||
# 0x00000800 - MiniDumpWithFullMemoryInfo #
|
||||
# 0x00001000 - MiniDumpWithThreadInfo #
|
||||
# 0x00002000 - MiniDumpWithCodeSegs #
|
||||
# 0x00004000 - MiniDumpWithoutAuxiliaryState #
|
||||
# 0x00008000 - MiniDumpWithFullAuxiliaryState #
|
||||
# 0x00010000 - MiniDumpWithPrivateWriteCopyMemory #
|
||||
# 0x00020000 - MiniDumpIgnoreInaccessibleMemory #
|
||||
# 0x00040000 - MiniDumpWithTokenInformation #
|
||||
# #
|
||||
##################################################################
|
||||
|
||||
#Setting Values:
|
||||
$MDN = '0'
|
||||
$MDWDS = '1'
|
||||
$MDWFM = '2'
|
||||
$MDWHD = '4'
|
||||
$MDFM = '8'
|
||||
$MDSM = '10'
|
||||
$MDWUM = '20'
|
||||
$MDWIR = '40'
|
||||
$MMDFMP = '80'
|
||||
$MDWPTD = '100'
|
||||
$MDWPRWM = '200'
|
||||
$MDWOD = '400'
|
||||
$MDWFMI = '800'
|
||||
$MDWTI = '1000'
|
||||
$MDWCS = '2000'
|
||||
$MDWAS = '4000'
|
||||
$MDWFAS = '8000'
|
||||
$MDWPWCM = '10000'
|
||||
$MDIIM = '20000'
|
||||
$MDWTOI = '40000'
|
||||
|
||||
$a = $MDN
|
||||
$b = $MDWDS
|
||||
$c = $MDWFM
|
||||
$d = $MDWHD
|
||||
$e = $MDFM
|
||||
$f = $MDSM
|
||||
$g = $MDWUM
|
||||
$h = $MDWIR
|
||||
$i = $MMDFMP
|
||||
$j = $MDWPTD
|
||||
$k = $MDWPRWM
|
||||
$l = $MDWOD
|
||||
$m = $MDWFMI
|
||||
$n = $MDWTI
|
||||
$o = $MDWCS
|
||||
$p = $MDWAS
|
||||
$q = $MDWFAS
|
||||
$r = $MDWPWCM
|
||||
$s = $MDIIM
|
||||
$t = $MDWTOI
|
||||
|
||||
$0x = "0x"
|
||||
|
||||
$array = @()
|
||||
|
||||
Clear-host
|
||||
write-host "Setting up your machine to receive Usermode Dumps via WER."
|
||||
Start-sleep -s 3
|
||||
|
||||
|
||||
New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps" -Name "DumpFolder" -Value "%LOCALAPPDATA%\CrashDumps" -PropertyType ExpandString -Force
|
||||
New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps" -Name "DumpCount" -Value "10" -PropertyType DWORD -Force
|
||||
|
||||
clear-host
|
||||
write-host "What would you like to do?"
|
||||
write-host "(0) Disable Dumps and restore system to factory."
|
||||
write-host "(1) Enable System for Full Dumps."
|
||||
write-host "(2) Enable System for Mini Dumps."
|
||||
write-host "(3) Enable System for custom dump with options."
|
||||
$NCD = Read-Host "Enter a number option"
|
||||
|
||||
If ($NCD -eq '3')
|
||||
{
|
||||
|
||||
New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps" -Name "DumpType" -Value "0" -PropertyType DWORD -Force
|
||||
Do
|
||||
{
|
||||
clear-host
|
||||
write-host "Here are the optional custom dump to add to your custom dump parameters:"
|
||||
write-host "(1) Mini Dump Normal"
|
||||
write-host "(2) Mini Dump With Data Segs"
|
||||
write-host "(3) Mini Dump With Full Memory"
|
||||
write-host "(4) Mini Dump With Handle Data"
|
||||
write-host "(5) Mini Dump Filter Memory"
|
||||
write-host "(6) Mini Dump Scan Memory"
|
||||
write-host "(7) Mini Dump With Unloaded Modules"
|
||||
write-host "(8) Mini Dump With Indirectly Referenced"
|
||||
write-host "(9) Memory Mini Dump Filter Module Paths"
|
||||
write-host "(10) Mini Dump With Process Thread Data"
|
||||
write-host "(11) Mini Dump With Private Read Write Memory"
|
||||
write-host "(12) Mini Dump Without Optional Data"
|
||||
write-host "(13) Mini Dump With Full Memory Info"
|
||||
write-host "(14) Mini Dump With Thread Info"
|
||||
write-host "(15) Mini Dump With Code Segs"
|
||||
write-host "(16) Mini Dump Without Auxiliary State"
|
||||
write-host "(17) Mini Dump With Full Auxiliary State"
|
||||
write-host "(18) Mini Dump With Private Write Copy Memory"
|
||||
write-host "(19) Mini Dump Ignore Inaccessible Memory"
|
||||
write-host "(20) Mini Dump With Token Information"
|
||||
$Option = Read-Host "Enter one number value at a time and press enter. (Press 'q' when finished)"
|
||||
if($Option -eq '1')
|
||||
{
|
||||
$array += [int]$a
|
||||
}
|
||||
ElseIf($Option -eq '2')
|
||||
{
|
||||
$array += [int]$b
|
||||
}
|
||||
ElseIf($Option -eq '3')
|
||||
{
|
||||
$array += [int]$c
|
||||
}
|
||||
ElseIf($Option -eq '4')
|
||||
{
|
||||
$array += [int]$d
|
||||
}
|
||||
ElseIf($Option -eq '5')
|
||||
{
|
||||
$array += [int]$e
|
||||
}
|
||||
ElseIf($Option -eq '6')
|
||||
{
|
||||
$array += [int]$f
|
||||
}
|
||||
ElseIf($Option -eq '7')
|
||||
{
|
||||
$array += [int]$g
|
||||
}
|
||||
ElseIf($Option -eq '8')
|
||||
{
|
||||
$array += [int]$h
|
||||
}
|
||||
ElseIf($Option -eq '9')
|
||||
{
|
||||
$array += [int]$i
|
||||
}
|
||||
ElseIf($Option -eq '10')
|
||||
{
|
||||
$array += [int]$j
|
||||
}
|
||||
ElseIf($Option -eq '11')
|
||||
{
|
||||
$array += [int]$k
|
||||
}
|
||||
ElseIf($Option -eq '12')
|
||||
{
|
||||
$array += [int]$l
|
||||
}
|
||||
ElseIf($Option -eq '13')
|
||||
{
|
||||
$array += [int]$m
|
||||
}
|
||||
ElseIf($Option -eq '14')
|
||||
{
|
||||
$array += [int]$n
|
||||
}
|
||||
ElseIf($Option -eq '15')
|
||||
{
|
||||
$array += [int]$o
|
||||
}
|
||||
ElseIf($Option -eq '16')
|
||||
{
|
||||
$array += [int]$p
|
||||
}
|
||||
ElseIf($Option -eq '17')
|
||||
{
|
||||
$array += [int]$q
|
||||
}
|
||||
ElseIf($Option -eq '18')
|
||||
{
|
||||
$array += [int]$r
|
||||
}
|
||||
ElseIf($Option -eq '19')
|
||||
{
|
||||
$array += [int]$s
|
||||
}
|
||||
ElseIf($Option -eq '20')
|
||||
{
|
||||
$array += [int]$t
|
||||
}
|
||||
ElseIf($Option -eq 'q')
|
||||
{
|
||||
write-host "Closing application."
|
||||
Start-Sleep -s 2
|
||||
}
|
||||
Else
|
||||
{
|
||||
write-host "Invalid Option, Try again."
|
||||
Start-sleep -s 2
|
||||
}
|
||||
|
||||
}
|
||||
While($Option -ne "q")
|
||||
$sum = $array -join '+'
|
||||
$SumArray = Invoke-Expression $sum
|
||||
$FinalSum = $0x + $SumArray
|
||||
|
||||
New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps" -Name "CustomDumpFlags" -Value "$FinalSum" -PropertyType DWORD -Force
|
||||
|
||||
write-host " "
|
||||
write-host "Setting up the system for crash dumps requires a reboot"
|
||||
}
|
||||
ElseIf ($NCD -eq '0')
|
||||
{
|
||||
Remove-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps" -Name "DumpCount" -Force -ErrorAction SilentlyContinue
|
||||
Remove-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps" -Name "DumpType" -Force -ErrorAction SilentlyContinue
|
||||
Remove-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps" -Name "DumpFolder" -Force -ErrorAction SilentlyContinue
|
||||
Remove-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps" -Name "CustomDumpFlags" -Force -ErrorAction SilentlyContinue
|
||||
write-host " "
|
||||
$reboot = read-host "Registry reset to factory settings and cleared. It is recommended to restart your machine, would you like to now?"
|
||||
if($reboot -eq "Yes" -or $reboot -eq "Y" -or $reboot -eq "yes" -or $reboot -eq "y")
|
||||
{
|
||||
shutdown -r
|
||||
}
|
||||
Else
|
||||
{
|
||||
write-host "Please restart the machine for settings to take effect at your convenience."
|
||||
}
|
||||
}
|
||||
ElseIf ($NCD -eq '1')
|
||||
{
|
||||
New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps" -Name "DumpType" -Value "2" -PropertyType DWORD -Force
|
||||
write-host "The computer has been set up to create a Full Sized Dump and will be located in %LOCALAPPDATA%\CrashDumps."
|
||||
write-host "The computer must also restart for settings to take effect. Would you like to now? (Y/n)"
|
||||
if($reboot -eq "Yes" -or $reboot -eq "Y" -or $reboot -eq "yes" -or $reboot -eq "y")
|
||||
{
|
||||
shutdown -r
|
||||
}
|
||||
Else
|
||||
{
|
||||
write-host "Please restart the machine for settings to take effect at your convenience."
|
||||
}
|
||||
}
|
||||
ElseIf ($NCD -eq '2')
|
||||
{
|
||||
New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps" -Name "DumpType" -Value "1" -PropertyType DWORD -Force
|
||||
write-host "The computer has been set up to create a Mini Dump and will be located in %LOCALAPPDATA%\CrashDumps."
|
||||
write-host "The computer must also restart for settings to take effect. Would you like to now? (Y/n)"
|
||||
if($reboot -eq "Yes" -or $reboot -eq "Y" -or $reboot -eq "yes" -or $reboot -eq "y")
|
||||
{
|
||||
shutdown -r
|
||||
}
|
||||
Else
|
||||
{
|
||||
write-host "Please restart the machine for settings to take effect at your convenience."
|
||||
}
|
||||
}
|
||||
Else
|
||||
{
|
||||
write-host "You did not enter a valid option. Please re-run Get-Dump.ps1"
|
||||
start-sleep -s 5
|
||||
}
|
||||
exit 0
|
||||
21
Powershell/Scripts/enable-god-mode.ps1
Normal file
21
Powershell/Scripts/enable-god-mode.ps1
Normal file
@@ -0,0 +1,21 @@
|
||||
<#
|
||||
.SYNTAX enable-god-mode.ps1
|
||||
.DESCRIPTION enables the god mode (adds a new icon to the desktop)
|
||||
.LINK https://github.com/fleschutz/PowerShell
|
||||
.NOTES Author: Markus Fleschutz / License: CC0
|
||||
#>
|
||||
|
||||
try {
|
||||
$GodModeSplat = @{
|
||||
Path = "$HOME\Desktop"
|
||||
Name = "GodMode.{ED7BA470-8E54-465E-825C-99712043E01C}"
|
||||
ItemType = 'Directory'
|
||||
}
|
||||
$null = new-item @GodModeSplat
|
||||
|
||||
"✔️ new icon added to the desktop"
|
||||
exit 0
|
||||
} catch {
|
||||
write-error "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
exit 1
|
||||
}
|
||||
18
Powershell/Scripts/enable-ssh-client.ps1
Normal file
18
Powershell/Scripts/enable-ssh-client.ps1
Normal file
@@ -0,0 +1,18 @@
|
||||
<#
|
||||
.SYNTAX enable-ssh-client.ps1
|
||||
.DESCRIPTION enables the SSH client (needs admin rights)
|
||||
.LINK https://github.com/fleschutz/PowerShell
|
||||
.NOTES Author: Markus Fleschutz / License: CC0
|
||||
#>
|
||||
|
||||
#Requires -RunAsAdministrator
|
||||
|
||||
try {
|
||||
Add-WindowsCapability -Online -Name OpenSSH.Client*
|
||||
|
||||
write-host -foregroundColor green "OK - SSH client enabled"
|
||||
exit 0
|
||||
} catch {
|
||||
write-error "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
exit 1
|
||||
}
|
||||
20
Powershell/Scripts/enable-ssh-server.ps1
Normal file
20
Powershell/Scripts/enable-ssh-server.ps1
Normal file
@@ -0,0 +1,20 @@
|
||||
<#
|
||||
.SYNTAX enable-ssh-server.ps1
|
||||
.DESCRIPTION enables the SSH server (needs admin rights)
|
||||
.LINK https://github.com/fleschutz/PowerShell
|
||||
.NOTES Author: Markus Fleschutz / License: CC0
|
||||
#>
|
||||
|
||||
#Requires -RunAsAdministrator
|
||||
|
||||
try {
|
||||
Add-WindowsCapability -Online -Name OpenSSH.Server*
|
||||
Start-Service sshd
|
||||
Set-Service -Name sshd -StartupType 'Automatic'
|
||||
|
||||
write-host -foregroundColor green "OK - SSH server enabled"
|
||||
exit 0
|
||||
} catch {
|
||||
write-error "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
exit 1
|
||||
}
|
||||
153
Powershell/Scripts/encrypt-file.ps1
Normal file
153
Powershell/Scripts/encrypt-file.ps1
Normal file
@@ -0,0 +1,153 @@
|
||||
<#
|
||||
.SYNTAX encrypt-file.ps1 [<path>] [<password>]
|
||||
.DESCRIPTION encrypts the given file
|
||||
.LINK https://github.com/fleschutz/PowerShell
|
||||
.NOTES Author: Markus Fleschutz / License: CC0
|
||||
#>
|
||||
|
||||
param($Path = "", $Password = "")
|
||||
|
||||
function EncryptFile {
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Encrypts a file using a symmetrical algorithm.
|
||||
|
||||
.DESCRIPTION
|
||||
Encrypts a file using a symmetrical algorithm.
|
||||
|
||||
.PARAMETER FileName
|
||||
File(s) to be encrypted.
|
||||
|
||||
.PARAMETER Key
|
||||
Cryptography key as a SecureString to be used for encryption.
|
||||
|
||||
.PARAMETER KeyAsPlainText
|
||||
Cryptography key as a String to be used for encryption.
|
||||
|
||||
.PARAMETER CipherMode
|
||||
Specifies the block cipher mode to use for encryption.
|
||||
|
||||
.PARAMETER PaddingMode
|
||||
Specifies the type of padding to apply when the message data block is shorter than the full number of bytes needed for a cryptographic operation.
|
||||
|
||||
.PARAMETER Suffix
|
||||
Suffix of the encrypted file to be removed.
|
||||
|
||||
.PARAMETER RemoveSource
|
||||
Removes the source (decrypted) file after encrypting.
|
||||
|
||||
.OUTPUTS
|
||||
System.IO.FileInfo. Protect-File will return FileInfo with the SourceFile, Algorithm, Key, CipherMode, and PaddingMode as added NoteProperties
|
||||
#>
|
||||
[CmdletBinding(DefaultParameterSetName='SecureString')]
|
||||
[OutputType([System.IO.FileInfo[]])]
|
||||
Param(
|
||||
[Parameter(Mandatory=$true, Position=1, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)]
|
||||
[Alias('PSPath','LiteralPath')]
|
||||
[string[]]$FileName,
|
||||
[Parameter(Mandatory=$false, Position=2)]
|
||||
[ValidateSet('AES','DES','RC2','Rijndael','TripleDES')]
|
||||
[String]$Algorithm = 'AES',
|
||||
[Parameter(Mandatory=$false, Position=3, ParameterSetName='SecureString')]
|
||||
[System.Security.SecureString]$Key = (New-CryptographyKey -Algorithm $Algorithm),
|
||||
[Parameter(Mandatory=$true, Position=3, ParameterSetName='PlainText')]
|
||||
[String]$KeyAsPlainText,
|
||||
[Parameter(Mandatory=$false, Position=4)]
|
||||
[System.Security.Cryptography.CipherMode]$CipherMode,
|
||||
[Parameter(Mandatory=$false, Position=5)]
|
||||
[System.Security.Cryptography.PaddingMode]$PaddingMode,
|
||||
[Parameter(Mandatory=$false, Position=6)]
|
||||
[String]$Suffix = ".$Algorithm",
|
||||
[Parameter()]
|
||||
[Switch]$RemoveSource
|
||||
)
|
||||
begin {
|
||||
try {
|
||||
if ($PSCmdlet.ParameterSetName -eq 'PlainText') {
|
||||
$Key = $KeyAsPlainText | ConvertTo-SecureString -AsPlainText -Force
|
||||
}
|
||||
|
||||
$BSTR = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($Key)
|
||||
$EncryptionKey = [System.Convert]::FromBase64String([System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR))
|
||||
|
||||
$Crypto = [System.Security.Cryptography.SymmetricAlgorithm]::Create($Algorithm)
|
||||
if ($PSBoundParameters.ContainsKey('CipherMode')) {
|
||||
$Crypto.Mode = $CipherMode
|
||||
}
|
||||
if ($PSBoundParameters.ContainsKey('PaddingMode')) {
|
||||
$Crypto.Padding = $PaddingMode
|
||||
}
|
||||
$Crypto.KeySize = $EncryptionKey.Length*8
|
||||
$Crypto.Key = $EncryptionKey
|
||||
} catch {
|
||||
Write-Error $_ -ErrorAction Stop
|
||||
}
|
||||
}
|
||||
process {
|
||||
$Files = Get-Item -LiteralPath $FileName
|
||||
|
||||
foreach($File in $Files) {
|
||||
$DestinationFile = $File.FullName + $Suffix
|
||||
|
||||
try {
|
||||
$FileStreamReader = New-Object System.IO.FileStream($File.FullName, [System.IO.FileMode]::Open)
|
||||
$FileStreamWriter = New-Object System.IO.FileStream($DestinationFile, [System.IO.FileMode]::Create)
|
||||
|
||||
$Crypto.GenerateIV()
|
||||
$FileStreamWriter.Write([System.BitConverter]::GetBytes($Crypto.IV.Length), 0, 4)
|
||||
$FileStreamWriter.Write($Crypto.IV, 0, $Crypto.IV.Length)
|
||||
|
||||
$Transform = $Crypto.CreateEncryptor()
|
||||
$CryptoStream = New-Object System.Security.Cryptography.CryptoStream($FileStreamWriter, $Transform, [System.Security.Cryptography.CryptoStreamMode]::Write)
|
||||
$FileStreamReader.CopyTo($CryptoStream)
|
||||
|
||||
$CryptoStream.FlushFinalBlock()
|
||||
$CryptoStream.Close()
|
||||
$FileStreamReader.Close()
|
||||
$FileStreamWriter.Close()
|
||||
|
||||
if ($RemoveSource) {
|
||||
Remove-Item -LiteralPath $File.FullName
|
||||
}
|
||||
|
||||
$result = Get-Item $DestinationFile
|
||||
$result | Add-Member –MemberType NoteProperty –Name SourceFile –Value $File.FullName
|
||||
$result | Add-Member –MemberType NoteProperty –Name Algorithm –Value $Algorithm
|
||||
$result | Add-Member –MemberType NoteProperty –Name Key –Value $Key
|
||||
$result | Add-Member –MemberType NoteProperty –Name CipherMode –Value $Crypto.Mode
|
||||
$result | Add-Member –MemberType NoteProperty –Name PaddingMode –Value $Crypto.Padding
|
||||
$result
|
||||
} catch {
|
||||
Write-Error $_
|
||||
if ($FileStreamWriter) {
|
||||
$FileStreamWriter.Close()
|
||||
Remove-Item -LiteralPath $DestinationFile -Force
|
||||
}
|
||||
continue
|
||||
} finally {
|
||||
if($CryptoStream){$CryptoStream.Close()}
|
||||
if($FileStreamReader){$FileStreamReader.Close()}
|
||||
if($FileStreamWriter){$FileStreamWriter.Close()}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
if ($Path -eq "" ) {
|
||||
$Path = read-host "Enter path to file"
|
||||
}
|
||||
if ($Password -eq "" ) {
|
||||
$Password = read-host "Enter password"
|
||||
}
|
||||
|
||||
$PasswordBase64 = [System.Convert]::ToBase64String($Password)
|
||||
EnryptFile "$Path" -Algorithm AES -KeyAsPlainText $PasswordBase64 -RemoveSource
|
||||
|
||||
write-host -foregroundColor green "Done."
|
||||
exit 0
|
||||
} catch {
|
||||
write-error "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
exit 1
|
||||
}
|
||||
79
Powershell/Scripts/enter-chat.ps1
Normal file
79
Powershell/Scripts/enter-chat.ps1
Normal file
@@ -0,0 +1,79 @@
|
||||
# make sure you adjust this path
|
||||
# it must point to a network share where you have read and write permissions
|
||||
$ServerShare = "\\myserver\chathome"
|
||||
|
||||
function Enter-Chat
|
||||
{
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory)]
|
||||
[string]
|
||||
$ChatChannelName,
|
||||
|
||||
[string]
|
||||
$Name = $env:USERNAME,
|
||||
|
||||
[Switch]
|
||||
$ShowOldPosts,
|
||||
|
||||
$HomeShare = $ServerShare
|
||||
|
||||
)
|
||||
|
||||
if ($ShowOldPosts)
|
||||
{
|
||||
$Option = ''
|
||||
}
|
||||
else
|
||||
{
|
||||
$Option = '-Tail 0'
|
||||
}
|
||||
|
||||
$Path = Join-Path -Path $HomeShare -ChildPath "$ChatChannelName.txt"
|
||||
$exists = Test-Path -Path $Path
|
||||
if ($exists -eq $false)
|
||||
{
|
||||
$null = New-Item -Path $Path -Force -ItemType File
|
||||
}
|
||||
|
||||
$process = Start-Process -FilePath powershell -ArgumentList "-noprofile -windowstyle hidden -command Get-COntent -Path '$Path' $Option -Wait | Out-GridView -Title 'Chat: [$ChatChannelName]'" -PassThru
|
||||
|
||||
Write-Host "To exit, enter: quit"
|
||||
"[$Name entered the chat]" | Add-Content -Path $Path
|
||||
do
|
||||
{
|
||||
Write-Host "[$ChatChannelName]: " -ForegroundColor Green -NoNewline
|
||||
$inputText = Read-Host
|
||||
|
||||
$isStopCommand = 'quit','exit','stop','leave' -contains $inputText
|
||||
if ($isStopCommand -eq $false)
|
||||
{
|
||||
"[$Name] $inputText" | Add-Content -Path $Path
|
||||
}
|
||||
|
||||
|
||||
} until ($isStopCommand -eq $true)
|
||||
"[$Name left the chat]" | Add-Content -Path $Path
|
||||
|
||||
$process | Stop-Process
|
||||
}
|
||||
|
||||
|
||||
|
||||
function Get-ChatChannel
|
||||
{
|
||||
param
|
||||
(
|
||||
$HomeShare = $ServerShare
|
||||
|
||||
)
|
||||
|
||||
Get-ChildItem -Path $HomeShare -Filter *.txt -File |
|
||||
ForEach-Object {
|
||||
[PSCustomObject]@{
|
||||
ChannelName = [System.IO.Path]::GetFileNameWithoutExtension($_.Name)
|
||||
LastActive = $_.LastWriteTime
|
||||
Started = $_.CreationTime
|
||||
}
|
||||
}
|
||||
}
|
||||
28
Powershell/Scripts/fetch-repo.ps1
Normal file
28
Powershell/Scripts/fetch-repo.ps1
Normal file
@@ -0,0 +1,28 @@
|
||||
<#
|
||||
.SYNTAX fetch-repo.ps1 [<repo-dir>]
|
||||
.DESCRIPTION fetches updates for a local Git repository (including submodules)
|
||||
.LINK https://github.com/fleschutz/PowerShell
|
||||
.NOTES Author: Markus Fleschutz / License: CC0
|
||||
#>
|
||||
|
||||
param($RepoDir = "$PWD")
|
||||
|
||||
try {
|
||||
if (-not(test-path "$RepoDir" -pathType container)) { throw "Can't access directory: $RepoDir" }
|
||||
set-location "$RepoDir"
|
||||
|
||||
$RepoDirName = (get-item "$RepoDir").Name
|
||||
"⏳ Fetching updates for Git repository 📂$RepoDirName ..."
|
||||
|
||||
$Null = (git --version)
|
||||
if ($lastExitCode -ne "0") { throw "Can't execute 'git' - make sure Git is installed and available" }
|
||||
|
||||
& git fetch --all --recurse-submodules --jobs=4
|
||||
if ($lastExitCode -ne "0") { throw "'git fetch' failed" }
|
||||
|
||||
"✔️ fetched Git repository 📂$RepoDirName"
|
||||
exit 0
|
||||
} catch {
|
||||
write-error "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
exit 1
|
||||
}
|
||||
37
Powershell/Scripts/fetch-repos.ps1
Normal file
37
Powershell/Scripts/fetch-repos.ps1
Normal file
@@ -0,0 +1,37 @@
|
||||
<#
|
||||
.SYNTAX fetch-repos.ps1 [<parent-dir>]
|
||||
.DESCRIPTION fetches updates for all Git repositories under the current/given directory (including submodules)
|
||||
.LINK https://github.com/fleschutz/PowerShell
|
||||
.NOTES Author: Markus Fleschutz / License: CC0
|
||||
#>
|
||||
|
||||
param($ParentDir = "$PWD")
|
||||
|
||||
try {
|
||||
$StopWatch = [system.diagnostics.stopwatch]::startNew()
|
||||
|
||||
if (-not(test-path "$ParentDir" -pathType container)) { throw "Can't access directory: $ParentDir" }
|
||||
|
||||
$Null = (git --version)
|
||||
if ($lastExitCode -ne "0") { throw "Can't execute 'git' - make sure Git is installed and available" }
|
||||
|
||||
$Folders = (get-childItem "$ParentDir" -attributes Directory)
|
||||
$FolderCount = $Folders.Count
|
||||
$ParentDirName = (get-item "$ParentDir").Name
|
||||
"Fetching updates for $FolderCount Git repositories at 📂$ParentDirName..."
|
||||
|
||||
foreach ($Folder in $Folders) {
|
||||
$FolderName = (get-item "$Folder").Name
|
||||
"🢃 Fetching 📂$FolderName..."
|
||||
|
||||
& git -C "$Folder" fetch --all --recurse-submodules --jobs=4
|
||||
if ($lastExitCode -ne "0") { throw "'git fetch' failed" }
|
||||
}
|
||||
|
||||
[int]$Elapsed = $StopWatch.Elapsed.TotalSeconds
|
||||
"✔️ fetched $FolderCount Git repositories at 📂$ParentDirName in $Elapsed sec"
|
||||
exit 0
|
||||
} catch {
|
||||
write-error "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
exit 1
|
||||
}
|
||||
BIN
Powershell/Scripts/folder.jpg
Normal file
BIN
Powershell/Scripts/folder.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 6.0 KiB |
32
Powershell/Scripts/generate-qrcode.ps1
Normal file
32
Powershell/Scripts/generate-qrcode.ps1
Normal file
@@ -0,0 +1,32 @@
|
||||
<#
|
||||
.SYNTAX generate-qrcode.ps1 [<text>] [<image-size>]
|
||||
.DESCRIPTION generates a QR code
|
||||
.LINK https://github.com/fleschutz/PowerShell
|
||||
.NOTES Author: Markus Fleschutz / License: CC0
|
||||
#>
|
||||
|
||||
param($Text = "", $ImageSize = "")
|
||||
if ($Text -eq "") { $Text = read-host "Enter text or URL" }
|
||||
if ($ImageSize -eq "") { $ImageSize = read-host "Enter image size (e.g. 500x500)" }
|
||||
|
||||
try {
|
||||
$ECC = "M" # can be L, M, Q, H
|
||||
$QuietZone = 1
|
||||
$ForegroundColor = "000000"
|
||||
$BackgroundColor = "ffffff"
|
||||
$FileFormat = "jpg"
|
||||
$PathToRepo = "$PSScriptRoot/.."
|
||||
$NewFile = "$PathToRepo/Data/qrcode.jpg"
|
||||
|
||||
$WebClient = new-object System.Net.WebClient
|
||||
$WebClient.DownloadFile(("http://api.qrserver.com/v1/create-qr-code/?data=" + $Text + "&ecc=" + $ECC +`
|
||||
"&size=" + $ImageSize + "&qzone=" + $QuietZone + `
|
||||
"&color=" + $ForegroundColor + "&bgcolor=" + $BackgroundColor.Text + `
|
||||
"&format=" + $FileFormat), $NewFile)
|
||||
|
||||
write-host -foregroundColor green "Done - QR code has been written to $NewFile"
|
||||
exit 0
|
||||
} catch {
|
||||
write-error "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
exit 1
|
||||
}
|
||||
20
Powershell/Scripts/hashdir.sh
Normal file
20
Powershell/Scripts/hashdir.sh
Normal file
@@ -0,0 +1,20 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# requires <hashdeep>
|
||||
|
||||
if [ -r new_hashes.xml ]
|
||||
then
|
||||
echo "Found new_hashes.xml, renaming it to known_hashes.xml ..."
|
||||
mv new_hashes.xml known_hashes.xml
|
||||
fi
|
||||
|
||||
echo "Calculating new_hashes.xml of folder $1 ..."
|
||||
hashdeep -c md5,sha1,sha256,tiger,whirlpool -r -d -l -j 1 $1 > new_hashes.xml
|
||||
|
||||
if [ -r known_hashes.xml ]
|
||||
then
|
||||
echo "This has changed:"
|
||||
diff known_hashes.xml new_hashes.xml
|
||||
fi
|
||||
|
||||
exit 0
|
||||
17
Powershell/Scripts/hibernate.ps1
Normal file
17
Powershell/Scripts/hibernate.ps1
Normal file
@@ -0,0 +1,17 @@
|
||||
<#
|
||||
.SYNTAX hibernate.ps1
|
||||
.DESCRIPTION enables hibernate mode for the local computer (needs admin rights)
|
||||
.LINK https://github.com/fleschutz/PowerShell
|
||||
.NOTES Author: Markus Fleschutz / License: CC0
|
||||
#>
|
||||
|
||||
#Requires -RunAsAdministrator
|
||||
|
||||
try {
|
||||
[Void][System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
|
||||
[System.Windows.Forms.Application]::SetSuspendState("Hibernate", $false, $false);
|
||||
exit 0
|
||||
} catch {
|
||||
write-error "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
exit 1
|
||||
}
|
||||
20
Powershell/Scripts/inspect-exe.ps1
Normal file
20
Powershell/Scripts/inspect-exe.ps1
Normal file
@@ -0,0 +1,20 @@
|
||||
<#
|
||||
.SYNTAX inspect-exe.ps1 [<path-to-exe-file>]
|
||||
.DESCRIPTION prints basic information of the given executable file
|
||||
.LINK https://github.com/fleschutz/PowerShell
|
||||
.NOTES Author: Markus Fleschutz / License: CC0
|
||||
#>
|
||||
|
||||
param($PathToExe = "")
|
||||
|
||||
if ($PathToExe -eq "" ) {
|
||||
$PathToExe = read-host "Enter path to executable file"
|
||||
}
|
||||
|
||||
try {
|
||||
get-childitem $PathToExe | % {$_.VersionInfo} | Select *
|
||||
exit 0
|
||||
} catch {
|
||||
write-error "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
exit 1
|
||||
}
|
||||
19
Powershell/Scripts/install-google-chrome.ps1
Normal file
19
Powershell/Scripts/install-google-chrome.ps1
Normal file
@@ -0,0 +1,19 @@
|
||||
<#
|
||||
.SYNTAX install-google-chrome.ps1
|
||||
.DESCRIPTION silently installs latest Google Chrome
|
||||
.LINK https://github.com/fleschutz/PowerShell
|
||||
.NOTES Author: Markus Fleschutz / License: CC0
|
||||
#>
|
||||
|
||||
try {
|
||||
$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
|
||||
write-host -foregroundColor green "✔️ installed Google Chrome"
|
||||
exit 0
|
||||
} catch {
|
||||
write-error "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
exit 1
|
||||
}
|
||||
37
Powershell/Scripts/install-signal-cli.ps1
Normal file
37
Powershell/Scripts/install-signal-cli.ps1
Normal file
@@ -0,0 +1,37 @@
|
||||
<#
|
||||
.SYNTAX install-signal-cli.ps1 [<version>]
|
||||
.DESCRIPTION installs signal-cli from github.com/AsamK/signal-cli
|
||||
.LINK https://github.com/fleschutz/PowerShell
|
||||
.NOTES Author: Markus Fleschutz / License: CC0
|
||||
#>
|
||||
|
||||
param($Version = "")
|
||||
if ($Version -eq "") { $Version = read-host "Enter version to install (see https://github.com/AsamK/signal-cli)" }
|
||||
|
||||
try {
|
||||
$StopWatch = [system.diagnostics.stopwatch]::startNew()
|
||||
|
||||
set-location /tmp
|
||||
|
||||
& wget --version
|
||||
if ($lastExitCode -ne "0") { throw "Can't execute 'wget' - make sure wget is installed and available" }
|
||||
|
||||
& wget "https://github.com/AsamK/signal-cli/releases/download/v$Version/signal-cli-$($Version).tar.gz"
|
||||
if ($lastExitCode -ne "0") { throw "'wget' failed" }
|
||||
|
||||
sudo tar xf "signal-cli-$Version.tar.gz" -C /opt
|
||||
if ($lastExitCode -ne "0") { throw "'sudo tar xf' failed" }
|
||||
|
||||
sudo ln -sf "/opt/signal-cli-$Version/bin/signal-cli" /usr/local/bin/
|
||||
if ($lastExitCode -ne "0") { throw "'sudo ln -sf' failed" }
|
||||
|
||||
rm "signal-cli-$Version.tar.gz"
|
||||
if ($lastExitCode -ne "0") { throw "'rm' failed" }
|
||||
|
||||
[int]$Elapsed = $StopWatch.Elapsed.TotalSeconds
|
||||
"✔️ installed signal-cli $Version to /opt and /usr/local/bin in $Elapsed sec"
|
||||
exit 0
|
||||
} catch {
|
||||
write-error "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
exit 1
|
||||
}
|
||||
29
Powershell/Scripts/introduce-powershell.ps1
Normal file
29
Powershell/Scripts/introduce-powershell.ps1
Normal file
@@ -0,0 +1,29 @@
|
||||
<#
|
||||
.SYNTAX introduce-powershell.ps1
|
||||
.DESCRIPTION introduces PowerShell to new users
|
||||
.LINK https://github.com/fleschutz/PowerShell
|
||||
.NOTES Author: Markus Fleschutz / License: CC0
|
||||
#>
|
||||
|
||||
try {
|
||||
& "$PSScriptRoot/write-big.ps1" "PowerShell"
|
||||
|
||||
& "$PSScriptRoot/write-animated.ps1" "Welcome to PowerShell"
|
||||
& "$PSScriptRoot/write-animated.ps1" "Feel the power of the console and scripting"
|
||||
|
||||
""
|
||||
"* Want to learn PowerShell? See the tutorials at: https://www.guru99.com/powershell-tutorial.html"
|
||||
""
|
||||
"* Need documentation? See the PowerShell docs at: https://docs.microsoft.com/en-us/powershell/"
|
||||
""
|
||||
"* Want sample scripts? See PowerShell Scripts at: https://github.com/fleschutz/PowerShell/"
|
||||
""
|
||||
|
||||
& "$PSScriptRoot/write-typewriter.ps1" "P.S. PowerShell is looking forward to execute your next command"
|
||||
""
|
||||
|
||||
exit 0
|
||||
} catch {
|
||||
write-error "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
exit 1
|
||||
}
|
||||
25
Powershell/Scripts/ipfs-publish.sh
Normal file
25
Powershell/Scripts/ipfs-publish.sh
Normal file
@@ -0,0 +1,25 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Syntax: ./ipfs-publish <dir-tree>
|
||||
# Description: publishes the given directory tree to IPFS
|
||||
# Author: Markus Fleschutz
|
||||
# Source: github.com/fleschutz/PowerShell
|
||||
# License: CC0
|
||||
# NOTE: requires <ipfs> and <hashdeep>
|
||||
|
||||
DIR=$1
|
||||
IPFS_HASHES="IPFS_hash_list.txt"
|
||||
DF_HASHES="checksum_list.xml"
|
||||
|
||||
echo "Publishing folder $DIR to IPFS"
|
||||
echo "(1/3) Removing Thumbs.db in subfolders ..."
|
||||
nice find "$DIR" -name Thumbs.db -exec rm -rf {} \;
|
||||
|
||||
echo "(2/3) Adding $DIR to IPFS ..."
|
||||
nice ipfs add -r "$DIR" > $IPFS_HASHES
|
||||
|
||||
echo "(3/3) Calculating digital forensics hashes to $DF_HASHES ..."
|
||||
nice hashdeep -c md5,sha1,sha256 -r -d -l -j 1 "$DIR" > $DF_HASHES
|
||||
|
||||
echo "OK - to publish the content execute: ipfs name publish <HASH>"
|
||||
exit 0
|
||||
14
Powershell/Scripts/list-aliases.ps1
Normal file
14
Powershell/Scripts/list-aliases.ps1
Normal file
@@ -0,0 +1,14 @@
|
||||
<#
|
||||
.SYNTAX list-aliases.ps1
|
||||
.DESCRIPTION lists all PowerShell aliases
|
||||
.LINK https://github.com/fleschutz/PowerShell
|
||||
.NOTES Author: Markus Fleschutz / License: CC0
|
||||
#>
|
||||
|
||||
try {
|
||||
get-alias
|
||||
exit 0
|
||||
} catch {
|
||||
write-error "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
exit 1
|
||||
}
|
||||
59
Powershell/Scripts/list-anagrams.ps1
Normal file
59
Powershell/Scripts/list-anagrams.ps1
Normal file
@@ -0,0 +1,59 @@
|
||||
<#
|
||||
.SYNTAX list-anagrams.ps1 [<word>] [<columns>]
|
||||
.DESCRIPTION lists all anagrams of the given word
|
||||
.LINK https://github.com/fleschutz/PowerShell
|
||||
.NOTES Author: Markus Fleschutz / License: CC0
|
||||
#>
|
||||
|
||||
param($Word = "", [int]$Columns = 8)
|
||||
|
||||
function GetPermutations {
|
||||
[cmdletbinding()]
|
||||
Param(
|
||||
[parameter(ValueFromPipeline=$True)]
|
||||
[string]$String = 'the'
|
||||
)
|
||||
Begin {
|
||||
Function NewAnagram { Param([int]$NewSize)
|
||||
if ($NewSize -eq 1) {
|
||||
return
|
||||
}
|
||||
for ($i=0;$i -lt $NewSize; $i++) {
|
||||
NewAnagram -NewSize ($NewSize - 1)
|
||||
if ($NewSize -eq 2) {
|
||||
New-Object PSObject -Property @{
|
||||
Permutation = $stringBuilder.ToString()
|
||||
}
|
||||
}
|
||||
MoveLeft -NewSize $NewSize
|
||||
}
|
||||
}
|
||||
Function MoveLeft { Param([int]$NewSize)
|
||||
$z = 0
|
||||
$position = ($Size - $NewSize)
|
||||
[char]$temp = $stringBuilder[$position]
|
||||
for ($z=($position+1);$z -lt $Size; $z++) {
|
||||
$stringBuilder[($z-1)] = $stringBuilder[$z]
|
||||
}
|
||||
$stringBuilder[($z-1)] = $temp
|
||||
}
|
||||
}
|
||||
Process {
|
||||
$size = $String.length
|
||||
$stringBuilder = New-Object System.Text.StringBuilder -ArgumentList $String
|
||||
NewAnagram -NewSize $Size
|
||||
}
|
||||
End {}
|
||||
}
|
||||
|
||||
try {
|
||||
if ($Word -eq "" ) {
|
||||
$Word = read-host "Enter word"
|
||||
$Columns = read-host "Enter number of columns"
|
||||
}
|
||||
GetPermutations -String $Word | Format-Wide -Column $Columns
|
||||
exit 0
|
||||
} catch {
|
||||
write-error "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
exit 1
|
||||
}
|
||||
70
Powershell/Scripts/list-automatic-variables.ps1
Normal file
70
Powershell/Scripts/list-automatic-variables.ps1
Normal file
@@ -0,0 +1,70 @@
|
||||
<#
|
||||
.SYNTAX list-automatic-variables.ps1
|
||||
.DESCRIPTION lists the automatic variables of PowerShell
|
||||
.LINK https://github.com/fleschutz/PowerShell
|
||||
.NOTES Author: Markus Fleschutz / License: CC0
|
||||
#>
|
||||
|
||||
function AddItem { param([string]$Variable, [string]$Content)
|
||||
new-object PSObject -property @{ 'Variable' = "$Variable"; 'Content' = "$Content" }
|
||||
}
|
||||
|
||||
function ListAutomaticVariables {
|
||||
AddItem "`$args" "$args"
|
||||
AddItem "`$ConsoleFileName" "$ConsoleFileName"
|
||||
AddItem "`$Error[0]" "$($Error[0])"
|
||||
AddItem "`$Event" "$Event"
|
||||
AddItem "`$EventArgs" "$EventArgs"
|
||||
AddItem "`$EventSubscriber" "$EventSubscriber"
|
||||
AddItem "`$ExecutionContext" "$ExecutionContext"
|
||||
AddItem "`$false" "$false"
|
||||
AddItem "`$foreach" "$foreach"
|
||||
AddItem "`$HOME" "$HOME"
|
||||
AddItem "`$input" "$input"
|
||||
AddItem "`$IsCoreCLR" "$IsCoreCLR"
|
||||
AddItem "`$IsLinux" "$IsLinux"
|
||||
AddItem "`$IsMacOS" "$IsMacOS"
|
||||
AddItem "`$IsWindows" "$IsWindows"
|
||||
AddItem "`$LastExitCode" "$LastExitCode"
|
||||
AddItem "`$Matches" "$Matches"
|
||||
AddItem "`$MyInvocation.PSScriptRoot" "$($MyInvocation.PSScriptRoot)"
|
||||
AddItem "`$MyInvocation.PSCommandPath" "$($MyInvocation.PSCommandPath)"
|
||||
AddItem "`$NestedPromptLevel" "$NestedPromptLevel"
|
||||
AddItem "`$null" "$null"
|
||||
AddItem "`$PID" "$PID"
|
||||
AddItem "`$PROFILE" "$PROFILE"
|
||||
AddItem "`$PSBoundParameters" "$PSBoundParameters"
|
||||
AddItem "`$PSCmdlet" "$PSCmdlet"
|
||||
AddItem "`$PSCommandPath" "$PSCommandPath"
|
||||
AddItem "`$PSCulture" "$PSCulture"
|
||||
AddItem "`$PSDebugContext" "$PSDebugContext"
|
||||
AddItem "`$PSHOME" "$PSHOME"
|
||||
AddItem "`$PSItem" "$PSItem"
|
||||
AddItem "`$PSScriptRoot" "$PSScriptRoot"
|
||||
AddItem "`$PSSenderInfo" "$PSSenderInfo"
|
||||
AddItem "`$PSUICulture" "$PSUICulture"
|
||||
AddItem "`$PSVersionTable.PSVersion" "$($PSVersionTable.PSVersion)"
|
||||
AddItem "`$PSVersionTable.PSEdition" "$($PSVersionTable.PSEdition)"
|
||||
AddItem "`$PSVersionTable.GitCommitId" "$($PSVersionTable.GitCommitId)"
|
||||
AddItem "`$PSVersionTable.OS" "$($PSVersionTable.OS)"
|
||||
AddItem "`$PSVersionTable.Platform" "$($PSVersionTable.Platform)"
|
||||
AddItem "`$PSVersionTable.PSCompatibleVersions" "$($PSVersionTable.PSCompatibleVersions)"
|
||||
AddItem "`$PSVersionTable.PSRemotingProtocolVersion" "$($PSVersionTable.PSRemotingProtocolVersion)"
|
||||
AddItem "`$PSVersionTable.SerializationVersion" "$($PSVersionTable.SerializationVersion)"
|
||||
AddItem "`$PSVersionTable.WSManStackVersion" "$($PSVersionTable.WSManStackVersion)"
|
||||
AddItem "`$PWD" "$PWD"
|
||||
AddItem "`$Sender" "$Sender"
|
||||
AddItem "`$ShellId" "$ShellId"
|
||||
AddItem "`$StackTrace" "$StackTrace"
|
||||
AddItem "`$switch" "$switch"
|
||||
AddItem "`$this" "$this"
|
||||
AddItem "`$true" "$true"
|
||||
}
|
||||
|
||||
try {
|
||||
ListAutomaticVariables | format-table -property Variable,Content
|
||||
exit 0
|
||||
} catch {
|
||||
write-error "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
exit 1
|
||||
}
|
||||
36
Powershell/Scripts/list-branches.ps1
Normal file
36
Powershell/Scripts/list-branches.ps1
Normal file
@@ -0,0 +1,36 @@
|
||||
<#
|
||||
.SYNTAX list-branches.ps1 [<repo-dir>] [<pattern>]
|
||||
.DESCRIPTION lists all branches in the current/given Git repository
|
||||
.LINK https://github.com/fleschutz/PowerShell
|
||||
.NOTES Author: Markus Fleschutz / License: CC0
|
||||
#>
|
||||
|
||||
param($RepoDir = "$PWD", $Pattern = "*")
|
||||
|
||||
try {
|
||||
if (-not(test-path "$RepoDir" -pathType container)) { throw "Can't access directory: $RepoDir" }
|
||||
|
||||
$Null = (git --version)
|
||||
if ($lastExitCode -ne "0") { throw "Can't execute 'git' - make sure Git is installed and available" }
|
||||
|
||||
& git -C "$RepoDir" fetch
|
||||
if ($lastExitCode -ne "0") { throw "'git fetch' failed" }
|
||||
|
||||
$Branches = $(git -C "$RepoDir" branch --list --remotes --no-color --no-column)
|
||||
if ($lastExitCode -ne "0") { throw "'git branch --list' failed" }
|
||||
|
||||
""
|
||||
"List of Git Branches"
|
||||
"--------------------"
|
||||
foreach($Branch in $Branches) {
|
||||
if ("$Branch" -match "origin/HEAD") { continue }
|
||||
$BranchName = $Branch.substring(9)
|
||||
if ("$BranchName" -notlike "$Pattern") { continue }
|
||||
"$BranchName"
|
||||
}
|
||||
""
|
||||
exit 0
|
||||
} catch {
|
||||
write-error "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
exit 1
|
||||
}
|
||||
36
Powershell/Scripts/list-cheat-sheet.ps1
Normal file
36
Powershell/Scripts/list-cheat-sheet.ps1
Normal file
@@ -0,0 +1,36 @@
|
||||
<#
|
||||
.SYNTAX list-cheat-sheet.ps1
|
||||
.DESCRIPTION lists the PowerShell cheat sheet
|
||||
.LINK https://github.com/fleschutz/PowerShell
|
||||
.NOTES Author: Markus Fleschutz / License: CC0
|
||||
#>
|
||||
|
||||
"PowerShell Cheat Sheet"
|
||||
"======================"
|
||||
""
|
||||
"Basic Commands"
|
||||
"--------------"
|
||||
" Cmdlet : Commands built into shell written in .NET"
|
||||
" Functions : Commands written in PowerShell language"
|
||||
" Parameter : Argument to a Cmdlet/Function/Script"
|
||||
" Alias : Shortcut for a Cmdlet or Function"
|
||||
" Scripts : Text files with .ps1 extension"
|
||||
" Applications : Existing windows programs"
|
||||
" Pipelines : Pass objects Get-process word | Stop-Process"
|
||||
" Ctrl+c : Interrupt current command"
|
||||
" Left/right : Navigate editing cursor"
|
||||
"Ctrl+left/right : Navigate a word at a time"
|
||||
" Home / End : End Move to start / end of line"
|
||||
" Up / down : Move up and down through history"
|
||||
" Insert : Toggles between insert/overwrite mode"
|
||||
" F7 : Command history in a window"
|
||||
"Tab / Shift-Tab : Command line completion"
|
||||
""
|
||||
"Variables"
|
||||
"---------"
|
||||
" `$var = `"string`" : Assign variable"
|
||||
"`$a,`$b = 0 or `$a,`$b = 'a','b' : Assign multiple variables"
|
||||
" `$a,`$b = `$b,`$a : Flip variables"
|
||||
" `$var=[int]5 : Strongly typed variable"
|
||||
""
|
||||
exit 0
|
||||
19
Powershell/Scripts/list-city-weather.ps1
Normal file
19
Powershell/Scripts/list-city-weather.ps1
Normal file
@@ -0,0 +1,19 @@
|
||||
<#
|
||||
.SYNTAX list-city-weather.ps1
|
||||
.DESCRIPTION list the current weather of cities world-wide (west to east)
|
||||
.LINK https://github.com/fleschutz/PowerShell
|
||||
.NOTES Author: Markus Fleschutz / License: CC0
|
||||
#>
|
||||
|
||||
$Cities="Hawaii","Los Angeles","Mexico City","Miami","New York","Rio de Janeiro","Paris","London","Berlin","Cape Town","Dubai","Mumbai","Singapore","Hong Kong","Peking","Tokyo","Sydney"
|
||||
|
||||
try {
|
||||
foreach($City in $Cities) {
|
||||
$Line = (Invoke-WebRequest http://wttr.in/${City}?format="%c %l+%t+%p+%h+%P+%w +%S →+%s" -UserAgent "curl").Content
|
||||
"$Line"
|
||||
}
|
||||
exit 0
|
||||
} catch {
|
||||
write-error "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
exit 1
|
||||
}
|
||||
14
Powershell/Scripts/list-clipboard.ps1
Normal file
14
Powershell/Scripts/list-clipboard.ps1
Normal file
@@ -0,0 +1,14 @@
|
||||
<#
|
||||
.SYNTAX list-clipboard.ps1
|
||||
.DESCRIPTION lists the contents of the clipboard
|
||||
.LINK https://github.com/fleschutz/PowerShell
|
||||
.NOTES Author: Markus Fleschutz / License: CC0
|
||||
#>
|
||||
|
||||
try {
|
||||
"📋 $(get-clipboard)"
|
||||
exit 0
|
||||
} catch {
|
||||
write-error "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
exit 1
|
||||
}
|
||||
14
Powershell/Scripts/list-cmdlets.ps1
Normal file
14
Powershell/Scripts/list-cmdlets.ps1
Normal file
@@ -0,0 +1,14 @@
|
||||
<#
|
||||
.SYNTAX list-cmdlets.ps1
|
||||
.DESCRIPTION lists all PowerShell cmdlets
|
||||
.LINK https://github.com/fleschutz/PowerShell
|
||||
.NOTES Author: Markus Fleschutz / License: CC0
|
||||
#>
|
||||
|
||||
try {
|
||||
Get-Command -Command-Type cmdlet
|
||||
exit 0
|
||||
} catch {
|
||||
write-error "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
exit 1
|
||||
}
|
||||
36
Powershell/Scripts/list-commits.ps1
Normal file
36
Powershell/Scripts/list-commits.ps1
Normal file
@@ -0,0 +1,36 @@
|
||||
<#
|
||||
.SYNTAX list-commits.ps1 [<repo-dir>] [<format>]
|
||||
.DESCRIPTION lists all commits in the current/given Git repository
|
||||
.LINK https://github.com/fleschutz/PowerShell
|
||||
.NOTES Author: Markus Fleschutz / License: CC0
|
||||
#>
|
||||
|
||||
param($RepoDir = "$PWD", $Format = "compact")
|
||||
|
||||
try {
|
||||
if (-not(test-path "$RepoDir" -pathType container)) { throw "Can't access directory: $RepoDir" }
|
||||
set-location "$RepoDir"
|
||||
|
||||
$Null = (git --version)
|
||||
if ($lastExitCode -ne "0") { throw "Can't execute 'git' - make sure Git is installed and available" }
|
||||
|
||||
& git fetch
|
||||
if ($lastExitCode -ne "0") { throw "'git fetch' failed" }
|
||||
|
||||
write-output ""
|
||||
write-output "List of Git Commits"
|
||||
write-output "-------------------"
|
||||
if ($Format -eq "compact") {
|
||||
& git log --graph --pretty=format:'%Cred%h%Creset%C(yellow)%d%Creset %s %C(bold blue)by %an %cr%Creset' --abbrev-commit
|
||||
if ($lastExitCode -ne "0") { throw "'git log' failed" }
|
||||
} else {
|
||||
& git log
|
||||
if ($lastExitCode -ne "0") { throw "'git log' failed" }
|
||||
}
|
||||
write-output ""
|
||||
write-output ""
|
||||
exit 0
|
||||
} catch {
|
||||
write-error "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
exit 1
|
||||
}
|
||||
41
Powershell/Scripts/list-credits.ps1
Normal file
41
Powershell/Scripts/list-credits.ps1
Normal file
@@ -0,0 +1,41 @@
|
||||
<#
|
||||
.SYNTAX list-credits.ps1
|
||||
.DESCRIPTION shows the credits
|
||||
.LINK https://github.com/fleschutz/PowerShell
|
||||
.NOTES Author: Markus Fleschutz / License: CC0
|
||||
#>
|
||||
|
||||
try {
|
||||
clear-host
|
||||
""
|
||||
" ______ ______ ______ _____ __ ______ ______ "
|
||||
" /\ ___\ /\ == \ /\ ___\ /\ __-. /\ \ /\__ _\ /\ ___\ "
|
||||
" \ \ \____ \ \ __< \ \ __\ \ \ \/\ \ \ \ \ \/_/\ \/ \ \___ \ "
|
||||
" \ \_____\ \ \_\ \_\ \ \_____\ \ \____- \ \_\ \ \_\ \/\_____\ "
|
||||
" \/_____/ \/_/ /_/ \/_____/ \/____/ \/_/ \/_/ \/_____/ "
|
||||
""
|
||||
|
||||
& "$PSScriptRoot/write-animated.ps1" "Typos: Markus Fleschutz"
|
||||
& "$PSScriptRoot/write-animated.ps1" "Keyboard: Rapoo 12335 E9270P WL Ultra-Slim Touch"
|
||||
& "$PSScriptRoot/write-animated.ps1" "Operating Systems: Windows 10 20H2 & Ubuntu Server 20.04 LTS"
|
||||
& "$PSScriptRoot/write-animated.ps1" "Console: Windows Terminal 1.7.1033.0"
|
||||
& "$PSScriptRoot/write-animated.ps1" "Background Image: Asteroid Field by starwars.com"
|
||||
& "$PSScriptRoot/write-animated.ps1" "Shell: PowerShell 5.1 & PowerShell 7.1.3"
|
||||
& "$PSScriptRoot/write-animated.ps1" "Scripts: PowerShell Scripts 0.2"
|
||||
& "$PSScriptRoot/write-animated.ps1" "GitHub: github.com/fleschutz/PowerShell"
|
||||
& "$PSScriptRoot/write-animated.ps1" "Git: version 2.30"
|
||||
& "$PSScriptRoot/write-animated.ps1" "SSH: OpenSSH version 7.7p1"
|
||||
& "$PSScriptRoot/write-animated.ps1" "Unicode: version 13.0"
|
||||
& "$PSScriptRoot/write-animated.ps1" "Song #1: Epic Song by BoxCat Games from Free Music Archive"
|
||||
& "$PSScriptRoot/write-animated.ps1" "Song #2: Siesta by Jahzzar from Free Music Archive"
|
||||
& "$PSScriptRoot/write-animated.ps1" "Executive Producer: Markus Fleschutz"
|
||||
& "$PSScriptRoot/write-animated.ps1" "Special Thanks: Andrea Fleschutz"
|
||||
& "$PSScriptRoot/write-animated.ps1" "Copyright: (c) 2021. All Rights Reserved"
|
||||
& "$PSScriptRoot/write-animated.ps1" "No Animals Were Harmed in the Making of This Film"
|
||||
|
||||
& "$PSScriptRoot/write-big.ps1" " Thanx 4 watching"
|
||||
exit 0
|
||||
} catch {
|
||||
write-error "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
exit 1
|
||||
}
|
||||
43
Powershell/Scripts/list-dir-tree.ps1
Normal file
43
Powershell/Scripts/list-dir-tree.ps1
Normal file
@@ -0,0 +1,43 @@
|
||||
<#
|
||||
.SYNTAX list-dir-tree.ps1 [<dir-tree>]
|
||||
.DESCRIPTION lists a directory tree
|
||||
.LINK https://github.com/fleschutz/PowerShell
|
||||
.NOTES Author: Markus Fleschutz / License: CC0
|
||||
#>
|
||||
|
||||
param($DirTree = "$PWD")
|
||||
|
||||
function ListDir { param([string]$Directory, [int]$Depth)
|
||||
$Depth++
|
||||
$Items = get-childItem -path $Directory
|
||||
foreach ($Item in $Items) {
|
||||
$Filename = $Item.Name
|
||||
if ($Item.Mode -like "d*") {
|
||||
for ($i = 0; $i -lt $Depth; $i++) {
|
||||
write-host -nonewline "+--"
|
||||
}
|
||||
write-host -foregroundColor green "📂$Filename"
|
||||
ListDir "$Directory\$Filename" $Depth
|
||||
$global:Dirs++
|
||||
} else {
|
||||
for ($i = 1; $i -lt $Depth; $i++) {
|
||||
write-host -nonewline "| "
|
||||
}
|
||||
write-host "|-$Filename ($($Item.Length) bytes)"
|
||||
$global:Files++
|
||||
$global:Bytes += $Item.Length
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
[int]$global:Dirs = 1
|
||||
[int]$global:Files = 0
|
||||
[int]$global:Bytes = 0
|
||||
ListDir $DirTree 0
|
||||
write-host "($($global:Dirs) directories, $($global:Files) files, $($global:Bytes) bytes total)"
|
||||
exit 0
|
||||
} catch {
|
||||
write-error "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
exit 1
|
||||
}
|
||||
30
Powershell/Scripts/list-dir.ps1
Normal file
30
Powershell/Scripts/list-dir.ps1
Normal file
@@ -0,0 +1,30 @@
|
||||
<#
|
||||
.SYNTAX list-dir.ps1 [<pattern>]
|
||||
.DESCRIPTION lists the directory content formatted in columns
|
||||
.LINK https://github.com/fleschutz/PowerShell
|
||||
.NOTES Author: Markus Fleschutz / License: CC0
|
||||
#>
|
||||
|
||||
param($Pattern = "*")
|
||||
|
||||
function ListDir { param([string]$Pattern)
|
||||
$Items = get-childItem -path "$Pattern"
|
||||
foreach ($Item in $Items) {
|
||||
$Name = $Item.Name
|
||||
if ($Name[0] -eq '.') { continue } # hidden file/dir
|
||||
if ($Item.Mode -like "d*") { $Icon = "📂"
|
||||
} elseif ($Name -like "*.iso") { $Icon = "📀"
|
||||
} elseif ($Name -like "*.mp3") { $Icon = "🎵"
|
||||
} elseif ($Name -like "*.epub") { $Icon = "📓"
|
||||
} else { $Icon = "📄" }
|
||||
new-object PSObject -Property @{ Name = "$Icon$Name" }
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
ListDir $Pattern | format-wide -autoSize
|
||||
exit 0
|
||||
} catch {
|
||||
write-error "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
exit 1
|
||||
}
|
||||
14
Powershell/Scripts/list-drives.ps1
Normal file
14
Powershell/Scripts/list-drives.ps1
Normal file
@@ -0,0 +1,14 @@
|
||||
<#
|
||||
.SYNTAX list-drives.ps1
|
||||
.DESCRIPTION lists all drives connected to the computer
|
||||
.LINK https://github.com/fleschutz/PowerShell
|
||||
.NOTES Author: Markus Fleschutz / License: CC0
|
||||
#>
|
||||
|
||||
try {
|
||||
get-PSDrive -PSProvider FileSystem
|
||||
exit 0
|
||||
} catch {
|
||||
write-error "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
exit 1
|
||||
}
|
||||
26
Powershell/Scripts/list-earthquakes.ps1
Normal file
26
Powershell/Scripts/list-earthquakes.ps1
Normal file
@@ -0,0 +1,26 @@
|
||||
<#
|
||||
.SYNTAX list-earthquakes.ps1
|
||||
.DESCRIPTION lists earthquakes with magnitude >= 6.0 for the last 30 days
|
||||
.LINK https://github.com/fleschutz/PowerShell
|
||||
.NOTES Author: Markus Fleschutz / License: CC0
|
||||
#>
|
||||
|
||||
$Format="csv" # csv, geojson, kml, text, xml
|
||||
$MinMagnitude=5.8
|
||||
$OrderBy="magnitude" # time, time-asc, magnitude, magnitude-asc
|
||||
|
||||
function ListEarthquakes {
|
||||
write-progress "Loading data ..."
|
||||
$Earthquakes = (invoke-webRequest -uri "https://earthquake.usgs.gov/fdsnws/event/1/query?format=$Format&minmagnitude=$MinMagnitude&orderby=$OrderBy" -userAgent "curl" -useBasicParsing).Content | ConvertFrom-CSV
|
||||
foreach ($Quake in $Earthquakes) {
|
||||
new-object PSObject -Property @{ Mag=$Quake.mag; Depth=$Quake.depth; Location=$Quake.place; Time=$Quake.time }
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
ListEarthquakes | format-table -property @{e='Mag';width=5},@{e='Location';width=42},@{e='Depth';width=6},Time
|
||||
exit 0
|
||||
} catch {
|
||||
write-error "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
exit 1
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user