Skip to content

Instantly share code, notes, and snippets.

View gravejester's full-sized avatar

Øyvind Kallstad gravejester

View GitHub Profile
@gravejester
gravejester / New-DataTableFromSqlTable.ps1
Last active August 29, 2015 14:07
Create a new DataTable object based on an existing Microsoft SQL database table
function New-DataTableFromSqlTable{
<#
.SYNOPSIS
Create a new (empty) DataTable object based on a SQL Table.
.DESCRIPTION
Create a new (empty) DataTable object based on a SQL Table.
.PARAMETER DatabaseServer
The Hostname of the database server.
@gravejester
gravejester / Get-FolderSize.ps1
Last active August 29, 2015 14:07
Get the total size of a folder.
function Get-FolderSize{
<#
.SYNOPSIS
Get the total size of a folder.
.DESCRIPTION
Get the total size of a folder.
.PARAMETER Path
Path to target folder.
@gravejester
gravejester / ConvertTo-ScriptBlock.ps1
Last active August 29, 2015 14:07
Convert to ScriptBlock.
function ConvertTo-ScriptBlock{
<#
.SYNOPSIS
Convert to ScriptBlock.
.DESCRIPTION
Convert input to ScriptBlock.
.EXAMPLE
Get-Content '.\scriptFile.ps1' -raw | ConvertTo-ScriptBlock
@gravejester
gravejester / Get-ChildItemRecurse.ps1
Last active August 29, 2015 14:07
Wrapper for Get-ChildItem to be able to define how deep you want to search in a directory structure.
function Get-ChildItemRecurse{
<#
.SYNOPSIS
Wrapper for Get-ChildItem to be able to define how deep you want to search in a directory structure.
.DESCRIPTION
Wrapper for Get-ChildItem to be able to define how deep you want to search in a directory structure.
.PARAMETER Path
One or more paths you want to start searching from. Defaults to '.' (Current location).
@gravejester
gravejester / Out-ClipboardText.ps1
Last active August 29, 2015 14:07
Send text to clipboard
function Out-ClipboardText {
[CmdletBinding()]
param (
[Parameter(ValueFromPipeline,Mandatory, Position = 0)]
[string] $Text
)
Add-Type -AssemblyName 'PresentationCore'
[System.Windows.Clipboard]::SetText($Text)
}
@gravejester
gravejester / Get-ClipboardText.ps1
Last active August 29, 2015 14:07
Get text from clipboard
function Get-ClipboardText{
Add-Type -AssemblyName 'PresentationCore'
Write-Output ([System.Windows.Clipboard]::GetText())
}
function Get-SpecialFolder {
param ([string]$Name)
foreach ($folder in (([Enum]::GetValues([System.Environment+SpecialFolder])) | Where-Object {$_ -like $Name})) {
Write-Output (,([PSCustomObject] @{
Name = $folder.ToString()
Path = [System.Environment]::GetFolderPath($folder)
}))
}
}
@gravejester
gravejester / Get-WebFile.ps1
Created October 7, 2014 11:24
Download a file from the internet.
function Get-WebFile {
<#
.SYNOPSIS
Download a file from the internet.
.DESCRIPTION
Download a file from the internet.
.PARAMETER Url
URL of file being downloaded
@gravejester
gravejester / Write-PluralString.ps1
Created October 8, 2014 13:39
Write string with built-in handling of plural-s for variable integer.
function Write-PluralString{
<#
.SYNOPSIS
Write string with built-in handling of plural-s for variable integer.
.DESCRIPTION
Write string with built-in handling of plural-s for variable integer.
.EXAMPLE
Write-PluralString "$($computer): " $num 'file' 'processed'
@gravejester
gravejester / Test-Connection.ps1
Created October 13, 2014 08:55
Test-Connection Proxy Function adding Resolve parameter
function Test-Connection {
[CmdletBinding(DefaultParameterSetName='Default', HelpUri='http://go.microsoft.com/fwlink/?LinkID=135266', RemotingCapability='OwnedByCommand')]
param(
[Parameter(ParameterSetName='Default')]
[Parameter(ParameterSetName='Source')]
[switch]
${AsJob},
[System.Management.AuthenticationLevel]
${Authentication},