Skip to content

Instantly share code, notes, and snippets.

@talatham
talatham / mastermind.py
Created June 13, 2013 10:02
A Mastermind style guessing game. FERMI - right number, right place. PICO - right number, wrong place.
# Mastermind Game (with numbers)
# import Random for creating code
import random
# Create a three digit random number
def secretCode():
secretCode = ''
for i in range(0, 3):
secretCode += str(random.randint(1, 9))
@talatham
talatham / usernotification.ps1
Created June 13, 2013 09:57
Show balloon tip.
[system.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms') | Out-Null
$balloon = New-Object System.Windows.Forms.NotifyIcon
$path = Get-Process -id $pid | Select-Object -ExpandProperty Path
$icon = [System.Drawing.Icon]::ExtractAssociatedIcon($path)
$balloon.Icon = $icon
$balloon.BalloonTipIcon = 'Info'
$balloon.BalloonTipText = 'Completed Operation'
$balloon.BalloonTipTitle = 'Done'
$balloon.Visible = $true
$balloon.ShowBalloonTip(10000)
@talatham
talatham / harddiskusage.ps1
Created June 13, 2013 09:36
Display the disk usage for a specified machine.
# Initialise machine name
$server = "<>"
# Get fixed drive info
$disks = Get-WmiObject -ComputerName $server -Class Win32_LogicalDisk -Filter "DriveType = 3";
foreach($disk in $disks)
{
$deviceID = $disk.DeviceID;
[float]$size = $disk.Size;
@talatham
talatham / machineuserdetails.ps1
Last active May 24, 2022 18:15
Return current/last user for a list of machines.
# ====================================================================
# Retrieve current or last user logon details for a list of machines
# Tom Latham (13/05/2010)
# ====================================================================
Function Get-FileName
# Open file dialog box and select a file to import
{
[void][System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms")
@talatham
talatham / openfile.ps1
Created June 12, 2013 14:51
Open and read a file selected by a user dialog.
# ---------- FUNCTION -------------
Function Get-FileName
# Open file dialog box and select a file to import
{
[void][System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms")
$OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog
$OpenFileDialog.filter = "Text Files (*.txt)| *.txt" # Set the file types visible to dialog
@talatham
talatham / savetofile.ps1
Created June 12, 2013 14:50
Save to a file specified by a user dialog.
# ------ FUNCTION --------------
Function Set-Filename
# Set file name for saving export
{
[void][System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms")
$SaveFileDialog = New-Object System.Windows.Forms.SaveFileDialog
$SaveFileDialog.Filter = "Text files (*.txt)|*.txt"
$SaveFileDialog.initialDirectory = "c:\"
@talatham
talatham / Ping Machines
Created June 12, 2013 14:49
Variety of methods for pinging machines.
Variety of methods for pinging machines.
@talatham
talatham / createfolderpath.vbs
Created June 12, 2013 14:46
Create a folder path recursively.
'Create folder path recursively
Function GeneratePath(pFolderPath)
GeneratePath = False
If Not wFile.FolderExists(pFolderPath) Then
If GeneratePath(wFile.GetParentFolderName(pFolderPath)) Then
GeneratePath = True
Call wFile.CreateFolder(pFolderPath)
End If
Else
GeneratePath = True
@talatham
talatham / listupdates.ps1
Created June 12, 2013 14:39
List all Windows Updates on the current machine.
$Session = New-Object -ComObject Microsoft.Update.Session
$Searcher = $Session.CreateUpdateSearcher()
$HistoryCount = $Searcher.GetTotalHistoryCount()
$Searcher.QueryHistory(1,$HistoryCount) |
Select-Object Date, Title, Description
@talatham
talatham / convertip.vbs
Created June 12, 2013 14:28
Convert IP address to integer format.
' ------------------------------------------------------------
' Convert IP Address - convert IP Address to integer format
' ------------------------------------------------------------
Function ConvertIP(IPAddress)
Dim IPnumber, IPArray, counter
IPArray = Split(IPAddress,".")
IPNumber = CDbl(0)
For counter = 0 To UBound(IPArray)