Skip to content

Instantly share code, notes, and snippets.

@talatham
talatham / export-dgv2csv.ps1
Last active October 24, 2018 11:22
Export a PowerShell datagrid to a CSV file
function export-DGV2CSV ([Windows.Forms.DataGridView] $grid, [String] $File)
<#
.SYNOPSIS
Export basic datagrid to CSV file
.PARAMETER grid
Datagrid object
.PARAMETER file
Path to CSV file
#>
@talatham
talatham / mousewatcher.sh
Last active October 24, 2018 11:23
Monitor mouse movement. If mouse hasn't moved in a set period of time within certain window, shut down the box.
#!/bin/bash
# ---------------------------------------------------------------------------#
# Mousewatcher v1.2
# Monitor user activity and shutdown machine if no activity detected.
#
# 24/05/2010 - Tom Latham
#
# Explanation:
# * Log output of /dev/input/mice to file. Monitor timestamp of file to
@talatham
talatham / force-64bitPS.ps1
Created October 27, 2016 10:31
Force Powershell to run as x64-bit if required.
if (($pshome -like "*syswow64*") -and ((Get-WmiObject Win32_OperatingSystem).OSArchitecture -like "64*")) {
write-warning "Restarting script under 64 bit powershell"
# relaunch this script under 64 bit shell
& (join-path ($pshome -replace "syswow64", "sysnative")\powershell.exe) -file $myinvocation.mycommand.Definition @args
# This will exit the original powershell process. This will only be done in case of an x86 process on a x64 OS.
exit
}
@talatham
talatham / vco_disableSSHAllHosts.js
Last active August 29, 2015 14:14
Disable and stop SSH service on all hosts in a specified vCenter. Input parameter: VC:sdkConnection
//Disable SSH on all hosts in a vCenter
//Tom Latham (04/02/2015)
//Get all host systems from vCenter
var hosts = vCenter.getAllHostSystems(null,null);
System.log (hosts.length + " hosts found in " + vCenter.name);
var countSSHEnabled = 0; //Count of servers with misconfigured SSH
var countSSHRemediated = 0;
//Iterate across all hosts
@talatham
talatham / checkmachineforhotfix.ps1
Created June 13, 2013 15:00
Check machines for specific hotfix.
# Check for a specific patch on remote PCs v1.2
# Tom Latham 04/02/2010
#
# Added v1.1: Error messaages
# Added v1.2: GUI Inputs
# Function to open file dialog box and select a file
Function Get-FileName($initialDirectory)
{
[void][System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms")
@talatham
talatham / addremoveprograms.vbs
Created June 13, 2013 14:48
Create a text file listing the contents of Add/Remove Programs.
Option Explicit
'---------------- USAGE -------------------------
Dim sComputer : sComputer = "."
'---------------- PROGRAM -------------------------
Dim sFileName : sFileName = sComputer & "_" & GetFilename() & ".txt"
Dim sData
@talatham
talatham / A collection of SCCM VBScript Functions
Last active October 30, 2018 12:59
VBScript functions for SCCM.
Includes:
* Connecting to SCCM
* Finding folders, packages and machines
* Creating software metering rules
* Remove machines from collections
@talatham
talatham / deletefolder.vbs
Created June 13, 2013 14:04
Delete a folder
'------------- USAGE --------------------
DeleteFolder("<machine>","\\<machine>\c$\Documents and Settings\xtomlatham")
'------------- FUNCTION -----------------
' Attempt to delete specifed folder. Fails on folder not found or deleted.
Function DeleteFolder(sComputer, sFolderPath)
Dim oFS : Set oFS = CreateObject("Scripting.FileSystemObject")
@talatham
talatham / A collection of PS file functions
Last active December 2, 2016 17:29
A collection of Powershell file functions
Including:
* Deleting files and folders (incl criteria based - if older than xx days)
* Open and save file dialogs
* Hard disk usage reports
@talatham
talatham / mousemovement
Created June 13, 2013 13:39
AutoIt script to auto-move the mouse. Run the script and use ` to toggle.
$bMouseMove = 0
HotKeySet( "`", "toggle" )
While 1
Sleep(10)
If $bMouseMove = 1 Then
$bMouseMove = 2
MouseMove(100,100)
ElseIf $bMouseMove = 2 Then
$bMouseMove = 1
MouseMove(200,200)