Skip to content

Instantly share code, notes, and snippets.

@talatham
talatham / createtextfile.cmd
Created June 12, 2013 14:26
Create a text file in each directory and sub-directory of the current directory with the same name as this batch script.
@ECHO OFF
for /f "tokens=*" %%G IN ('dir /ad /b /s') DO (
echo. > "%%G\%~n0.txt"
)
@talatham
talatham / convertdate.vbs
Created June 12, 2013 14:27
Convert US date to UK date.
Function ToDDMM(dDate)
Dim dTemp
dTemp=Split(dDate, "/")
ToDDMM=dTemp(1) & "/" & dTemp(0) & "/" &dTemp(2)
End Function
@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)
@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 / 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 / Ping Machines
Created June 12, 2013 14:49
Variety of methods for pinging machines.
Variety of methods for pinging machines.
@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 / 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 / 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 / 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;