PowerShell File Transfer Calculator

# Function to convert data size to megabits
function Convert-DataSizeToMb {
    param (
        [float]$dataSize,
        [string]$unit
    )
    switch ($unit.ToLower()) {
        "kb" { return $dataSize * 0.008 }
        "mb" { return $dataSize * 8 }
        "gb" { return $dataSize * 8192 }
        "tb" { return $dataSize * 8388608 }
        default { throw "Invalid data size unit" }
    }
}
 
# Function to convert transfer rate to megabits per second
function Convert-TransferRateToMbps {
    param (
        [float]$transferRate,
        [string]$unit
    )
    switch ($unit.ToLower()) {
        "kbps" { return $transferRate * 0.001 }
        "mbps" { return $transferRate }
        "gbps" { return $transferRate * 1000 }
        default { throw "Invalid transfer rate unit" }
    }
}
 
# Prompt for the amount of data and its unit
$dataAmount = Read-Host "Enter the amount of data to transfer"
$dataUnit = Read-Host "Enter the unit of data size (KB, MB, GB, TB)"
 
# Prompt for the transfer rate and its unit
$transferRate = Read-Host "Enter the transfer rate"
$rateUnit = Read-Host "Enter the unit of transfer rate (kbps, mbps, gbps)"
 
# Convert data size and transfer rate to megabits
$dataAmountMb = Convert-DataSizeToMb -dataSize $dataAmount -unit $dataUnit
$transferRateMbps = Convert-TransferRateToMbps -transferRate $transferRate -unit $rateUnit
 
# Calculate transfer time in seconds
$transferTimeSeconds = $dataAmountMb / $transferRateMbps
 
# Convert transfer time to hours, minutes, and seconds
$transferTimeHours = [math]::Floor($transferTimeSeconds / 3600)
$transferTimeMinutes = [math]::Floor(($transferTimeSeconds % 3600) / 60)
$transferTimeSeconds = [math]::Floor($transferTimeSeconds % 60)
 
# Output the transfer time
Write-Output "Transfer time: $transferTimeHours hours, $transferTimeMinutes minutes, $transferTimeSeconds seconds"

Explicit Permission Hunter

# Specify the root folder path
$rootFolderPath = "C:\Temp"
 
# Get all items (files and subfolders) under the root folder
$items = Get-ChildItem -Path $rootFolderPath -Recurse
 
# Iterate through each item
foreach ($item in $items) {
    # Get the ACL for the item
    $acl = Get-Acl -Path $item.FullName
 
    # Check if any explicit permissions exist (not inherited)
    $explicitPermissions = $acl.Access | Where-Object { $_.IsInherited -eq $false }
 
    if ($explicitPermissions.Count -gt 0) {
        Write-Host "Explicit permissions found for $($item.FullName):"
        foreach ($permission in $explicitPermissions) {
            Write-Host "  User: $($permission.IdentityReference)"
            Write-Host "  Permissions: $($permission.FileSystemRights)"
            Write-Host "  Access Control Type: $($permission.AccessControlType)"
            Write-Host "  Inherited: $($permission.IsInherited)"
            Write-Host ""
        }
    }
}

Validate SHA256 Checksums with Python

import tkinter as tk
from tkinter import filedialog, simpledialog, messagebox
import hashlib

def calculate_sha256(file_path):
    sha256_hash = hashlib.sha256()
    with open(file_path, "rb") as f:
        # Read and update hash string value in blocks of 4K
        for byte_block in iter(lambda: f.read(4096), b""):
            sha256_hash.update(byte_block)
    return sha256_hash.hexdigest()

def verify_checksum():
    file_path = filedialog.askopenfilename(title="Select the file to check the SHA256 checksum on", filetypes=[("All Files", "*.*")])

    if file_path:
        # Prompt user for SHA256 checksum
        entered_checksum = simpledialog.askstring("Checksum Verification", "Enter SHA256 checksum:")

        # Calculate the SHA256 checksum of the selected file
        file_checksum = calculate_sha256(file_path)

        # Compare entered checksum with calculated checksum
        if entered_checksum == file_checksum:
            messagebox.showinfo("Verification Result", "Checksum verification successful. The file has not been tampered with.")
        else:
            messagebox.showerror("Verification Result", "Checksum verification failed. The file may have been tampered with.")
    else:
        messagebox.showinfo("File Selection", "File selection cancelled by the user.")

# Create the main application window
root = tk.Tk()
root.withdraw()  # Hide the main window

# Call the verify_checksum function
verify_checksum()

# Start the main loop
root.mainloop()

Don’t Scan Random QR codes

Don’t scan codes from strangers (if you receive a QR code from an unsolicited message — text, social media, email, or physical — be skeptical and don’t use it!) If it’s a physical QR code — take a look to see if it was tampered with.

Check service status on multiple nodes

# List of remote computer names
$computers = @("Server01", "Server02", "Server03", "Server04", "Server05", "Server06")
 
# Name of the service you want to check
$serviceName = "PrintSpooler"
 
# Loop through the list of remote computers and check the service status
foreach ($computer in $computers) {
    try {
        $serviceStatus = Get-Service -ComputerName $computer -Name $serviceName
        Write-Host "Service $serviceName on $computer is $($serviceStatus.Status)"
    } catch {
        Write-Host "Failed to get service status on" $computer
    }
}

Show all users RDP’d into many computers


# List of computer names or IP addresses.
# Note: Un-comment the preferred source 
#$computers = @("ServerA", "ServerB")
#$computers = Get-Content -Path "C:\TEMP\AllNodes.txt
 
foreach ($computer in $computers) {
    Write-Host "Users logged on to"$computer":"
    try {
        $loggedOnUsers = query user /server:$computer 2>&1 | ForEach-Object {
            # Split the line into individual pieces of information
            $userDetails = $_ -split '\s+'
            if ($userDetails[1] -ne "USERNAME" -and $userDetails[1] -ne "No") {
                # Filter out header and empty lines
                $userDetails[1]
            }
        }
       
        if ($loggedOnUsers -eq $null) {
            Write-Host "No users are currently logged on to $computer."
        } else {
            $loggedOnUsers
        }
    } catch {
        Write-Host "Error connecting to "$computer": $_"
    }
    Write-Host
}
 

Check for Windows Activation for a group of nodes

 
# Define list of nodes to check
$servers = Get-Content -Path "C:\TEMP\AllNodes.txt" 
 
# Query activation status
foreach ($server in $servers) {
    $activation = Get-WmiObject -Query "SELECT * FROM SoftwareLicensingProduct WHERE (PartialProductKey IS NOT NULL)" -ComputerName $server
   
    if ($activation) {
        Write-Host "Server $server is activated."
    } else {
        Write-Host "Server $server is not activated."
    }
}