This commit is contained in:
Markus Fleschutz 2020-12-25 10:30:43 +00:00
parent 4cb019eee0
commit 94106839fd
51 changed files with 164 additions and 174 deletions

View File

@ -7,15 +7,14 @@
# License: CC0 # License: CC0
param([string]$File) param([string]$File)
if ($File -eq "" ) {
$File = read-host "Enter file"
}
try { try {
if ($File -eq "" ) {
$File = read-host "Enter path to file"
}
$Result = get-filehash $File -algorithm MD5 $Result = get-filehash $File -algorithm MD5
write-host "✔️ MD5 hash is" $Result.Hash write-output "MD5 hash is" $Result.Hash
exit 0 exit 0
} catch { } catch {
Write-Error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" write-error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1 exit 1
} }

View File

@ -7,15 +7,15 @@
# License: CC0 # License: CC0
param([string]$File) param([string]$File)
if ($File -eq "" ) {
$File = read-host "Enter file"
}
try { try {
if ($File -eq "" ) {
$File = read-host "Enter file"
}
$Result = get-filehash $File -algorithm SHA1 $Result = get-filehash $File -algorithm SHA1
write-host "✔️ SHA1 hash is" $Result.Hash write-output "SHA1 hash is" $Result.Hash
exit 0 exit 0
} catch { } catch {
Write-Error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" write-error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1 exit 1
} }

View File

@ -7,15 +7,15 @@
# License: CC0 # License: CC0
param([string]$File) param([string]$File)
if ($File -eq "" ) {
$File = read-host "Enter file"
}
try { try {
if ($File -eq "" ) {
$File = read-host "Enter file"
}
$Result = get-filehash $File -algorithm SHA256 $Result = get-filehash $File -algorithm SHA256
write-host "✔️ SHA256 hash is" $Result.Hash write-output "SHA256 hash is:" $Result.Hash
exit 0 exit 0
} catch { } catch {
Write-Error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" write-error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1 exit 1
} }

View File

@ -18,6 +18,6 @@ try {
exit 0 exit 0
} catch { } catch {
Write-Error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" write-error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1 exit 1
} }

View File

@ -36,6 +36,6 @@ try {
exit 0 exit 0
} }
} catch { } catch {
write-warning "$($MyInvocation.MyCommand.Name) - Error: $($_.Exception.Message) - Line Number: $($_.InvocationInfo.ScriptLineNumber)" write-error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1 exit 1
} }

View File

@ -16,9 +16,9 @@ try {
} }
} }
write-host "Done." write-output "Done."
exit 0 exit 0
} catch { } catch {
Write-Error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" write-error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1 exit 1
} }

View File

@ -16,9 +16,9 @@ try {
git config --global user.email $UserEmail git config --global user.email $UserEmail
git config --global core.editor $UserEditor git config --global core.editor $UserEditor
git config --global init.defaultBranch main git config --global init.defaultBranch main
echo "Done." write-output "Done."
exit 0 exit 0
} catch { } catch {
Write-Error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" write-error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1 exit 1
} }

View File

@ -21,6 +21,6 @@ try {
} }
exit 0 exit 0
} catch { } catch {
Write-Error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" write-error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1 exit 1
} }

View File

@ -17,6 +17,6 @@ try {
} }
exit 0 exit 0
} catch { } catch {
Write-Error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" write-error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1 exit 1
} }

View File

@ -14,9 +14,9 @@ try {
} }
wget --mirror --convert-links --adjust-extension --page-requisites --no-parent $URL --directory-prefix . --no-verbose wget --mirror --convert-links --adjust-extension --page-requisites --no-parent $URL --directory-prefix . --no-verbose
Write-Output "OK." write-output "OK."
exit 0 exit 0
} catch { } catch {
Write-Error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" write-error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1 exit 1
} }

View File

@ -7,15 +7,14 @@
# License: CC0 # License: CC0
param([string]$File) param([string]$File)
if ($File -eq "" ) {
$File = read-host "Enter path to executable file"
}
try { try {
if ($File -eq "" ) {
$File = read-host "Enter path to executable file"
}
get-childitem $File | % {$_.VersionInfo} | Select * get-childitem $File | % {$_.VersionInfo} | Select *
exit 0 exit 0
} catch { } catch {
Write-Error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" write-error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1 exit 1
} }

View File

@ -56,6 +56,6 @@ try {
GetPermutations -String $Word | Format-Wide -Column $Columns GetPermutations -String $Word | Format-Wide -Column $Columns
exit 0 exit 0
} catch { } catch {
Write-Error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" write-error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1 exit 1
} }

View File

@ -10,6 +10,6 @@ try {
Get-Command -Command-Type cmdlet Get-Command -Command-Type cmdlet
exit 0 exit 0
} catch { } catch {
Write-Error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" write-error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1 exit 1
} }

View File

@ -11,10 +11,10 @@ $MinMagnitude=6.0
$OrderBy="time" # time, time-asc, magnitude, magnitude-asc $OrderBy="time" # time, time-asc, magnitude, magnitude-asc
try { try {
Write-Progress "Querying earthquakes for the last 30 days ..." write-progress "Querying earthquakes for the last 30 days ..."
(Invoke-WebRequest -Uri "https://earthquake.usgs.gov/fdsnws/event/1/query?format=$Format&minmagnitude=$MinMagnitude&orderby=$OrderBy" -UserAgent "curl" ).Content (Invoke-WebRequest -Uri "https://earthquake.usgs.gov/fdsnws/event/1/query?format=$Format&minmagnitude=$MinMagnitude&orderby=$OrderBy" -UserAgent "curl" ).Content
exit 0 exit 0
} catch { } catch {
Write-Error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" write-error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1 exit 1
} }

View File

@ -8,13 +8,12 @@
param([string]$DirTree) param([string]$DirTree)
write-host "Listing empty subfolders in $DirTree ..."
try { try {
write-progress "Listing empty subfolders in $DirTree ..."
(Get-ChildItem $DirTree -recurse | ? {$_.PSIsContainer -eq $True}) | ?{$_.GetFileSystemInfos().Count -eq 0} | select FullName (Get-ChildItem $DirTree -recurse | ? {$_.PSIsContainer -eq $True}) | ?{$_.GetFileSystemInfos().Count -eq 0} | select FullName
echo "Done." echo "Done."
exit 0 exit 0
} catch { } catch {
Write-Error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" write-error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1 exit 1
} }

View File

@ -10,6 +10,6 @@ try {
Get-Module Get-Module
exit 0 exit 0
} catch { } catch {
Write-Error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" write-error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1 exit 1
} }

View File

@ -10,6 +10,6 @@ try {
Get-Process | Format-Table -Property Id, @{Label="CPU(s)";Expression={$_.CPU.ToString("N")+"%"};Alignment="Right"}, ProcessName -AutoSize Get-Process | Format-Table -Property Id, @{Label="CPU(s)";Expression={$_.CPU.ToString("N")+"%"};Alignment="Right"}, ProcessName -AutoSize
exit 0 exit 0
} catch { } catch {
Write-Error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" write-error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1 exit 1
} }

View File

@ -17,6 +17,6 @@ try {
exit 0 exit 0
} catch { } catch {
Write-Error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" write-error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1 exit 1
} }

View File

@ -13,9 +13,9 @@ if ($City -eq "" ) {
try { try {
write-progress "Reading worldcities.csv..." write-progress "Reading worldcities.csv..."
$PathToData=(get-item $MyInvocation.MyCommand.Path).directory $PathToRepo=(get-item $MyInvocation.MyCommand.Path).directory.parent
$PathToData="$PathToData/../Data" $Table = import-csv "$PathToRepo/Data/worldcities.csv"
$Table = import-csv "$PathToData/worldcities.csv"
$FoundOne = 0 $FoundOne = 0
foreach($Row in $Table) { foreach($Row in $Table) {
if ($Row.city -eq $City) { if ($Row.city -eq $City) {
@ -35,6 +35,6 @@ try {
write-error "City $City not found" write-error "City $City not found"
exit 1 exit 1
} catch { } catch {
Write-Error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" write-error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1 exit 1
} }

View File

@ -7,15 +7,14 @@
# License: CC0 # License: CC0
param([string]$IPaddr) param([string]$IPaddr)
if ($IPaddr -eq "" ) {
$IPaddr = read-host "Enter IP address to locate"
}
try { try {
if ($IPaddr -eq "" ) {
$IPaddr = read-host "Enter IP address to locate"
}
$result = Invoke-RestMethod -Method Get -Uri "http://ip-api.com/json/$IPaddr" $result = Invoke-RestMethod -Method Get -Uri "http://ip-api.com/json/$IPaddr"
write-host $result write-output $result
exit 0 exit 0
} catch { } catch {
Write-Error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" write-error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1 exit 1
} }

View File

@ -7,18 +7,18 @@
# License: CC0 # License: CC0
param([string]$CountryCode, [string]$ZipCode) param([string]$CountryCode, [string]$ZipCode)
if ($CountryCode -eq "" ) {
$CountryCode = read-host "Enter the country code"
}
if ($ZipCode -eq "" ) {
$ZipCode = read-host "Enter the zip code"
}
$PathToDataDir=(get-item $MyInvocation.MyCommand.Path).directory
$PathToDataDir="$PathToDataDir/../Data"
try { try {
if ($CountryCode -eq "" ) {
$CountryCode = read-host "Enter the country code"
}
if ($ZipCode -eq "" ) {
$ZipCode = read-host "Enter the zip code"
}
write-progress "Reading zip-codes.csv..." write-progress "Reading zip-codes.csv..."
$Table = import-csv "$PathToDataDir/zip-codes.csv" $PathToRepo=(get-item $MyInvocation.MyCommand.Path).directory.parent
$Table = import-csv "$PathToRepo/Data/zip-codes.csv"
$FoundOne = 0 $FoundOne = 0
foreach($Row in $Table) { foreach($Row in $Table) {
@ -28,7 +28,7 @@ try {
$City = $Row.city $City = $Row.city
$Lat = $Row.latitude $Lat = $Row.latitude
$Lon = $Row.longitude $Lon = $Row.longitude
write-host "* $Country $ZipCode $City is at $Lat°N, $Lon°W" write-output "* $Country $ZipCode $City is at $Lat°N, $Lon°W"
$FoundOne = 1 $FoundOne = 1
} }
} }
@ -40,6 +40,6 @@ try {
write-error "Zip-code $ZipCode in country $CountryCode not found" write-error "Zip-code $ZipCode in country $CountryCode not found"
exit 1 exit 1
} catch { } catch {
Write-Error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" write-error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1 exit 1
} }

View File

@ -21,6 +21,6 @@ try {
pause pause
exit 0 exit 0
} catch { } catch {
Write-Error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" write-error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1 exit 1
} }

View File

@ -10,6 +10,6 @@ try {
(Invoke-WebRequest http://wttr.in/Moon -UserAgent "curl" ).Content (Invoke-WebRequest http://wttr.in/Moon -UserAgent "curl" ).Content
exit 0 exit 0
} catch { } catch {
Write-Error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" write-error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1 exit 1
} }

View File

@ -7,15 +7,14 @@
# License: CC0 # License: CC0
param([string]$emailAddress) param([string]$emailAddress)
if ($emailAddress -eq "" ) {
$emailAddress = "markus@fleschutz.de"
}
try { try {
if ($emailAddress -eq "" ) {
$emailAddress = "markus@fleschutz.de"
}
$URL="mailto:$emailAddress" $URL="mailto:$emailAddress"
Start-Process $URL Start-Process $URL
exit 0 exit 0
} catch { } catch {
Write-Error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" write-error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1 exit 1
} }

View File

@ -13,15 +13,15 @@ $RSS_URL = "https://yahoo.com/news/rss/world"
try { try {
[xml]$FileContent = (Invoke-WebRequest -Uri $RSS_URL).Content [xml]$FileContent = (Invoke-WebRequest -Uri $RSS_URL).Content
write-host "" write-output ""
write-host "+++ " $FileContent.rss.channel.title " +++" write-output "+++ " $FileContent.rss.channel.title " +++"
write-host "" write-output ""
foreach ($item in $FileContent.rss.channel.item) { foreach ($item in $FileContent.rss.channel.item) {
write-host "*" $item.title write-output "*" $item.title
} }
exit 0 exit 0
} catch { } catch {
Write-Error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" write-error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1 exit 1
} }

View File

@ -7,14 +7,13 @@
# License: CC0 # License: CC0
param([string]$URL) param([string]$URL)
if ($URL -eq "" ) {
$URL = "http://www.fleschutz.de"
}
try { try {
if ($URL -eq "" ) {
$URL = "http://www.fleschutz.de"
}
Start-Process $URL Start-Process $URL
exit 0 exit 0
} catch { } catch {
Write-Error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" write-error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1 exit 1
} }

View File

@ -10,6 +10,6 @@ try {
Start-Process "mailto:markus@fleschutz.de" Start-Process "mailto:markus@fleschutz.de"
exit 0 exit 0
} catch { } catch {
Write-Error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" write-error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1 exit 1
} }

View File

@ -11,6 +11,6 @@ try {
Stop-Computer Stop-Computer
exit 0 exit 0
} catch { } catch {
Write-Error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" write-error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1 exit 1
} }

View File

@ -11,6 +11,6 @@ try {
Restart-Computer Restart-Computer
exit 0 exit 0
} catch { } catch {
Write-Error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" write-error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1 exit 1
} }

View File

@ -13,14 +13,14 @@ $ErrorActionPreference= "silentlycontinue"
foreach($add in $range) { foreach($add in $range) {
$ip = "{0}.{1}" -F $network,$add $ip = "{0}.{1}" -F $network,$add
Write-Progress "Scanning IP $ip" -PercentComplete (($add/$range.Count)*100) write-progress "Scanning IP $ip" -PercentComplete (($add/$range.Count)*100)
if (Test-Connection -BufferSize 32 -Count 1 -quiet -ComputerName $ip) { if (Test-Connection -BufferSize 32 -Count 1 -quiet -ComputerName $ip) {
$socket = new-object System.Net.Sockets.TcpClient($ip, $port) $socket = new-object System.Net.Sockets.TcpClient($ip, $port)
if ($socket.Connected) { if ($socket.Connected) {
write-host "TCP port $port at $ip is open" write-output "TCP port $port at $ip is open"
$socket.Close() $socket.Close()
} else { } else {
write-host "TCP port $port at $ip is not open" write-output "TCP port $port at $ip is not open"
} }
} }
} }

View File

@ -23,6 +23,6 @@ try {
$smtp.Send($msg) $smtp.Send($msg)
exit 0 exit 0
} catch { } catch {
Write-Error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" write-error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1 exit 1
} }

View File

@ -8,17 +8,17 @@
param([string]$TargetIP, [int]$TargetPort, [string]$Message) param([string]$TargetIP, [int]$TargetPort, [string]$Message)
if ($TargetIP -eq "" ) {
$TargetIP = read-host "Enter target IP address"
}
if ($TargetPort -eq 0 ) {
$TargetPort = read-host "Enter target port"
}
if ($Message -eq "" ) {
$Message = read-host "Enter message to send"
}
try { try {
if ($TargetIP -eq "" ) {
$TargetIP = read-host "Enter target IP address"
}
if ($TargetPort -eq 0 ) {
$TargetPort = read-host "Enter target port"
}
if ($Message -eq "" ) {
$Message = read-host "Enter message to send"
}
$IP = [System.Net.Dns]::GetHostAddresses($TargetIP) $IP = [System.Net.Dns]::GetHostAddresses($TargetIP)
$Address = [System.Net.IPAddress]::Parse($IP) $Address = [System.Net.IPAddress]::Parse($IP)
$Socket = New-Object System.Net.Sockets.TCPClient($Address,$TargetPort) $Socket = New-Object System.Net.Sockets.TCPClient($Address,$TargetPort)
@ -31,9 +31,9 @@ try {
$Stream.Close() $Stream.Close()
$Socket.Close() $Socket.Close()
echo "Done." write-output "Done."
exit 0 exit 0
} catch { } catch {
Write-Error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" write-error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1 exit 1
} }

View File

@ -8,17 +8,17 @@
param([string]$TargetIP, [int]$TargetPort, [string]$Message) param([string]$TargetIP, [int]$TargetPort, [string]$Message)
if ($TargetIP -eq "" ) {
$TargetIP = read-host "Enter target IP address"
}
if ($TargetPort -eq 0 ) {
$TargetPort = read-host "Enter target port"
}
if ($Message -eq "" ) {
$Message = read-host "Enter message to send"
}
try { try {
if ($TargetIP -eq "" ) {
$TargetIP = read-host "Enter target IP address"
}
if ($TargetPort -eq 0 ) {
$TargetPort = read-host "Enter target port"
}
if ($Message -eq "" ) {
$Message = read-host "Enter message to send"
}
$IP = [System.Net.Dns]::GetHostAddresses($TargetIP) $IP = [System.Net.Dns]::GetHostAddresses($TargetIP)
$Address = [System.Net.IPAddress]::Parse($IP) $Address = [System.Net.IPAddress]::Parse($IP)
$EndPoints = New-Object System.Net.IPEndPoint($Address, $TargetPort) $EndPoints = New-Object System.Net.IPEndPoint($Address, $TargetPort)
@ -26,9 +26,9 @@ try {
$EncodedText = [Text.Encoding]::ASCII.GetBytes($Message) $EncodedText = [Text.Encoding]::ASCII.GetBytes($Message)
$SendMessage = $Socket.Send($EncodedText, $EncodedText.Length, $EndPoints) $SendMessage = $Socket.Send($EncodedText, $EncodedText.Length, $EndPoints)
$Socket.Close() $Socket.Close()
echo "Done." write-output "Done."
exit 0 exit 0
} catch { } catch {
Write-Error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" write-error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1 exit 1
} }

View File

@ -15,7 +15,7 @@ try {
write-progress "$i seconds" write-progress "$i seconds"
start-sleep -s 1 start-sleep -s 1
} }
write-host "OK - $Seconds seconds countdown finished" write-output "OK - $Seconds seconds countdown finished"
exit 0 exit 0
} catch { } catch {
write-error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" write-error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"

View File

@ -7,9 +7,9 @@
# License: CC0 # License: CC0
try { try {
$PathToData=(get-item $MyInvocation.MyCommand.Path).directory write-progress "Reading Matrix.csv..."
$PathToData="$PathToData/../Data" $PathToRepo=(get-item $MyInvocation.MyCommand.Path).directory.parent
$Table = import-csv "$PathToData/Matrix.csv" $Table = import-csv "$PathToRepo/Data/Matrix.csv"
Clear-Host Clear-Host
foreach($Row in $Table) { foreach($Row in $Table) {
@ -46,6 +46,6 @@ try {
} }
exit 0 exit 0
} catch { } catch {
Write-Error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" write-error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1 exit 1
} }

View File

@ -7,17 +7,16 @@
# License: CC0 # License: CC0
param([string]$File) param([string]$File)
if ($File -eq "") {
$File = read-host "Enter path to file"
}
try { try {
if ($File -eq "") {
$File = read-host "Enter path to file"
}
$Text = Get-Content $File $Text = Get-Content $File
$voice = New-Object ComObject SAPI.SPVoice $voice = New-Object ComObject SAPI.SPVoice
$voice.Speak($Text); $voice.Speak($Text);
exit 0 exit 0
} catch { } catch {
Write-Error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" write-error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1 exit 1
} }

View File

@ -7,15 +7,15 @@
# License: CC0 # License: CC0
param([string]$Text) param([string]$Text)
if ($Text -eq "") {
$Text = "Hello World!"
}
try { try {
if ($Text -eq "") {
$Text = read-host "Enter text to speak"
}
$voice = New-Object ComObject SAPI.SPVoice $voice = New-Object ComObject SAPI.SPVoice
$voice.Speak($Text); $voice.Speak($Text);
exit 0 exit 0
} catch { } catch {
Write-Error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" write-error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1 exit 1
} }

View File

@ -84,7 +84,7 @@ Function Get-TimedScreenshot {
#run screenshot function #run screenshot function
GenScreenshot GenScreenshot
Write-Verbose "Saved screenshot to $FilePath. Sleeping for $Interval seconds" write-verbose "Saved screenshot to $FilePath. Sleeping for $Interval seconds"
Start-Sleep -Seconds $Interval Start-Sleep -Seconds $Interval
} }
@ -93,6 +93,6 @@ Function Get-TimedScreenshot {
While ((Get-Date -Format HH:%m) -lt $EndTime) While ((Get-Date -Format HH:%m) -lt $EndTime)
} }
Catch {Write-Warning "$Error[0].ToString() + $Error[0].InvocationInfo.PositionMessage"} Catch {write-error "$Error[0].ToString() + $Error[0].InvocationInfo.PositionMessage"}
} }

View File

@ -84,7 +84,7 @@ Function Get-TimedScreenshot {
#run screenshot function #run screenshot function
GenScreenshot GenScreenshot
Write-Verbose "Saved screenshot to $FilePath. Sleeping for $Interval seconds" write-verbose "Saved screenshot to $FilePath. Sleeping for $Interval seconds"
Start-Sleep -Seconds $Interval Start-Sleep -Seconds $Interval
} }
@ -93,6 +93,6 @@ Function Get-TimedScreenshot {
While ((Get-Date -Format HH:%m) -lt $EndTime) While ((Get-Date -Format HH:%m) -lt $EndTime)
} }
Catch {Write-Warning "$Error[0].ToString() + $Error[0].InvocationInfo.PositionMessage"} Catch {write-error "$Error[0].ToString() + $Error[0].InvocationInfo.PositionMessage"}
} }

View File

@ -11,6 +11,6 @@ try {
echo $PSVersionTable echo $PSVersionTable
exit 0 exit 0
} catch { } catch {
Write-Error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" write-error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1 exit 1
} }

View File

@ -9,22 +9,21 @@
try { try {
$StartTime = Get-Date $StartTime = Get-Date
$PathToData=(get-item $MyInvocation.MyCommand.Path).directory $PathToRepo=(get-item $MyInvocation.MyCommand.Path).directory.parent
$PathToData="$PathToData/../Data" $Table = import-csv "$PathToRepo/Data/domain_table.csv"
$Table = import-csv "$PathToData/domain_table.csv"
foreach($Row in $Table) { foreach($Row in $Table) {
$Domain = $Row.Domain $Domain = $Row.Domain
Write-Progress "Training DNS cache with $Domain..." write-progress "Training DNS cache with $Domain..."
$Ignore = nslookup $Domain $Ignore = nslookup $Domain
} }
$Count = $Table.Length $Count = $Table.Length
$StopTime = Get-Date $StopTime = Get-Date
$TimeInterval = New-Timespan -start $StartTime -end $StopTime $TimeInterval = New-Timespan -start $StartTime -end $StopTime
Write-Output "OK - DNS cache trained with $Count domain names in $TimeInterval seconds" write-output "OK - DNS cache trained with $Count domain names in $TimeInterval seconds"
exit 0 exit 0
} catch { } catch {
Write-Error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" write-error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1 exit 1
} }

View File

@ -7,22 +7,22 @@
# License: CC0 # License: CC0
param([string]$SourceFile, [string]$SourceLanguage, [string]$TargetLanguage) param([string]$SourceFile, [string]$SourceLanguage, [string]$TargetLanguage)
if ($SourceFile -eq "" ) {
$SourceFile = read-host "Enter path to file"
}
if ($SourceLanguage -eq "" ) {
$SourceLanguage = read-host "Enter language of this file"
}
if ($TargetLanguage -eq "" ) {
$TargetLanguage = read-host "Enter language to translate to"
}
try { try {
$PathToData=(get-item $MyInvocation.MyCommand.Path).directory if ($SourceFile -eq "" ) {
$PathToData="$PathToData/../Data" $SourceFile = read-host "Enter path to file"
Start-Process -FilePath "$PathToData/trans" -ArgumentList "-i $SourceFile -s $SourceLanguage -t $TargetLanguage -e google -brief" -NoNewWindow -Wait }
if ($SourceLanguage -eq "" ) {
$SourceLanguage = read-host "Enter language of this file"
}
if ($TargetLanguage -eq "" ) {
$TargetLanguage = read-host "Enter language to translate to"
}
$PathToRepo=(get-item $MyInvocation.MyCommand.Path).directory.parent
Start-Process -FilePath "$PathToRepo/Data/trans" -ArgumentList "-i $SourceFile -s $SourceLanguage -t $TargetLanguage -e google -brief" -NoNewWindow -Wait
exit 0 exit 0
} catch { } catch {
Write-Error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" write-error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1 exit 1
} }

View File

@ -41,6 +41,6 @@ try {
} }
exit 0 exit 0
} catch { } catch {
Write-Error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" write-error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1 exit 1
} }

View File

@ -22,6 +22,6 @@ try {
$SpeechSynthesizer.Dispose() $SpeechSynthesizer.Dispose()
exit 0 exit 0
} catch { } catch {
Write-Error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" write-error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1 exit 1
} }

View File

@ -53,15 +53,15 @@ try {
$thisMAC=$array[1] $thisMAC=$array[1]
if ($thisHost -like $Hostname) { if ($thisHost -like $Hostname) {
Send-WOL $thisMAC Send-WOL $thisMAC
write-output "✔️ host $thisHost waked up (MAC $thisMAC)" write-output "OK - host $thisHost waked up (MAC $thisMAC)"
exit 0 exit 0
} }
} }
echo "Sorry, hostname $Hostname is unknown." write-output "Sorry, hostname $Hostname is unknown."
pause pause
exit 1 exit 1
} catch { } catch {
Write-Error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" write-error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1 exit 1
} }

View File

@ -34,6 +34,6 @@ try {
} }
exit 0 exit 0
} catch { } catch {
Write-Error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" write-error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1 exit 1
} }

View File

@ -12,6 +12,6 @@ try {
(Invoke-WebRequest http://v2d.wttr.in/$GeoLocation -UserAgent "curl" ).Content (Invoke-WebRequest http://v2d.wttr.in/$GeoLocation -UserAgent "curl" ).Content
exit 0 exit 0
} catch { } catch {
Write-Error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" write-error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1 exit 1
} }

View File

@ -19,6 +19,6 @@ try {
write-output "" write-output ""
exit 0 exit 0
} catch { } catch {
Write-Error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" write-error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1 exit 1
} }

View File

@ -12,6 +12,6 @@ try {
(Invoke-WebRequest http://wttr.in/$GeoLocation -UserAgent "curl" ).Content (Invoke-WebRequest http://wttr.in/$GeoLocation -UserAgent "curl" ).Content
exit 0 exit 0
} catch { } catch {
Write-Error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" write-error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1 exit 1
} }

View File

@ -15,14 +15,12 @@ $Speed = 250 # milliseconds
try { try {
$Random = New-Object System.Random $Random = New-Object System.Random
$Text -split '' | $Text -split '' | ForEach-Object {
ForEach-Object {
Write-Host -nonewline $_ Write-Host -nonewline $_
Start-Sleep -milliseconds $(1 + $Random.Next($Speed)) Start-Sleep -milliseconds $(1 + $Random.Next($Speed))
} }
exit 0 exit 0
} catch { } catch {
Write-Error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" write-error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1 exit 1
} }

View File

@ -7,14 +7,14 @@
# License: CC0 # License: CC0
param([string]$Path) param([string]$Path)
if ($Path -eq "" ) {
$URL = read-host "Enter path to folder to zip"
}
try { try {
if ($Path -eq "" ) {
$URL = read-host "Enter path to folder to zip"
}
Compress-Archive -Path $Path -DestinationPath $Path.zip Compress-Archive -Path $Path -DestinationPath $Path.zip
exit 0 exit 0
} catch { } catch {
Write-Error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" write-error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1 exit 1
} }