diff --git a/Scripts/MD5.ps1 b/Scripts/MD5.ps1 index 0c2e939a..6beec805 100755 --- a/Scripts/MD5.ps1 +++ b/Scripts/MD5.ps1 @@ -6,12 +6,13 @@ .NOTES Author: Markus Fleschutz / License: CC0 #> -param([string]$File = "") +param($File = "") + +if ($File -eq "" ) { + $File = read-host "Enter path to file" +} try { - if ($File -eq "" ) { - $File = read-host "Enter path to file" - } $Result = get-filehash $File -algorithm MD5 write-output "MD5 hash is" $Result.Hash exit 0 diff --git a/Scripts/SHA1.ps1 b/Scripts/SHA1.ps1 index 2b09352b..08256fbd 100755 --- a/Scripts/SHA1.ps1 +++ b/Scripts/SHA1.ps1 @@ -6,13 +6,13 @@ .NOTES Author: Markus Fleschutz / License: CC0 #> -param([string]$File = "") +param($File = "") + +if ($File -eq "" ) { + $File = read-host "Enter the filename" +} try { - if ($File -eq "" ) { - $File = read-host "Enter file" - } - $Result = get-filehash $File -algorithm SHA1 write-output "SHA1 hash is" $Result.Hash exit 0 diff --git a/Scripts/SHA256.ps1 b/Scripts/SHA256.ps1 index a252abbc..3648f82d 100755 --- a/Scripts/SHA256.ps1 +++ b/Scripts/SHA256.ps1 @@ -6,13 +6,13 @@ .NOTES Author: Markus Fleschutz / License: CC0 #> -param([string]$File = "") +param($File = "") + +if ($File -eq "" ) { + $File = read-host "Enter the filename" +} try { - if ($File -eq "" ) { - $File = read-host "Enter file" - } - $Result = get-filehash $File -algorithm SHA256 write-output "SHA256 hash is:" $Result.Hash exit 0 diff --git a/Scripts/alert.ps1 b/Scripts/alert.ps1 index 63f8ca1a..dbb28bd6 100755 --- a/Scripts/alert.ps1 +++ b/Scripts/alert.ps1 @@ -6,7 +6,8 @@ .NOTES Author: Markus Fleschutz / License: CC0 #> -param([string]$Message) +param($Message = "") + if ($Message -eq "" ) { $URL = read-host "Enter alert message" } diff --git a/Scripts/check-symlinks.ps1 b/Scripts/check-symlinks.ps1 index 659b2894..e969e274 100755 --- a/Scripts/check-symlinks.ps1 +++ b/Scripts/check-symlinks.ps1 @@ -8,11 +8,11 @@ param($DirTree = "") -try { - if ($DirTree -eq "" ) { - $DirTree = read-host "Enter the path to the directory tree" - } +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 { diff --git a/Scripts/check-xml-file.ps1 b/Scripts/check-xml-file.ps1 index d20656ca..2a7525eb 100755 --- a/Scripts/check-xml-file.ps1 +++ b/Scripts/check-xml-file.ps1 @@ -8,10 +8,11 @@ param($File = "") +if ($File -eq "" ) { + $File = read-host "Enter path to XML file" +} + try { - if ($File -eq "" ) { - $File = read-host "Enter path to XML file" - } $XmlFile = Get-Item $File $script:ErrorCount = 0 diff --git a/Scripts/close-program.ps1 b/Scripts/close-program.ps1 index 004da5f9..3ec5618b 100755 --- a/Scripts/close-program.ps1 +++ b/Scripts/close-program.ps1 @@ -8,15 +8,15 @@ param($FullProgramName = "", $ProgramName = "", $ProgramAliasName = "") -try { - 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 - } +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) { diff --git a/Scripts/configure-git.ps1 b/Scripts/configure-git.ps1 index 87604ee7..cfd10317 100755 --- a/Scripts/configure-git.ps1 +++ b/Scripts/configure-git.ps1 @@ -8,6 +8,16 @@ 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 { & git --version } catch { @@ -16,15 +26,6 @@ try { } try { - 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,...)" - } & git config --global user.name $FullName & git config --global user.email $EmailAddress & git config --global core.editor $FavoriteEditor diff --git a/Scripts/create-symlink.ps1 b/Scripts/create-symlink.ps1 index db365c81..844c6854 100755 --- a/Scripts/create-symlink.ps1 +++ b/Scripts/create-symlink.ps1 @@ -8,14 +8,14 @@ param($Symlink = "", $Target = "") -try { - if ($Symlink -eq "" ) { - $Symlink = read-host "Enter filename of symlink" - } - if ($Target -eq "" ) { - $Target = read-host "Enter path to 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 "Done." diff --git a/Scripts/csv-to-text.ps1 b/Scripts/csv-to-text.ps1 index 40989a99..167e916d 100755 --- a/Scripts/csv-to-text.ps1 +++ b/Scripts/csv-to-text.ps1 @@ -8,11 +8,11 @@ param([String]$Path) -try { - if ($Path -eq "" ) { - $Path = read-host "Enter path to CSV file" - } +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) { diff --git a/Scripts/download.ps1 b/Scripts/download.ps1 index bf0d1be7..d6af9f40 100755 --- a/Scripts/download.ps1 +++ b/Scripts/download.ps1 @@ -8,6 +8,10 @@ param($URL = "") +if ($URL -eq "" ) { + $URL = read-host "Enter URL to download" +} + try { & wget --version } catch { @@ -16,10 +20,6 @@ try { } try { - if ($URL -eq "" ) { - $URL = read-host "Enter URL to download" - } - wget --mirror --convert-links --adjust-extension --page-requisites --no-parent $URL --directory-prefix . --no-verbose write-host -foregroundColor green "Done." diff --git a/Scripts/generate-qrcode.ps1 b/Scripts/generate-qrcode.ps1 index e689543d..490ec627 100755 --- a/Scripts/generate-qrcode.ps1 +++ b/Scripts/generate-qrcode.ps1 @@ -8,13 +8,14 @@ param($Text = "", $ImageSize = "") +if ($Text -eq "") { + $Text = read-input "Enter text or URL" +} +if ($ImageSize -eq "") { + $ImageSize = read-input "Enter image size (e.g. 500x500)" +} + try { - if ($Text -eq "") { - $Text = read-input "Enter text or URL" - } - if ($ImageSize -eq "") { - $ImageSize = read-input "Enter image size (e.g. 500x500)" - } $ECC = "M" # can be L, M, Q, H $QuietZone = 1 $ForegroundColor = "000000" diff --git a/Scripts/inspect-exe.ps1 b/Scripts/inspect-exe.ps1 index 2c49b1a9..b699ee98 100755 --- a/Scripts/inspect-exe.ps1 +++ b/Scripts/inspect-exe.ps1 @@ -6,12 +6,13 @@ .NOTES Author: Markus Fleschutz / License: CC0 #> -param([string]$PathToExe) +param($PathToExe = "") + +if ($PathToExe -eq "" ) { + $PathToExe = read-host "Enter path to executable file" +} try { - if ($PathToExe -eq "" ) { - $PathToExe = read-host "Enter path to executable file" - } get-childitem $PathToExe | % {$_.VersionInfo} | Select * exit 0 } catch { diff --git a/Scripts/list-anagrams.ps1 b/Scripts/list-anagrams.ps1 index 6c3660ac..c976febb 100755 --- a/Scripts/list-anagrams.ps1 +++ b/Scripts/list-anagrams.ps1 @@ -6,7 +6,7 @@ .NOTES Author: Markus Fleschutz / License: CC0 #> -param([string]$Word, [int]$Columns = 8) +param($Word = "", [int]$Columns = 8) function GetPermutations { [cmdletbinding()] diff --git a/Scripts/list-empty-dirs.ps1 b/Scripts/list-empty-dirs.ps1 index d2b46dd2..f6b136f8 100755 --- a/Scripts/list-empty-dirs.ps1 +++ b/Scripts/list-empty-dirs.ps1 @@ -8,10 +8,11 @@ param($DirTree = "") +if ($DirTree -eq "" ) { + $DirTree = read-host "Enter the path to the directory tree" +} + try { - if ($DirTree -eq "" ) { - $DirTree = read-host "Enter the path to the directory tree" - } write-progress "Listing empty directories in $DirTree..." [int]$Count = 0 Get-ChildItem $DirTree -recurse | Where {$_.PSIsContainer -eq $true} | Where {$_.GetFileSystemInfos().Count -eq 0} | ForEach-Object { diff --git a/Scripts/list-empty-files.ps1 b/Scripts/list-empty-files.ps1 index 58262ce7..59560a08 100755 --- a/Scripts/list-empty-files.ps1 +++ b/Scripts/list-empty-files.ps1 @@ -8,10 +8,11 @@ param($DirTree = "") +if ($DirTree -eq "" ) { + $DirTree = read-host "Enter the path to the directory tree" +} + try { - if ($DirTree -eq "" ) { - $DirTree = read-host "Enter the path to the directory tree" - } [int]$Count = 0 write-progress "Listing empty files in $DirTree ..." get-childItem $DirTree -recurse | where {$_.PSIsContainer -eq $false} | where {$_.Length -eq 0} | foreach-object { diff --git a/Scripts/list-files.ps1 b/Scripts/list-files.ps1 index 804ade58..5a00de52 100755 --- a/Scripts/list-files.ps1 +++ b/Scripts/list-files.ps1 @@ -6,12 +6,13 @@ .NOTES Author: Markus Fleschutz / License: CC0 #> -param([string]$Folder) +param($Folder = "") + +if ($Folder -eq "" ) { + $Folder = read-host "Enter path to folder" +} try { - if ($Folder -eq "" ) { - [string]$Folder = read-host "Enter path to folder" - } Get-ChildItem -path $Folder -recurse | select FullName exit 0 } catch { diff --git a/Scripts/list-formatted.ps1 b/Scripts/list-formatted.ps1 index 6b7d1dde..ea5f1208 100755 --- a/Scripts/list-formatted.ps1 +++ b/Scripts/list-formatted.ps1 @@ -6,7 +6,7 @@ .NOTES Author: Markus Fleschutz / License: CC0 #> -param([string]$Dir = "") +param($Dir = "") function ListDirectory { param([string]$Path) $Items = get-childItem -path $Path diff --git a/Scripts/list-fritzbox-calls.ps1 b/Scripts/list-fritzbox-calls.ps1 index e2c72537..cc178321 100755 --- a/Scripts/list-fritzbox-calls.ps1 +++ b/Scripts/list-fritzbox-calls.ps1 @@ -8,13 +8,15 @@ #Requires -Version 3 -param([string]$Username = "", [string]$Password = "") +param($Username = "", $Password = "") + if ($Username -eq "") { $Username = read-host "Enter username for FRITZ!Box" } if ($Password -eq "") { $Password = read-host "Enter password for FRITZ!Box" } + write-progress "Contacting FRITZ!Box ..." $FQDN = "fritz.box" diff --git a/Scripts/list-fritzbox-devices.ps1 b/Scripts/list-fritzbox-devices.ps1 index 635bd7e0..e60af547 100755 --- a/Scripts/list-fritzbox-devices.ps1 +++ b/Scripts/list-fritzbox-devices.ps1 @@ -8,13 +8,15 @@ #Requires -Version 3 -param([string]$Username = "", [string]$Password = "") +param($Username = "", $Password = "") + if ($Username -eq "") { $Username = read-host "Enter username for FRITZ!Box" } if ($Password -eq "") { $Password = read-host "Enter password for FRITZ!Box" } + write-progress "Contacting FRITZ!Box ..." [string]$HostURL = "https://fritz.box:49443" [string]$SOAPAction="urn:dslforum-org:service:Hosts:1#X_AVM-DE_GetHostListPath" diff --git a/Scripts/list-news.ps1 b/Scripts/list-news.ps1 index b654c0c1..5487093e 100755 --- a/Scripts/list-news.ps1 +++ b/Scripts/list-news.ps1 @@ -6,7 +6,7 @@ .NOTES Author: Markus Fleschutz / License: CC0 #> -param([string]$RSS_URL = "https://yahoo.com/news/rss/world") +param($RSS_URL = "https://yahoo.com/news/rss/world") try { [xml]$Content = (invoke-webRequest -URI $RSS_URL).Content diff --git a/Scripts/list-unused-files.ps1 b/Scripts/list-unused-files.ps1 index d5181fae..f79d2e68 100755 --- a/Scripts/list-unused-files.ps1 +++ b/Scripts/list-unused-files.ps1 @@ -6,7 +6,7 @@ .NOTES Author: Markus Fleschutz / License: CC0 #> -param([string]$DirTree, [int]$NumberOfDaysUnused) +param($DirTree = "", [int]$NumberOfDaysUnused = 99) write-host "Listing files in $DirTree with last access time older than $NumberOfDaysUnused days" diff --git a/Scripts/locate-city.ps1 b/Scripts/locate-city.ps1 index 35045201..d0eca5a6 100755 --- a/Scripts/locate-city.ps1 +++ b/Scripts/locate-city.ps1 @@ -6,10 +6,12 @@ .NOTES Author: Markus Fleschutz / License: CC0 #> -param([string]$City) +param($City = "") + if ($City -eq "" ) { - $City = read-host "Enter the city" + $City = read-host "Enter the city name" } + $PathToRepo = "$PSScriptRoot/.." try { diff --git a/Scripts/locate-ipaddress.ps1 b/Scripts/locate-ipaddress.ps1 index 4030164e..76e6fdea 100755 --- a/Scripts/locate-ipaddress.ps1 +++ b/Scripts/locate-ipaddress.ps1 @@ -7,10 +7,12 @@ #> param($IPaddr = "") + +if ($IPaddr -eq "" ) { + $IPaddr = read-host "Enter IP address to locate" +} + try { - if ($IPaddr -eq "" ) { - $IPaddr = read-host "Enter IP address to locate" - } $result = Invoke-RestMethod -Method Get -Uri "http://ip-api.com/json/$IPaddr" write-output $result exit 0 diff --git a/Scripts/locate-zip-code.ps1 b/Scripts/locate-zip-code.ps1 index ee427579..ec8848b5 100755 --- a/Scripts/locate-zip-code.ps1 +++ b/Scripts/locate-zip-code.ps1 @@ -6,18 +6,18 @@ .NOTES Author: Markus Fleschutz / License: CC0 #> -param([string]$CountryCode = "", [string]$ZipCode = "") -$PathToRepo = "$PSScriptRoot/.." +param($CountryCode = "", $ZipCode = "") + +if ($CountryCode -eq "" ) { + $CountryCode = read-host "Enter the country code" +} +if ($ZipCode -eq "" ) { + $ZipCode = read-host "Enter the zip code" +} 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..." + $PathToRepo = "$PSScriptRoot/.." $Table = import-csv "$PathToRepo/Data/zip-codes.csv" $FoundOne = 0 diff --git a/Scripts/new-email.ps1 b/Scripts/new-email.ps1 index 7f4f7afa..7d44f9d3 100755 --- a/Scripts/new-email.ps1 +++ b/Scripts/new-email.ps1 @@ -6,12 +6,13 @@ .NOTES Author: Markus Fleschutz / License: CC0 #> -param([string]$EmailAddress = "") +param($EmailAddress = "") + +if ($EmailAddress -eq "" ) { + $EmailAddress = "markus@fleschutz.de" +} try { - if ($EmailAddress -eq "" ) { - $EmailAddress = "markus@fleschutz.de" - } $URL="mailto:$EmailAddress" Start-Process $URL exit 0 diff --git a/Scripts/open-browser.ps1 b/Scripts/open-browser.ps1 index 4c6ad5c1..cfd10520 100755 --- a/Scripts/open-browser.ps1 +++ b/Scripts/open-browser.ps1 @@ -6,12 +6,13 @@ .NOTES Author: Markus Fleschutz / License: CC0 #> -param([string]$URL = "") +param($URL = "") + +if ($URL -eq "" ) { + $URL = "http://www.fleschutz.de" +} try { - if ($URL -eq "" ) { - $URL = "http://www.fleschutz.de" - } Start-Process $URL exit 0 } catch { diff --git a/Scripts/play-m3u.ps1 b/Scripts/play-m3u.ps1 index ae842a6a..1ab613d6 100644 --- a/Scripts/play-m3u.ps1 +++ b/Scripts/play-m3u.ps1 @@ -8,10 +8,11 @@ param($Filename = "") +if ($Filename -eq "" ) { + $Filename = read-host "Enter the M3U playlist filename" +} + try { - if ($Filename -eq "" ) { - $Filename = read-host "Enter the M3U playlist filename" - } $Lines = get-content $Filename add-type -assemblyName presentationCore diff --git a/Scripts/play-mp3.ps1 b/Scripts/play-mp3.ps1 index 608d77fa..048681df 100755 --- a/Scripts/play-mp3.ps1 +++ b/Scripts/play-mp3.ps1 @@ -8,10 +8,11 @@ param($Filename = "") +if ($Filename -eq "" ) { + $Filename = read-host "Enter the MP3 filename" +} + try { - if ($Filename -eq "" ) { - $Filename = read-host "Enter the MP3 filename" - } add-type -assemblyName presentationCore $MediaPlayer = new-object system.windows.media.mediaplayer $MediaPlayer.open("$Filename") diff --git a/Scripts/query-smart-data.ps1 b/Scripts/query-smart-data.ps1 index 83108862..205ef60b 100755 --- a/Scripts/query-smart-data.ps1 +++ b/Scripts/query-smart-data.ps1 @@ -11,7 +11,7 @@ #Requires -RunAsAdministrator -param([string]$Directory = "") +param($Directory = "") function CheckIfInstalled { diff --git a/Scripts/reboot-fritzbox.ps1 b/Scripts/reboot-fritzbox.ps1 index bb378eba..1dc59fe0 100755 --- a/Scripts/reboot-fritzbox.ps1 +++ b/Scripts/reboot-fritzbox.ps1 @@ -6,7 +6,7 @@ .NOTES Author: Markus Fleschutz / License: CC0 #> -param([string]$USERNAME = "", [string]$PASSWORD = "") +param($USERNAME = "", $PASSWORD = "") if ($USERNAME -eq "") { $USERNAME = read-host "Enter username for FRITZ!Box" } diff --git a/Scripts/search-files.ps1 b/Scripts/search-files.ps1 index b8c3a19d..e649fda6 100755 --- a/Scripts/search-files.ps1 +++ b/Scripts/search-files.ps1 @@ -6,7 +6,7 @@ .NOTES Author: Markus Fleschutz / License: CC0 #> -param([string]$Pattern = "", [string]$Path = "") +param($Pattern = "", $Path = "") function ListScripts { param([string]$Pattern, [string]$Path) $List = Select-String -Path $Path -Pattern "$Pattern" diff --git a/Scripts/send-tcp.ps1 b/Scripts/send-tcp.ps1 index db07c097..f155582d 100755 --- a/Scripts/send-tcp.ps1 +++ b/Scripts/send-tcp.ps1 @@ -6,7 +6,7 @@ .NOTES Author: Markus Fleschutz / License: CC0 #> -param([string]$TargetIP = "", [int]$TargetPort = 0, [string]$Message = "") +param($TargetIP = "", [int]$TargetPort = 0, $Message = "") try { if ($TargetIP -eq "" ) { diff --git a/Scripts/send-udp.ps1 b/Scripts/send-udp.ps1 index 795170f3..ac4c7013 100755 --- a/Scripts/send-udp.ps1 +++ b/Scripts/send-udp.ps1 @@ -6,7 +6,7 @@ .NOTES Author: Markus Fleschutz / License: CC0 #> -param([string]$TargetIP = "", [int]$TargetPort = 0, [string]$Message = "") +param($TargetIP = "", [int]$TargetPort = 0, $Message = "") try { if ($TargetIP -eq "" ) { diff --git a/Scripts/set-timer.ps1 b/Scripts/set-timer.ps1 index d46a4d84..5c1c3e3f 100755 --- a/Scripts/set-timer.ps1 +++ b/Scripts/set-timer.ps1 @@ -8,11 +8,11 @@ param([int]$Seconds = 0) -try { - if ($Seconds -eq 0 ) { - [int]$Seconds = read-host "Enter number of seconds" - } +if ($Seconds -eq 0 ) { + [int]$Seconds = read-host "Enter number of seconds" +} +try { for ($i = $Seconds; $i -gt 0; $i--) { clear-host ./write-big "T-$i seconds" diff --git a/Scripts/set-wallpaper.ps1 b/Scripts/set-wallpaper.ps1 index 123ea3f0..aa0bd1c9 100755 --- a/Scripts/set-wallpaper.ps1 +++ b/Scripts/set-wallpaper.ps1 @@ -7,7 +7,7 @@ .NOTES Author: Markus Fleschutz / License: CC0 #> -param([string]$ImageFile = "", [string]$Style = "Fit") +param($ImageFile = "", $Style = "Fit") function SetWallPaper { param([string]$Image, [ValidateSet('Fill', 'Fit', 'Stretch', 'Tile', 'Center', 'Span')][string]$Style) diff --git a/Scripts/simulate-presence.ps1 b/Scripts/simulate-presence.ps1 index 02d83010..e9ffe29d 100755 --- a/Scripts/simulate-presence.ps1 +++ b/Scripts/simulate-presence.ps1 @@ -8,10 +8,11 @@ param($IPaddress = "") +if ($IPaddress -eq "" ) { + $IPaddress = read-host "Enter IP address of Shelly1 device" +} + try { - if ($IPaddress -eq "" ) { - $IPaddress = read-host "Enter IP address of Shelly1 device" - } for ([int]$i = 0; $i -lt 1000; $i++) { & ./switch-shelly1.ps1 $IPaddress on 0 start-sleep -s 10 diff --git a/Scripts/smart-data2csv.ps1 b/Scripts/smart-data2csv.ps1 index addde45e..7c7cf256 100755 --- a/Scripts/smart-data2csv.ps1 +++ b/Scripts/smart-data2csv.ps1 @@ -7,7 +7,7 @@ .NOTES Author: Markus Fleschutz / License: CC0 #> -param([string]$Directory = "") +param($Directory = "") function WriteCsvHeader { param([PSCustomObject]$File) foreach($Entry in $File.ata_smart_attributes.table) { diff --git a/Scripts/speak-epub.ps1 b/Scripts/speak-epub.ps1 index 2f3f52a1..56caeb9e 100755 --- a/Scripts/speak-epub.ps1 +++ b/Scripts/speak-epub.ps1 @@ -6,7 +6,7 @@ .NOTES Author: Markus Fleschutz / License: CC0 #> -param([string]$Filename = "") +param($Filename = "") function Speak { param([string]$Text) write-output "$Text" diff --git a/Scripts/speak-file.ps1 b/Scripts/speak-file.ps1 index fd4d4645..8591218c 100755 --- a/Scripts/speak-file.ps1 +++ b/Scripts/speak-file.ps1 @@ -6,12 +6,13 @@ .NOTES Author: Markus Fleschutz / License: CC0 #> -param([string]$File = "") +param($File = "") + +if ($File -eq "") { + $File = read-host "Enter path to text file" +} try { - if ($File -eq "") { - $File = read-host "Enter path to text file" - } $Text = Get-Content $File $Voice = new-object -ComObject SAPI.SPVoice diff --git a/Scripts/speak-german.ps1 b/Scripts/speak-german.ps1 index f4ed1808..c89f85af 100755 --- a/Scripts/speak-german.ps1 +++ b/Scripts/speak-german.ps1 @@ -8,15 +8,16 @@ param($Text = "") +if ($Text -eq "") { + $Text = read-host "Enter the text to speak" +} + try { $Voice = new-object -ComObject SAPI.SPVoice $Voices = $Voice.GetVoices() foreach ($OtherVoice in $Voices) { $Description = $OtherVoice.GetDescription() if ($Description -like "*- German*") { - if ($Text -eq "") { - $Text = read-host "Enter the text to speak" - } write-progress "$Text" $Voice.Voice = $OtherVoice [void]$Voice.Speak($Text) diff --git a/Scripts/speak-text.ps1 b/Scripts/speak-text.ps1 index ad49ec19..7f5bc234 100755 --- a/Scripts/speak-text.ps1 +++ b/Scripts/speak-text.ps1 @@ -6,13 +6,13 @@ .NOTES Author: Markus Fleschutz / License: CC0 #> -param([string]$Text = "") +param($Text = "") + +if ($Text -eq "") { + $Text = read-host "Enter the text to speak" +} try { - if ($Text -eq "") { - $Text = read-host "Enter the text to speak" - } - $Voice = new-object -ComObject SAPI.SPVoice $Result = $Voice.Speak($Text) exit 0 diff --git a/Scripts/switch-branch.ps1 b/Scripts/switch-branch.ps1 index bfe77c25..7f0cf3f2 100755 --- a/Scripts/switch-branch.ps1 +++ b/Scripts/switch-branch.ps1 @@ -8,6 +8,10 @@ param($Branch = "") +if ($Branch -eq "") { + $Branch = read-host "Enter branch name to switch to" +} + try { & git --version } catch { @@ -16,10 +20,6 @@ try { } try { - if ($Branch -eq "") { - $Branch = read-host "Enter branch name to switch to" - } - & git switch --recurse-submodules $Branch if ($lastExitCode -ne "0") { throw "'git switch --recurse-submodules $Branch' failed" } diff --git a/Scripts/take-screenshot.ps1 b/Scripts/take-screenshot.ps1 index 2cbff017..8f5f8b16 100755 --- a/Scripts/take-screenshot.ps1 +++ b/Scripts/take-screenshot.ps1 @@ -6,7 +6,7 @@ .NOTES Author: Markus Fleschutz / License: CC0 #> -param([string]$Directory = "") +param($Directory = "") function TakeScreenshot { param([string]$FilePath) Add-Type -Assembly System.Windows.Forms diff --git a/Scripts/take-screenshots.ps1 b/Scripts/take-screenshots.ps1 index 046edb71..37899330 100755 --- a/Scripts/take-screenshots.ps1 +++ b/Scripts/take-screenshots.ps1 @@ -6,7 +6,7 @@ .NOTES Author: Markus Fleschutz / License: CC0 #> -param([string]$Directory = "", [int]$Interval = 60) +param($Directory = "", [int]$Interval = 60) function TakeScreenshot { param([string]$FilePath) Add-Type -Assembly System.Windows.Forms diff --git a/Scripts/translate-file.ps1 b/Scripts/translate-file.ps1 index 061f8495..fbde0bfa 100755 --- a/Scripts/translate-file.ps1 +++ b/Scripts/translate-file.ps1 @@ -8,18 +8,18 @@ param($File = "", $SourceLanguage = "", $TargetLanguage = "") +if ($File -eq "" ) { + $File = 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 { $PathToRepo = "$PSScriptRoot/.." - - if ($File -eq "" ) { - $File = 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" - } Start-Process -FilePath "$PathToRepo/Data/trans" -ArgumentList "-i $File -s $SourceLanguage -t $TargetLanguage -e google -brief" -NoNewWindow -Wait exit 0 diff --git a/Scripts/update-repos.ps1 b/Scripts/update-repos.ps1 index 95fc2f0a..748ad4a7 100755 --- a/Scripts/update-repos.ps1 +++ b/Scripts/update-repos.ps1 @@ -8,6 +8,10 @@ param($Directory = "") +if ($Directory -eq "") { + $Directory = "$PWD" +} + try { & git --version } catch { @@ -16,9 +20,6 @@ try { } try { - if ($Directory -eq "") { - $Directory = "$PWD" - } $Files = get-childItem -path $Directory foreach ($File in $Files) { if ($File.Mode -like "d*") { diff --git a/Scripts/visualize-dir-tree.ps1 b/Scripts/visualize-dir-tree.ps1 index bd3f8a75..e45068e0 100755 --- a/Scripts/visualize-dir-tree.ps1 +++ b/Scripts/visualize-dir-tree.ps1 @@ -6,7 +6,7 @@ .NOTES Author: Markus Fleschutz / License: CC0 #> -param([string]$DirTree = "") +param($DirTree = "") function VisualizeDirectory { param([string]$Directory, [int]$Depth) $Depth++ diff --git a/Scripts/wakeup.ps1 b/Scripts/wakeup.ps1 index a5a1f283..d7fcca72 100755 --- a/Scripts/wakeup.ps1 +++ b/Scripts/wakeup.ps1 @@ -6,7 +6,7 @@ .NOTES Author: Markus Fleschutz / License: CC0 #> -param([string]$MACaddress = "", [string]$IPaddress = "") +param($MACaddress = "", $IPaddress = "") function Send-WOL { param([string]$mac, [string]$ip="255.255.255.255", [int]$port=9) $broadcast = [Net.IPAddress]::Parse($ip) diff --git a/Scripts/write-big.ps1 b/Scripts/write-big.ps1 index 6fd1618d..21b872d5 100755 --- a/Scripts/write-big.ps1 +++ b/Scripts/write-big.ps1 @@ -6,7 +6,7 @@ .NOTES Author: Markus Fleschutz / License: CC0 #> -param([string]$Text = "") +param($Text = "") Set-StrictMode -Version Latest diff --git a/Scripts/write-blue.ps1 b/Scripts/write-blue.ps1 index b905379f..28139645 100755 --- a/Scripts/write-blue.ps1 +++ b/Scripts/write-blue.ps1 @@ -8,10 +8,11 @@ param($Text = "") +if ($Text -eq "" ) { + $Text = read-host "Enter the text to write" +} + try { - if ($Text -eq "" ) { - [String]$Text = read-host "Enter text to write" - } write-host -foregroundColor blue $Text exit 0 } catch { diff --git a/Scripts/write-braille.ps1 b/Scripts/write-braille.ps1 index 01b791ff..0aab09f7 100755 --- a/Scripts/write-braille.ps1 +++ b/Scripts/write-braille.ps1 @@ -6,7 +6,7 @@ .NOTES Author: Markus Fleschutz / License: CC0 #> -param([string]$Text = "") +param($Text = "") function BrailleA { param([int]$Row) switch($Row) { diff --git a/Scripts/write-green.ps1 b/Scripts/write-green.ps1 index 61d0f5e6..e91b854c 100755 --- a/Scripts/write-green.ps1 +++ b/Scripts/write-green.ps1 @@ -6,12 +6,13 @@ .NOTES Author: Markus Fleschutz / License: CC0 #> -param([string]$Text = "") +param($Text = "") + +if ($Text -eq "" ) { + $Text = read-host "Enter the text to write" +} try { - if ($Text -eq "" ) { - [string]$Text = read-host "Enter text to write" - } write-host -foregroundColor green $Text exit 0 } catch { diff --git a/Scripts/write-logbook.ps1 b/Scripts/write-logbook.ps1 index 3bd5186d..29a5e425 100755 --- a/Scripts/write-logbook.ps1 +++ b/Scripts/write-logbook.ps1 @@ -6,14 +6,15 @@ .NOTES Author: Markus Fleschutz / License: CC0 #> -param([string]$Text = "") +param($Text = "") + +if ($Text -eq "" ) { + $Text = read-host "Enter the text to write" +} try { $Time = get-date -format "yyyy-MM-ddTHH:mm:ssZ" -asUTC $User = $(whoami) - if ($Text -eq "" ) { - [string]$Text = read-host "Enter text to write" - } $Line = "$Time,$User,$Text" $PathToRepo=(get-item $MyInvocation.MyCommand.Path).directory.parent diff --git a/Scripts/write-marquee.ps1 b/Scripts/write-marquee.ps1 index 20e36249..63eb3a46 100755 --- a/Scripts/write-marquee.ps1 +++ b/Scripts/write-marquee.ps1 @@ -6,10 +6,7 @@ .NOTES Author: Markus Fleschutz / License: CC0 #> -param([string]$Text = "", [int]$Speed = 60) # 60 ms pause -if ($Text -eq "") { - $Text = "PowerShell is powerful! PowerShell is cross-platform! PowerShell is open-source! PowerShell is easy to learn! Powershell is fully documented" -} +param($Text = "PowerShell is powerful! PowerShell is cross-platform! PowerShell is open-source! PowerShell is easy to learn! Powershell is fully documented", [int]$Speed = 60) # 60 ms pause function StartMarquee { param([string]$text) $Length = $text.Length diff --git a/Scripts/write-morse-code.ps1 b/Scripts/write-morse-code.ps1 index 5dc47fb6..310bfb92 100755 --- a/Scripts/write-morse-code.ps1 +++ b/Scripts/write-morse-code.ps1 @@ -6,7 +6,7 @@ .NOTES Author: Markus Fleschutz / License: CC0 #> -param([string]$Text = "", [int]$OneTimeUnit = 100) # in milliseconds +param($Text = "", [int]$OneTimeUnit = 100) # in milliseconds function gap { param([int]$Length) for ([int]$i = 1; $i -lt $Length; $i++) { diff --git a/Scripts/write-red.ps1 b/Scripts/write-red.ps1 index cd1ef16f..ebf965bf 100755 --- a/Scripts/write-red.ps1 +++ b/Scripts/write-red.ps1 @@ -6,15 +6,11 @@ .NOTES Author: Markus Fleschutz / License: CC0 #> -param([string]$Text = "") +param($Text = "") -try { - if ($Text -eq "" ) { - [string]$Text = read-host "Enter text to write" - } - write-host -foregroundcolor red $Text - exit 0 -} catch { - write-error "ERROR: line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" - exit 1 +if ($Text -eq "" ) { + $Text = read-host "Enter the text to write" } + +write-host -foregroundcolor red $Text +exit 0 diff --git a/Scripts/write-rot13.ps1 b/Scripts/write-rot13.ps1 index bab98e42..37650021 100755 --- a/Scripts/write-rot13.ps1 +++ b/Scripts/write-rot13.ps1 @@ -6,7 +6,7 @@ .NOTES Author: Markus Fleschutz / License: CC0 #> -param([string]$Text = "") +param($Text = "") function ROT13 { param([string]$Text) $Text.ToCharArray() | ForEach-Object { diff --git a/Scripts/write-typewriter.ps1 b/Scripts/write-typewriter.ps1 index 9181405a..be165dc6 100755 --- a/Scripts/write-typewriter.ps1 +++ b/Scripts/write-typewriter.ps1 @@ -6,11 +6,7 @@ .NOTES Author: Markus Fleschutz / License: CC0 #> -param([string]$Text = "", [int]$Speed = 250) # in milliseconds - -if ($Text -eq "" ) { - $Text = "`nHello World`n-----------`nPowerShell is cross-platform`nPowerShell is open-source`nPowerShell is easy to learn`nPowerShell is fully documented`n`nThanks for watching`n`n:-)`n`n" -} +param($Text = "`nHello World`n-----------`nPowerShell is cross-platform`nPowerShell is open-source`nPowerShell is easy to learn`nPowerShell is fully documented`n`nThanks for watching`n`n:-)`n`n", [int]$Speed = 250) # in milliseconds try { $Random = New-Object System.Random diff --git a/Scripts/write-uppercase.ps1 b/Scripts/write-uppercase.ps1 index 7ef2bb65..28051e12 100755 --- a/Scripts/write-uppercase.ps1 +++ b/Scripts/write-uppercase.ps1 @@ -6,12 +6,13 @@ .NOTES Author: Markus Fleschutz / License: CC0 #> -param([string]$Text = "") +param($Text = "") + +if ($Text -eq "" ) { + $Text = read-host "Enter the text to write" +} try { - if ($Text -eq "" ) { - [string]$Text = read-host "Enter text to write" - } write-output $Text.ToUpper() exit 0 } catch { diff --git a/Scripts/write-vertical.ps1 b/Scripts/write-vertical.ps1 index af0872c8..ca20b38f 100755 --- a/Scripts/write-vertical.ps1 +++ b/Scripts/write-vertical.ps1 @@ -6,12 +6,13 @@ .NOTES Author: Markus Fleschutz / License: CC0 #> -param([string]$Text = "") +param($Text = "") + +if ($Text -eq "" ) { + $Text = read-host "Enter the text to write" +} try { - if ($Text -eq "" ) { - [String]$Text = read-host "Enter text to write" - } [char[]]$TextArray = $Text foreach($Char in $TextArray) { write-output $Char diff --git a/Scripts/zip-dir.ps1 b/Scripts/zip-dir.ps1 index 3778fee0..68c59344 100755 --- a/Scripts/zip-dir.ps1 +++ b/Scripts/zip-dir.ps1 @@ -8,11 +8,11 @@ param($Directory = "") -try { - if ($Directory -eq "" ) { - $Directory = read-host "Enter path to directory to zip" - } +if ($Directory -eq "" ) { + $Directory = read-host "Enter the path to the directory to zip" +} +try { compress-archive -path $Directory -destinationPath $Directory.zip write-host -foregroundColor green "Done - created zip archive $($Directory).zip"