Skip to content

Instantly share code, notes, and snippets.

@iqwirty
iqwirty / Search-FileByKeyword.ps1
Created March 8, 2017 21:30
Use PowerShell to search C: drive of computer for file names matching a keyword
# Search entire C: drive for any files with "keyword1" in the name. Use SilentlyContinue to
# continue past any Access Denied errors. Results are captured in a variable for later
# processing.
$d = Get-ChildItem -Path C:\ -Filter "*keyword*.*" -Recurse -ErrorAction SilentlyContinue
# Explore the results in a GridView pop-up, filtering further on "keyword2".
$d | Select FullName, CreationTime | ? { $_.FullName -like "*keyword2*" } | Sort FullName | Out-GridView
@iqwirty
iqwirty / ParameterExamples.ps1
Last active August 29, 2015 14:22
Examples using PowerShell script and function parameters
#
# Examples using PowerShell script and function parameters
#
# Give the script some of the standard PowerShell parameters like -Verbose and -Debug
[CmdletBinding()]
Param (
# Make this parameter mandatory, so no default value
[Parameter(Mandatory=$true)]
[string] $FirstParameterAsString,
@iqwirty
iqwirty / CreateParentOUAndChildren
Created February 10, 2015 15:40
Create a parent organizational unit and some children
# Create a parent organizational unit and some children
Import-Module ActiveDirectory
# Create the parent in dc=domain,dc=net
New-ADOrganizationalUnit "ParentOU"
# Create the children
1..10 | % `
{
New-ADOrganizationalUnit -Name "ChildOU$_" -Path "ou=ParentOU,dc=domain,dc=net"
@iqwirty
iqwirty / everadd.js
Last active February 26, 2024 09:54
A lightweight interface for adding notes to Evernote, to run on Google Apps Script
//
// Provides a lightweight and responsive interface for
// adding a note to my Evernote account. Uses the Evernote
// email service for adding the note.
//
//
// Global variables / configuration
//
@iqwirty
iqwirty / TfsGetRecent.ps1
Created April 18, 2014 18:46
Gets a list of recent changes in a few TFS servers and emails as a report
Clear-Host
Set-PSDebug -Trace 0
Set-StrictMode -Version Latest
#
# Function Send()
#
# Sends an email using the specified to/from, subject, body, and
# and SMTP server. Allows an attachment to be included. Also includes
# in the body the source path of the running script to improve
@iqwirty
iqwirty / ConnectTfs.ps1
Created April 18, 2014 14:37
Connect to a TFS server and display some information
# Load the snap-in for TFS. You might need to first install the TFS Powertools from Microsoft.
Add-PSSnapin Microsoft.TeamFoundation.PowerShell
$serverUrl = "http://servername:8080/tfs"
$tfsServer = Get-TfsServer -Name $serverUrl
# Output some information about the server object
$tfsServer
@iqwirty
iqwirty / cleaner.ps1
Created April 17, 2014 19:26
First iteration of a script to help find / rid various stuff left on a Windows computer
Clear-Host
$outputFile = "c:\tempo\cleaner-$(Get-Date -Format yyyy-MM-dd_hh-mm-ss).log"
$pathsToClean = @("$Env:USERPROFILE\AppData\Roaming\Microsoft\Word", `
"$Env:USERPROFILE\AppData\Roaming\Microsoft\Excel", `
"$Env:USERPROFILE\AppData\Roaming\Microsoft\PowerPoint", `
"$Env:USERPROFILE\AppData\Local\Microsoft\Windows\Temporary Internet Files\Content.Word", `
"$Env:USERPROFILE\AppData\Local\Microsoft\Windows\Temporary Internet Files\Content.MSO", `
"$Env:USERPROFILE\AppData\Local\Microsoft\Windows\Temporary Internet Files\Content.Outlook", `
@iqwirty
iqwirty / WriteLog.ps1
Created April 16, 2014 19:48
Writes a logging message to the console and to a file.
Function WriteLog
{
# Writes a logging message to the console and to a file. Assumes
# a variable called $logPath has already been initialized
# globally.
Param (
[string]$Message
)
@iqwirty
iqwirty / GetStoredProcedureResult.ps1
Created April 16, 2014 19:46
Gets an array of objects representing the return value of a stored procedure.
Function GetStoredProcedureResult
{
# Gets an array of objects representing the return value of the
# specified stored procedure. This function allows up to one
# (optional) named SQL integer parameter to be provided.
Param (
[string]$Server = $(Throw "No SQL server specified."),
[string]$Database = $(Throw "No database name specified."),
[string]$StoredProcedure = $(Throw "No stored procedure name specified."),
@iqwirty
iqwirty / EmailScriptReport.ps1
Created April 16, 2014 19:44
Sends an email from a script with an optional attachment. Includes path of currently running script in body.
Function EmailScriptReport
{
# Sends an email using the specified to/from, subject, body, and
# and SMTP server. Allows an attachment to be included. Also includes
# in the body the source path of the running script to improve
# traceability.
Param (
[string]$To,
[string]$From,