Skip to content

Instantly share code, notes, and snippets.

View lazywinadmin's full-sized avatar

François-Xavier Cat lazywinadmin

View GitHub Profile
@lazywinadmin
lazywinadmin / Get-Excuse.ps1
Created January 31, 2016 03:01
Excuse for SysAdmins
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)]
}
@lazywinadmin
lazywinadmin / Remove_port_from_URL.ps1
Created January 18, 2016 02:36
Remove the port of a URL
[System.UriBuilder] $uri = "https://www.google.com:8080/search"
$uri.Port = -1
$uri.Uri.AbsoluteUri
@lazywinadmin
lazywinadmin / SCSM-Affected_and_Related_CI.ps1
Created December 2, 2015 19:42
SCSM - Get the Affected and Related Configuration Items
@lazywinadmin
lazywinadmin / StringMethod.ps1
Created November 18, 2015 15:46
Add a String method
$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
$a = 1..10
[Array]::Reverse($a)
$a
@lazywinadmin
lazywinadmin / array_reverse_method.ps1
Created November 8, 2015 20:43
Add reverse method to array object
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()
@lazywinadmin
lazywinadmin / psboundparameters.ps1
Created October 23, 2015 03:29
User $PSBoundParameters to create a powershell object
function test {
param($first,$last)
New-Object PSObject -Property ([ordered]@{}+$PSBoundParameters)
}
test john doe
@lazywinadmin
lazywinadmin / netstat_no.ps1
Created October 1, 2015 04:15
NetStat -no parsed in PowerShell
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
@lazywinadmin
lazywinadmin / pinger.ps1
Created September 24, 2015 23:37
Fast Pinger
$ips = 0..255 | %{"192.168.1.$_"}
$t=$ips|%{(New-Object Net.NetworkInformation.Ping).SendPingAsync($_,250)};[Threading.Tasks.Task]::WaitAll($t);$t.Result
@lazywinadmin
lazywinadmin / Timeout.ps1
Created August 26, 2015 14:44
Timeout in powershell
#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.'