This file contains hidden or 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 Measure-ScriptBlock { | |
| <# | |
| .SYNOPSIS | |
| Measure time, memory consumption and CPU time for a block of code to execute. | |
| .DESCRIPTION | |
| Measure time, memory consumption and CPU time for a block of code to execute. | |
| This function is using Measure-Command internally, but is also trying to record how much memory and CPU time the code uses during execution. | |
| .EXAMPLE |
This file contains hidden or 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 Get-TrimmedMean { | |
| <# | |
| .SYNOPSIS | |
| Function to calculate the trimmed mean of a set of numbers. | |
| .DESCRIPTION | |
| Function to calculate the trimmed mean of a set of numbers. | |
| The default trim percent is 25, which when used will calculate the Interquartile Mean of the number set. | |
| Use the TrimPercent parameter to set the trim percent as needed. | |
| .EXAMPLE | |
| [double[]]$dataSet = 8, 3, 7, 1, 3, 9 |
This file contains hidden or 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
| # the EnumUtils code was nicked from Wayne Hartman (http://blog.waynehartman.com/articles/84.aspx) | |
| Add-Type -TypeDefinition @" | |
| using System; | |
| using System.Reflection; | |
| using System.ComponentModel; | |
| public enum MockarooType | |
| { | |
| Boolean, | |
| City, |
This file contains hidden or 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 New-FormatTableItem { | |
| <# | |
| .SYNOPSIS | |
| Create new format Table Item | |
| .DESCRIPTION | |
| Create new format Table Item for use with Add-FormatTable | |
| .EXAMPLE | |
| Assuming you have a custom object with a type name of 'Custom.UserType': | |
| @( |
This file contains hidden or 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 Resolve-PathEx { | |
| <# | |
| .SYNOPSIS | |
| Resolve-Path extended to also work with files that don't exist. | |
| .DESCRIPTION | |
| You can use Resolve-PathEx when you want to handle both filenames and paths in a single parameter in your functions. | |
| The function returns an object, and includes the resolved path as well as a boolean indicating whether the file | |
| exists or not. Wildcards are supported for both path and filename. | |
| .EXAMPLE | |
| Resolve-Path *.ps1 |
This file contains hidden or 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 Invoke-Touch { | |
| <# | |
| .SYNOPSIS | |
| PowerShell inplementation of the Unix/Linux utility called touch. | |
| .DESCRIPTION | |
| Touch let's you update the access date and / or modification date of a file. If the file don't exist, an empty file will be created | |
| unless you use the DoNotCreateNewFile parameter. This implementation have the original parameter names added as | |
| aliases, so if you are familiar with the original touch utility it should be easy to use this one. | |
| .EXAMPLE | |
| Invoke-Touch newfile |
This file contains hidden or 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 New-Log { | |
| <# | |
| .SYNOPSIS | |
| Create a new log. | |
| .DESCRIPTION | |
| The New-Log function is used to create a new log file or Windows Event log. A log object is also created | |
| and either saved in the global PSLOG variable (default) or sent to the pipeline. The latter is useful if | |
| you need to write to different log files in the same script/function. | |
| .EXAMPLE | |
| New-Log '.\myScript.log' |
This file contains hidden or 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
| # Basic Script Template for Runspace Jobs against an array of computers | |
| # This is just an example to show the basic layout of a script using the Runspace functions | |
| # If you are creating a script to be run in production, please add logging and error handling | |
| # Also consider writing it to support parameters for input instead of hardcoding it like in this example | |
| #region verify that runspace functions are present | |
| $missingFunctions = $false | |
| $functions = ( | |
| 'New-RunspacePool', | |
| 'New-RunspaceJob', |
This file contains hidden or 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
| # PowerShell Profile - Øyvind Kallstad | |
| # Last updated: 27.11.2014 | |
| # Get the original prompt | |
| $originalPrompt = (Get-Item function:prompt).ScriptBlock | |
| # define our new custom prompt | |
| $customPrompt = { | |
| $currentLocaction = $executionContext.SessionState.Path.CurrentLocation.ToString() | |
| $host.UI.RawUI.WindowTitle = $currentLocaction.Replace('Microsoft.PowerShell.Core\','') |
This file contains hidden or 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 Search-Spotify { | |
| <# | |
| .SYNOPSIS | |
| Search Spotify. | |
| .DESCRIPTION | |
| This function uses the public web API of Spotify to let you query their database for information about | |
| artists, albums, tracks and popular playlists. | |
| .EXAMPLE | |
| Search-Spotify 'Madonna' | |
| Will search for 'Madonna' among all artists in the Spotify database. |