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 Log-Start{ | |
<# | |
.SYNOPSIS | |
Creates log file | |
.DESCRIPTION | |
Creates log file with path and name that is passed. Checks if log file exists, and if it does deletes it and creates a new one. | |
Once created, writes initial logging data | |
.PARAMETER LogPath |
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
<# | |
.Synopsis | |
Performance test for output suppression in PowerShell | |
.DESCRIPTION | |
Very basic performance test against different types of output suppression in PowerShell | |
Increase the value of the Iterations parameter to observe how performance impacts the different methods | |
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
New-IseSnippet -Title '@Calculated Property, Named' -Description "Named calculated property template" -Text '@{ Name = ""; Expression = { } }' -CaretOffset 11 | |
New-IseSnippet -Title '@Calculated Property, Anonymous' -Description "Calculated property template, without a name (For use with Sort-Object and Group-Object)" -Text '@{ Expression = { } }' -CaretOffset 18 |
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 Reverse-String { | |
param( | |
[string]$instr | |
) | |
$chars = $instr.ToCharArray() | |
[array]::Reverse($chars) | |
$chars -join "" | |
} |
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 New-JunkFile | |
{ | |
<# | |
.SYNOPSIS | |
Generates a file of a specified length, filled with random bytes | |
.DESCRIPTION | |
Generates a file of a specified length, filled with random bytes | |
Uses the RNGCryptoServiceProvider to randomly select each byte |
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
# | |
# Ping-Forever.ps1 | |
# | |
# Modified version of alexinnes/ConstantPingToServer.ps1 (https://gist.github.com/alexinnes/b2076c88700020af3963) | |
# | |
[CmdletBinding()] | |
param( | |
[Parameter(Mandatory=$true)] | |
[string]$ComputerName, | |
[string]$LogDirectory = 'C:\ping logs\' |
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 Parse-SimpleFilter { | |
param([string]$Filter) | |
$err = @() # TODO inspect parsing errors | |
$Tokens = [System.Management.Automation.PSParser]::Tokenize($Filter,[ref]$err) | |
$Elements = foreach($t in $Tokens){ | |
switch($t.Type){ | |
([System.Management.Automation.PSTokenType]::Command) { | |
'$_.{0}' -f $t.Content |
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 ?? { | |
$args |Select-Object -First 1 | |
} | |
# Use like: | |
# $Name = ?? (Get-ADUser $_ | Select-Object -Expand Name) "John Doe" | |
# | |
# supports as many fallthroughs as you like (like chained ?? in C#) | |
# $Something =?? $null $null $null 1 | |
# ($Something -eq 1) is now the case |
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 Measure-Lines { | |
param($Path = 'C:\log.txt') | |
$FileStream = New-Object IO.FileStream ($Path,[System.IO.FileMode]::Open,[System.IO.FileAccess]::Read,[System.IO.FileShare]::ReadWrite) | |
$StreamReader = New-Object System.IO.StreamReader $FileStream | |
$TotalLines = 0 | |
while($StreamReader.ReadLine() -ne $null){ | |
$TotalLines++ | |
} | |
$TotalLines |
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
# Most straighforward way I can think of | |
# 2 pairs of curly braces and a single semicolon for the calculated OSVERSION property | |
Import-Csv .\input.csv |Select-Object -Property MACHINENAME,@{Label='OSVERSION';Expression={(Get-WmiObject Win32_OperatingSystem -ComputerName $_.MACHINENAME).Caption}} | Export-Csv .\output.csv -NoTypeInformation |