This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# 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, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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 | |
// |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", ` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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."), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, |
NewerOlder