Skip to content

Instantly share code, notes, and snippets.

@Grimthorr
Grimthorr / pending-updates.ps1
Created November 9, 2015 16:03
PowerShell script to list the pending/missing Windows updates.
$UpdateSession = New-Object -ComObject Microsoft.Update.Session
$UpdateSearcher = $UpdateSession.CreateupdateSearcher()
$Updates = @($UpdateSearcher.Search("IsHidden=0 and IsInstalled=0").Updates)
$Updates | Select-Object Title
@Grimthorr
Grimthorr / import-users.ps1
Created October 8, 2015 08:17
PowerShell script to batch create (or import) users in Active Directory.
Import-Module ActiveDirectory
$Users = Import-Csv -Delimiter "," -Path ".\users.csv"
foreach ($User in $Users) {
$SAM = $User.Username
$Displayname = $User.Displayname
$Firstname = $User.Firstname
$Lastname = $User.Lastname
$OU = $User.Container
@Grimthorr
Grimthorr / remove-all-metro-apps.ps1
Last active October 8, 2015 08:05
Uninstall all Windows Metro apps including those pre-installed on the system.
Get-AppxPackage -AllUsers | Remove-AppxPackage
Get-AppXProvisionedPackage -Online | Remove-AppxProvisionedPackage -Online
@Grimthorr
Grimthorr / exchange-report-deleted-items.ps1
Created January 13, 2015 16:09
Generate a CSV report detailing the total size of and number of items in each Exchange user's Deleted Items folder.
cls
echo "Generating report for deleted items folders..."
echo "Please wait..."
$data = @()
foreach($mbx in Get-MailboxDatabase | Get-Mailbox) {
$dispname = $mbx.displayName
$data += Get-MailboxFolderStatistics $mbx.identity | where{$_.FolderType -eq "DeletedItems"} | Select-Object @{n="Username";e={$mbx.displayName}}, @{n="TotalSizeIncSubfolders(MB)";e={$_.FolderAndSubFolderSize.ToMb()}}, ItemsInFolderAndSubFolders
}
@Grimthorr
Grimthorr / move-old-files.py
Created December 19, 2014 14:36
Python script to move old files from one folder to another.
import sys
import os
import glob
import shutil
import time
import logging
from datetime import datetime, date, timedelta
# start editable vars #
days_old = 28 # how old the files have to be before they are moved
@Grimthorr
Grimthorr / directory-inventory.py
Last active June 27, 2024 14:01
Python script to generate a text file listing all files from a given directory (including those in sub-folders).
#!/usr/bin/python
import os
# start editable vars #
outputfile = "~/inventory.txt" # file to save the results to
folder = "~/test" # the folder to inventory
exclude = ['Thumbs.db','.tmp'] # exclude files containing these strings
pathsep = "/" # path seperator ('/' for linux, '\' for Windows)
# end editable vars #
@Grimthorr
Grimthorr / write-ini.vbs
Created December 16, 2014 11:25
Visual Basic script function to write a key to an INI file.
Sub WriteIni( myFilePath, mySection, myKey, myValue )
' This subroutine writes a value to an INI file
'
' Arguments:
' myFilePath [string] the (path and) file name of the INI file
' mySection [string] the section in the INI file to be searched
' myKey [string] the key whose value is to be written
' myValue [string] the value to be written (myKey will be
' deleted if myValue is <DELETE_THIS_VALUE>)
'
@Grimthorr
Grimthorr / read-ini.vbs
Created December 16, 2014 11:24
Visual Basic script function to read a key value from an INI file.
Function ReadIni( myFilePath, mySection, myKey )
' This function returns a value read from an INI file
'
' Arguments:
' myFilePath [string] the (path and) file name of the INI file
' mySection [string] the section in the INI file to be searched
' myKey [string] the key whose value is to be returned
'
' Returns:
' the [string] value for the specified key in the specified section
@Grimthorr
Grimthorr / delete-files-older-than.vbs
Last active July 25, 2019 14:17
A Visual Basic script to delete files from the specified folder that are older than the specified number of days.
On Error Resume Next
'Dim some stuffs
Dim objFso, objFolder, objFile, strFolderPath, intDaysOlderThan
Set objFso = CreateObject("Scripting.FileSystemObject")
'Change these variables
strFolderPath = "C:\Temp"
intDaysOlderThan = 28