Simple Python Subnet Calculator

#!/usr/bin/env python3
# Use: ./subnet.py <ip/cidr>
# Alt: ./subnet.py <ip> <mask>

import sys

if __name__=="__main__":
    addr = [0, 0, 0, 0]
    mask = [0, 0, 0, 0]
    cidr = 0
    
    if len(sys.argv) == 2:
        (addr, cidr) = sys.argv[1].split('/')
        
        addr = [int(x) for x in addr.split(".")]
        cidr = int(cidr)
        mask = [( ((1<<32)-1) << (32-cidr) >> i ) & 255 for i in reversed(range(0, 32, 8))]
    elif len(sys.argv) == 3:
        addr = sys.argv[1]
        mask = sys.argv[2]
        
        addr = [int(x) for x in addr.split(".")]
        mask = [int(x) for x in mask.split(".")]
        cidr = sum((bin(x).count('1') for x in mask))
    else:
        print("Use: {0} <ip/cidr>".format(sys.argv[0]))
        print("Alt: {0} <ip> <mask>".format(sys.argv[0]))
        sys.exit(-1)
        
    netw = [addr[i] & mask[i] for i in range(4)]
    bcas = [(addr[i] & mask[i]) | (255^mask[i]) for i in range(4)]
    
    print("Address: {0}".format('.'.join(map(str, addr))))
    print("Mask: {0}".format('.'.join(map(str, mask))))
    print("Cidr: {0}".format(cidr))
    print("Network: {0}".format('.'.join(map(str, netw))))
    print("Broadcast: {0}".format('.'.join(map(str, bcas))))

Install multiple .MSU packages

# This snippet installs all .MSU files in a given path

# Notes:
#      -Run this script / ISE as administrator
#      -Update the path for the MSU's prior to execution


# Obtain all .MSU files in a given path
$Dir = (Get-Item -Path "\\FileServer.domain.local\share" -Verbose).FullName
 
 # Loop through each .MSU file
 Foreach($Item in (ls $Dir *.msu -Name))
 {
    # Write the item to the screen so the operator know what is being worked on
    Write-Host "Starting on $Item" -ForegroundColor Magenta
    Write-Host "." 
    Write-Host "."
   
    # Use the Windows Update Standalone Installer (WUSA) to execute
    $item = $Dir + "\" + $Item
    wusa $Item /quiet /norestart | Out-Null
    Write-Host "Completed. Moving on..." -ForegroundColor Green
    Write-Host "."  
    Write-Host "." 
 }

Write-Host "Done with everything. Should probably reboot..." -ForegroundColor Green -BackgroundColor Black
pause
exit

Simple Countdown Timer

[int]$Time = Read-Host "Enter time in minutes"
$Time = $Time * 60
$Length = $Time / 100
For ($Time; $Time -gt 0; $Time--) {
$min = [int](([string]($Time/60)).split('.')[0])
$Text = " " + $min + " minutes " + ($Time % 60) + "seconds left"
Write-Progress -Activity "Waiting for..." -Status $Text -PercentComplete ($Time / $Length)
Start-Sleep 1
}