Skip to content

Instantly share code, notes, and snippets.

View gravejester's full-sized avatar

Øyvind Kallstad gravejester

View GitHub Profile
@gravejester
gravejester / Get-ClusterGroupInfo.ps1
Last active December 14, 2015 06:19
Microsoft Cluster – Get group ownership information
Get-WmiObject -namespace rootmscluster -class mscluster_resourcegroup -computer $computer -Authentication PacketPrivacy|Add-Member -pass ScriptProperty Node {Get-WmiObject -namespace rootmscluster -computer $computer -Authentication PacketPrivacy -query "ASSOCIATORS OF {MSCluster_ResourceGroup.Name='$($this.name)'} WHERE AssocClass = MSCluster_NodeToActiveGroup"|Select -ExpandProperty Name}|Select @{Name="Group";Expression={$_.Name}},Node,@{Name="Status";Expression={if($_.State -eq 0){"Online"}else{"Offline"}}}|ft -autosize
@gravejester
gravejester / Trace-Route.ps1
Last active April 3, 2018 16:26
For some reason I wanted to write a trace route script in PowerShell, but decided to run it through Google first to see if it had been done. Surprisingly few results came up, and as far as I can tell, only one true PowerShell script doing Trace Route without just being a wrapper for tracert or something similar: https://snoj.us/75/traceroute-wit…
function Trace-Route {
<#
.SYNOPSIS
Trace the route between source computer and a target machine.
.DESCRIPTION
Trace the route between source computer and a target machine.
.EXAMPLE
Trace-Route Computer01
Perform trace route to Computer01
.EXAMPLE
@gravejester
gravejester / wget.ps1
Created February 26, 2013 20:37
Ever wanted to download a file from the web using PowerShell? It’s quite easy actually.
# PowerShell wget
# Version 1.0
[CmdletBinding()]
param(
[Parameter(ValueFromPipeline = $true, Mandatory = $true)]
$url,
$dest = (Get-Location).Path
)
if(!$url){break}
@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)
}))
}
}