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 Get-Excuse { | |
(Invoke-WebRequest http://pages.cs.wisc.edu/~ballard/bofh/excuses -OutVariable excuses).content.split([Environment]::NewLine)[(get-random $excuses.content.split([Environment]::NewLine).count)] | |
} |
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
[System.UriBuilder] $uri = "https://www.google.com:8080/search" | |
$uri.Port = -1 | |
$uri.Uri.AbsoluteUri |
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
$a = 1257657656 | |
$a = $a | Add-Member -MemberType ScriptMethod -Name tostring -Force -Value { param($Unit = 1MB, $Digits =1, $Suffix=' MB') "{0:n$Digits}$Suffix" -f ($this/($Unit)) } -PassThru | |
<# | |
PS> $a | |
1.199,4 MB | |
PS> $a.ToString(1GB, 0, ' GB') | |
1 GB | |
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
$a = 1..10 | |
[Array]::Reverse($a) | |
$a |
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
add-type -ass system.linq | |
update-typedata -TypeName System.Array -MemberType ScriptMethod -MemberName Reverse -Value { [System.Linq.Enumerable]::reverse($this) } | |
[int[]]$a =@(1,2,3,4,5) | |
$a.reverse() |
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 test { | |
param($first,$last) | |
New-Object PSObject -Property ([ordered]@{}+$PSBoundParameters) | |
} | |
test john doe |
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 Get-NetStat | |
{ | |
<# | |
.SYNOPSIS | |
This function will get the output of netstat -n and parse the output | |
.DESCRIPTION | |
This function will get the output of netstat -n and parse the output | |
.LINK | |
http://www.lazywinadmin.com/2014/08/powershell-parse-this-netstatexe.html | |
.NOTES |
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
$ips = 0..255 | %{"192.168.1.$_"} | |
$t=$ips|%{(New-Object Net.NetworkInformation.Ping).SendPingAsync($_,250)};[Threading.Tasks.Task]::WaitAll($t);$t.Result |
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
#requires -Version 2 | |
$maximumRuntimeSeconds = 3 | |
$process = Start-Process -FilePath powershell.exe -ArgumentList '-Command Start-Sleep -Seconds 4' -PassThru | |
try | |
{ | |
$process | Wait-Process -Timeout $maximumRuntimeSeconds -ErrorAction Stop | |
Write-Warning -Message 'Process successfully completed within timeout.' |