diff --git a/Scripts/PowerShellHere.ps1 b/Scripts/PowerShellHere.ps1 index 072fdf9..7e986d9 100644 --- a/Scripts/PowerShellHere.ps1 +++ b/Scripts/PowerShellHere.ps1 @@ -1,23 +1,19 @@ -if (-not (Test-Path -Path Registry::HKEY_CLASSES_ROOT\.ps1)) -{ +if (-not (Test-Path -Path Registry::HKEY_CLASSES_ROOT\.ps1)) { New-Item -Path Registry::HKEY_CLASSES_ROOT\.ps1 -Force } -if (-not (Test-Path -Path Registry::HKEY_CLASSES_ROOT\Microsoft.PowerShellScript.1)) -{ +if (-not (Test-Path -Path Registry::HKEY_CLASSES_ROOT\Microsoft.PowerShellScript.1)) { New-Item -Path Registry::HKEY_CLASSES_ROOT\Microsoft.PowerShellScript.1 -Force } New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\Microsoft.PowerShellScript.1 -Name EditFlags -Type DWord -Value 131072 -Force New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\Microsoft.PowerShellScript.1 -Name FriendlyTypeName -Type ExpandString -Value "@`"%systemroot%\system32\windowspowershell\v1.0\powershell.exe`",-103" -Force -if (-not (Test-Path -Path Registry::HKEY_CLASSES_ROOT\Microsoft.PowerShellScript.1\DefaultIcon)) -{ +if (-not (Test-Path -Path Registry::HKEY_CLASSES_ROOT\Microsoft.PowerShellScript.1\DefaultIcon)) { New-Item -Path Registry::HKEY_CLASSES_ROOT\Microsoft.PowerShellScript.1\DefaultIcon -Force } New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\Microsoft.PowerShellScript.1\DefaultIcon -Name "(Default)" -Type String -Value "`"C:\Windows\System32\WindowsPowerShell\v1.0\powershell_ise.exe`",1" -Force -if (-not (Test-Path -Path Registry::HKEY_CLASSES_ROOT\Microsoft.PowerShellScript.1\Shell\RunAs\Command)) -{ +if (-not (Test-Path -Path Registry::HKEY_CLASSES_ROOT\Microsoft.PowerShellScript.1\Shell\RunAs\Command)) { New-Item -Path Registry::HKEY_CLASSES_ROOT\Microsoft.PowerShellScript.1\Shell\RunAs\Command -Force } New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\Microsoft.PowerShellScript.1\Shell\RunAs -Name HasLUAShield -Type String -Value "" -Force diff --git a/Scripts/hw.ps1 b/Scripts/hw.ps1 index 87bae6d..2079ebc 100644 --- a/Scripts/hw.ps1 +++ b/Scripts/hw.ps1 @@ -40,7 +40,8 @@ function GetCPUTemperature { [int]$IntTemp = Get-Content "/sys/class/thermal/thermal_zone0/temp" $temp = [math]::round($IntTemp / 1000.0, 1) } - } else { + } + else { $objects = Get-WmiObject -Query "SELECT * FROM Win32_PerfFormattedData_Counters_ThermalZoneInformation" -Namespace "root/CIMV2" foreach ($object in $objects) { $highPrec = $object.HighPrecisionTemperature @@ -77,13 +78,16 @@ $socket = "$($details.SocketDesignation) socket, " $celsius = GetCPUTemperature if ($celsius -eq 99999.9) { $temp = "no temp" -} elseif ($celsius -gt 50) { +} +elseif ($celsius -gt 50) { $temp = "$($celsius)°C" $status = "⚠️" -} elseif ($celsius -lt 0) { +} +elseif ($celsius -lt 0) { $temp = "$($celsius)°C" $status = "⚠️" -} else { +} +else { $temp = "$($celsius)°C" } foreach ($cpu in $cpus) { @@ -135,10 +139,10 @@ foreach ($vol in $volumes) { # Firewall status for all profiles (Domain, Private, Public) $firewallStatus = Get-NetFirewallProfile | ForEach-Object { - [PSCustomObject]@{ - Profile = $_.Name - Enabled = $_.Enabled - } + [PSCustomObject]@{ + Profile = $_.Name + Enabled = $_.Enabled + } } Write-Host "Firewall: " -ForegroundColor Yellow $firewallStatus | Format-Table -Property Profile, Enabled -AutoSize diff --git a/Scripts/ip-change.ps1 b/Scripts/ip-change.ps1 index 9fbe118..8bc39c4 100644 --- a/Scripts/ip-change.ps1 +++ b/Scripts/ip-change.ps1 @@ -10,50 +10,52 @@ function ConvertTo-PrefixLength { return $prefixLength } -function ipchangefun{ -# Display network adapters to the user -Write-Host "Available Network Adapters and their Interface Indexes:" -Get-NetAdapter | Format-Table Name, InterfaceIndex, Status - -# Prompt for Interface Index and validate -$interfaceIndex = $null -do { - $interfaceIndex = Read-Host "Enter the Interface Index from the list above" - if (-not $interfaceIndex -or $interfaceIndex -eq '') { - Write-Host "Interface Index cannot be empty, please enter a valid number." +function ipchangefun { + # Display network adapters to the user + Write-Host "Available Network Adapters and their Interface Indexes:" + Get-NetAdapter | Format-Table Name, InterfaceIndex, Status + + # Prompt for Interface Index and validate + $interfaceIndex = $null + do { + $interfaceIndex = Read-Host "Enter the Interface Index from the list above" + if (-not $interfaceIndex -or $interfaceIndex -eq '') { + Write-Host "Interface Index cannot be empty, please enter a valid number." + } + if (-not (Get-NetAdapter | Where-Object InterfaceIndex -eq $interfaceIndex)) { + Write-Host "Invalid Interface Index entered. Please enter a number from the list above." + $interfaceIndex = $null + } + } while (-not $interfaceIndex) + + $ipAddress = Read-Host "Enter the new IP Address" + $subnetMask = Read-Host "Enter the Subnet Mask" + + # Check if subnet mask is empty and set default value + if ([string]::IsNullOrWhiteSpace($subnetMask)) { + $subnetMask = "255.255.255.0" } - if (-not (Get-NetAdapter | Where-Object InterfaceIndex -eq $interfaceIndex)) { - Write-Host "Invalid Interface Index entered. Please enter a number from the list above." - $interfaceIndex = $null - } -} while (-not $interfaceIndex) - -$ipAddress = Read-Host "Enter the new IP Address" -$subnetMask = Read-Host "Enter the Subnet Mask" -# Check if subnet mask is empty and set default value -if ([string]::IsNullOrWhiteSpace($subnetMask)) { - $subnetMask = "255.255.255.0" -} + # Convert the subnet mask to prefix length + $prefixLength = ConvertTo-PrefixLength -SubnetMask $subnetMask -# Convert the subnet mask to prefix length -$prefixLength = ConvertTo-PrefixLength -SubnetMask $subnetMask - -# Remove the existing IP address -try { - Get-NetIPAddress -InterfaceIndex $interfaceIndex | Remove-NetIPAddress -Confirm:$false - Write-Host "Existing IP Address(es) removed." -} catch { - Write-Error "Failed to remove existing IP Address. Error: $_" -} + # Remove the existing IP address + try { + Get-NetIPAddress -InterfaceIndex $interfaceIndex | Remove-NetIPAddress -Confirm:$false + Write-Host "Existing IP Address(es) removed." + } + catch { + Write-Error "Failed to remove existing IP Address. Error: $_" + } -# Set the IP Address -try { - New-NetIPAddress -InterfaceIndex $interfaceIndex -IPAddress $ipAddress -PrefixLength $prefixLength - Write-Host "IP Address has been changed successfully." -} catch { - Write-Error "Failed to change IP Address. Error: $_" -} + # Set the IP Address + try { + New-NetIPAddress -InterfaceIndex $interfaceIndex -IPAddress $ipAddress -PrefixLength $prefixLength + Write-Host "IP Address has been changed successfully." + } + catch { + Write-Error "Failed to change IP Address. Error: $_" + } } ipchangefun \ No newline at end of file diff --git a/Scripts/list-weather.ps1 b/Scripts/list-weather.ps1 index 6c01dd6..fb62e98 100644 --- a/Scripts/list-weather.ps1 +++ b/Scripts/list-weather.ps1 @@ -2,71 +2,71 @@ function GetDescription([string]$text) { switch ($text) { - "Blizzard" { return "❄️ blizzard ⚠️" } - "Blowing snow" { return "❄️ blowing snow ⚠️" } - "Clear" { return "🌙 clear" } - "Cloudy" { return "☁️ cloudy" } - "Fog" { return "🌫 fog" } - "Freezing fog" { return "🌫 freezing fog" } - "Heavy rain" { return "💧 heavy rain ⚠️" } - "Heavy snow" { return "❄️ heavy snow ⚠️" } - "Light drizzle" { return "💧 light drizzle" } - "Light freezing rain" { return "💧 light freezing rain ⚠️" } - "Light rain" { return "💧 light rain" } - "Light rain shower" { return "💧 light rain shower" } - "Light sleet" { return "❄️ light sleet" } - "Light sleet showers" { return "❄️ light sleet showers" } - "Light snow" { return "❄️ light snow" } - "Light snow showers" { return "❄️ light snow showers" } - "Moderate or heavy freezing rain"{return "💧 moderate or heavy freezing rain ⚠️" } - "Moderate or heavy sleet" { return "❄️ moderate or heavy sleet ⚠️" } - "Moderate or heavy rain shower" { return "💧 moderate or heavy rain shower ⚠️" } - "Moderate or heavy rain in area with thunder" { return "💧 moderate or heavy rain in area with thunder ⚠️" } - "Moderate or heavy snow showers"{ return "❄️ moderate or heavy snow showers ⚠️" } - "Moderate or heavy snow in area with thunder" { return "❄️ moderate or heavy snow in area with thunder ⚠️" } - "Moderate rain" { return "💧 moderate rain" } - "Moderate rain at times" { return "💧 moderate rain at times" } - "Moderate snow" { return "❄️ moderate snow" } - "Mist" { return "🌫 misty" } - "Overcast" { return "☁️ overcast" } - "Partly cloudy" { return "⛅️partly cloudy" } - "Patchy heavy snow" { return "❄️ patchy heavy snow ⚠️" } - "Patchy light drizzle" { return "💧 patchy light drizzle" } - "Patchy light rain" { return "💧 patchy light rain" } - "Patchy light rain in area with thunder" { return "💧 patchy light rain in area with thunder" } - "Patchy light rain with thunder" { return "💧 patchy light rain with thunder" } - "Patchy light snow" { return "❄️ patchy light snow" } - "Patchy moderate snow" { return "❄️ patchy moderate snow" } - "Patchy rain possible" { return "💧 patchy rain possible" } - "Patchy rain nearby" { return "💧 patchy rain nearby" } - "Patchy sleet nearby" { return "❄️ patchy sleet nearby" } - "Patchy snow possible" { return "❄️ patchy snow possible" } - "Sunny" { return "☀️ sunny" } - "Thundery outbreaks possible" { return "⚡️thundery outbreaks possible" } - "Thundery outbreaks in nearby" { return "⚡️thundery outbreaks in nearby" } - default { return $text } + "Blizzard" { return "❄️ blizzard ⚠️" } + "Blowing snow" { return "❄️ blowing snow ⚠️" } + "Clear" { return "🌙 clear" } + "Cloudy" { return "☁️ cloudy" } + "Fog" { return "🌫 fog" } + "Freezing fog" { return "🌫 freezing fog" } + "Heavy rain" { return "💧 heavy rain ⚠️" } + "Heavy snow" { return "❄️ heavy snow ⚠️" } + "Light drizzle" { return "💧 light drizzle" } + "Light freezing rain" { return "💧 light freezing rain ⚠️" } + "Light rain" { return "💧 light rain" } + "Light rain shower" { return "💧 light rain shower" } + "Light sleet" { return "❄️ light sleet" } + "Light sleet showers" { return "❄️ light sleet showers" } + "Light snow" { return "❄️ light snow" } + "Light snow showers" { return "❄️ light snow showers" } + "Moderate or heavy freezing rain" { return "💧 moderate or heavy freezing rain ⚠️" } + "Moderate or heavy sleet" { return "❄️ moderate or heavy sleet ⚠️" } + "Moderate or heavy rain shower" { return "💧 moderate or heavy rain shower ⚠️" } + "Moderate or heavy rain in area with thunder" { return "💧 moderate or heavy rain in area with thunder ⚠️" } + "Moderate or heavy snow showers" { return "❄️ moderate or heavy snow showers ⚠️" } + "Moderate or heavy snow in area with thunder" { return "❄️ moderate or heavy snow in area with thunder ⚠️" } + "Moderate rain" { return "💧 moderate rain" } + "Moderate rain at times" { return "💧 moderate rain at times" } + "Moderate snow" { return "❄️ moderate snow" } + "Mist" { return "🌫 misty" } + "Overcast" { return "☁️ overcast" } + "Partly cloudy" { return "⛅️partly cloudy" } + "Patchy heavy snow" { return "❄️ patchy heavy snow ⚠️" } + "Patchy light drizzle" { return "💧 patchy light drizzle" } + "Patchy light rain" { return "💧 patchy light rain" } + "Patchy light rain in area with thunder" { return "💧 patchy light rain in area with thunder" } + "Patchy light rain with thunder" { return "💧 patchy light rain with thunder" } + "Patchy light snow" { return "❄️ patchy light snow" } + "Patchy moderate snow" { return "❄️ patchy moderate snow" } + "Patchy rain possible" { return "💧 patchy rain possible" } + "Patchy rain nearby" { return "💧 patchy rain nearby" } + "Patchy sleet nearby" { return "❄️ patchy sleet nearby" } + "Patchy snow possible" { return "❄️ patchy snow possible" } + "Sunny" { return "☀️ sunny" } + "Thundery outbreaks possible" { return "⚡️thundery outbreaks possible" } + "Thundery outbreaks in nearby" { return "⚡️thundery outbreaks in nearby" } + default { return $text } } } function GetWindDir([string]$text) { - switch($text) { - "NW" { return "↘" } - "NNW" { return "↓" } - "N" { return "↓" } - "NNE" { return "↓" } - "NE" { return "↙" } - "ENE" { return "←" } - "E" { return "←" } - "ESE" { return "←" } - "SE" { return "↖" } - "SSE" { return "↑" } - "S" { return "↑" } - "SSW" { return "↑" } - "SW" { return "↗" } - "WSW" { return "→" } - "W" { return "→" } - "WNW" { return "→" } - default { return "$text" } + switch ($text) { + "NW" { return "↘" } + "NNW" { return "↓" } + "N" { return "↓" } + "NNE" { return "↓" } + "NE" { return "↙" } + "ENE" { return "←" } + "E" { return "←" } + "ESE" { return "←" } + "SE" { return "↖" } + "SSE" { return "↑" } + "S" { return "↑" } + "SSW" { return "↑" } + "SW" { return "↗" } + "WSW" { return "→" } + "W" { return "→" } + "WNW" { return "→" } + default { return "$text" } } } @@ -79,7 +79,7 @@ try { Write-Progress -completed "Done." [int]$day = 0 - foreach($hourly in $weather.weather.hourly) { + foreach ($hourly in $weather.weather.hourly) { $hour = $hourly.time / 100 $tempC = $(($hourly.tempC.toString()).PadLeft(3)) $precip = $($($hourly.precipMM).PadLeft(4)) @@ -94,11 +94,13 @@ try { if ($hour -eq 0) { if ($day -eq 0) { Write-Host "TODAY 🌡°C ☂️mm 💧 💨km/h ☀️UV ☁️ 👁km at $area ($region, $country)" -foregroundColor green - } elseif ($day -eq 1) { + } + elseif ($day -eq 1) { $date = (Get-Date).AddDays(1) [string]$dayOfWeek = $date.DayOfWeek Write-Host "$($dayOfWeek.toUpper())" -foregroundColor green - } else { + } + else { $date = (Get-Date).AddDays(2) [string]$dayOfWeek = $date.DayOfWeek Write-Host "$($dayOfWeek.toUpper())" -foregroundColor green @@ -107,6 +109,7 @@ try { } "$(($hour.toString()).PadLeft(2))h $tempC° $precip $humidity% $($windDir)$windSpeed $UV $clouds% $visib $desc" } -} catch { +} +catch { "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" } diff --git a/Scripts/locate-ipaddress.ps1 b/Scripts/locate-ipaddress.ps1 index 5b8e66d..e5bd027 100644 --- a/Scripts/locate-ipaddress.ps1 +++ b/Scripts/locate-ipaddress.ps1 @@ -1,4 +1,4 @@ -param([string]$IPaddress= "") +param([string]$IPaddress = "") try { if ($IPaddress -eq "" ) { $IPaddress = read-host "Enter IP address to locate" } @@ -6,7 +6,8 @@ try { $result = Invoke-RestMethod -Method Get -Uri "http://ip-api.com/json/$IPaddress" write-output $result exit 0 # success -} catch { +} +catch { "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" exit 1 } diff --git a/Scripts/post-install.sh b/Scripts/post-install.sh index ce2c5c1..61a8d71 100644 --- a/Scripts/post-install.sh +++ b/Scripts/post-install.sh @@ -10,20 +10,20 @@ clean_empty_files() { touch ~/.hushlogin # Update package list silently -sudo apt update > /dev/null 2>&1 +sudo apt update >/dev/null 2>&1 if [ $? -ne 0 ]; then echo -e "\033[1;31mFailed to update package list. Please check your internet connection or package manager configuration.\033[0m" exit 1 fi # Clean up storage by removing unused packages -sudo apt autoremove -y > /dev/null 2>&1 +sudo apt autoremove -y >/dev/null 2>&1 # Clean up cache memory -sudo apt clean > /dev/null 2>&1 +sudo apt clean >/dev/null 2>&1 # Remove unwanted files (e.g., temporary files) -sudo rm -rf /tmp/* /var/tmp/* > /dev/null 2>&1 +sudo rm -rf /tmp/* /var/tmp/* >/dev/null 2>&1 # Remove empty files and directories from the entire WSL folder, excluding problematic areas clean_empty_files "/home" @@ -36,7 +36,7 @@ UPDATES=$(apt list --upgradable 2>/dev/null | grep -v "Listing..." | wc -l) if [ "$UPDATES" -gt 0 ]; then # Upgrade installed packages silently - sudo apt upgrade -y > /dev/null 2>&1 + sudo apt upgrade -y >/dev/null 2>&1 if [ $? -ne 0 ]; then echo -e "\033[1;31mFailed to upgrade packages. Please check for errors.\033[0m" exit 1 @@ -48,7 +48,7 @@ else fi # Install desired packages silently -sudo apt install -y nala btop screen > /dev/null 2>&1 +sudo apt install -y nala btop screen >/dev/null 2>&1 if [ $? -ne 0 ]; then echo -e "\033[1;31mFailed to install packages. Please check for errors.\033[0m" exit 1 diff --git a/Scripts/qr.ps1 b/Scripts/qr.ps1 index f01feb8..3a9f301 100644 --- a/Scripts/qr.ps1 +++ b/Scripts/qr.ps1 @@ -15,7 +15,8 @@ try { if ($PSVersionTable.PSVersion.Platform -eq "Unix") { $PathToPics = "$HOME/Pictures" - } else { + } + else { $PathToPics = [Environment]::GetFolderPath('MyPictures') } @@ -27,11 +28,12 @@ try { $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 + ` - "&format=" + $FileFormat), $NewFile) + "&size=" + $ImageSize + "&qzone=" + $QuietZone + ` + "&color=" + $ForegroundColor + "&bgcolor=" + $BackgroundColor + ` + "&format=" + $FileFormat), $NewFile) "✔️ saved new QR code image file to: $NewFile" -} catch { +} +catch { "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($_.Exception.Message)" } \ No newline at end of file diff --git a/Scripts/short-url.ps1 b/Scripts/short-url.ps1 index c94ae40..ec3977b 100644 --- a/Scripts/short-url.ps1 +++ b/Scripts/short-url.ps1 @@ -51,7 +51,8 @@ PROCESS { Shortener = $Shortener CreationDateTime = Get-Date } - } catch { + } + catch { Write-Error -Message "An error occurred while attempting to shorten the URL: $_" } } diff --git a/Scripts/windefender.ps1 b/Scripts/windefender.ps1 index 17d7dd3..149ac10 100644 --- a/Scripts/windefender.ps1 +++ b/Scripts/windefender.ps1 @@ -6,29 +6,30 @@ $userInput = Read-Host "Enter an option: [3] Check status " -switch($userInput) { -1 { -$defender.DisableRealtimeMonitoring = $true -$defender | Set-MpPreference -Write-Host "Real-time monitoring of Windows Defender has been disabled." -break -} -2 { -$defender.DisableRealtimeMonitoring = $false -$defender | Set-MpPreference -Write-Host "Real-time monitoring of Windows Defender has been enabled." -break -} -3 { -if($defender.DisableRealtimeMonitoring) { -Write-Host "Real-time monitoring of Windows Defender is currently disabled." -} else { -Write-Host "Real-time monitoring of Windows Defender is currently enabled." -} -break -} -default { -Write-Host "Invalid option selected." -break -} +switch ($userInput) { + 1 { + $defender.DisableRealtimeMonitoring = $true + $defender | Set-MpPreference + Write-Host "Real-time monitoring of Windows Defender has been disabled." + break + } + 2 { + $defender.DisableRealtimeMonitoring = $false + $defender | Set-MpPreference + Write-Host "Real-time monitoring of Windows Defender has been enabled." + break + } + 3 { + if ($defender.DisableRealtimeMonitoring) { + Write-Host "Real-time monitoring of Windows Defender is currently disabled." + } + else { + Write-Host "Real-time monitoring of Windows Defender is currently enabled." + } + break + } + default { + Write-Host "Invalid option selected." + break + } } diff --git a/Scripts/yt-download.ps1 b/Scripts/yt-download.ps1 index c8379a4..d881d79 100644 --- a/Scripts/yt-download.ps1 +++ b/Scripts/yt-download.ps1 @@ -14,11 +14,13 @@ function ytdownloadfun { if (Test-Path $gitPath) { & $gitPath clone $gitRepo $path Write-Host "Download complete." - } else { + } + else { Write-Host "Git is not installed. Please install Git or add it to your PATH." return } - } else { + } + else { Write-Host "Checking for updates..." Set-Location -Path $path & $gitPath fetch @@ -27,7 +29,8 @@ function ytdownloadfun { Write-Host "Updates found. Pulling changes..." & $gitPath pull Write-Host "Update complete." - } else { + } + else { Write-Host "No updates found." } Set-Location -Path $pwd @@ -36,7 +39,8 @@ function ytdownloadfun { # Execute the Python script if it exists if (Test-Path $fullPath) { & $python312Path $fullPath - } else { + } + else { Write-Host "The script file does not exist even after attempting to download. Please check the repository URL and directory permissions." } }